3

I'm writing GUI tests for an ASP.NET web application but Selenium can not seem to connect to the localhost. Every time I run the test case it loads the chrome browser, but I get the error "ERR_CONNECTION_REFUSED". I can connect to the localhost just fine for development, just not testing.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace MyApplication.Tests
{
    [TestClass]
    public class UnitTest1
    { 
        [TestMethod]
        public void ButtonMenuDimensions_Chrome()
        {
            try
            {
                String url = "http://localhost:52956";
                ChromeDriver driver = new ChromeDriver();
                driver.Navigate().GoToUrl(url);
                driver.Manage().Window.Maximize();
                String actualHeight = driver.FindElement(By.Id("menu")).GetCssValue("height");
                Console.WriteLine("Actual Height: " + actualHeight);
                String expectedHeight = "450px";
                String actualWidth = driver.FindElement(By.Id("menu")).GetCssValue("width");
                String expectedWidth = "200px";

                Assert.AreEqual(expectedHeight, actualHeight);
                Assert.AreEqual(expectedWidth, actualWidth);

                driver.Close();
                driver.Dispose();
            }
            catch
            {
                Console.WriteLine("Error executing test case: Dimensions");
            }
        }
    }
}

When I open up the output for this test case I am getting

Error executing test case: Dimensions

1 Answer 1

3

I suspect you're running the app on iis express, you will need to make sure this is running when your test are by having the ASP website running/debugging in VS.

If you hit the URL http://localhost:52956 without running the ASP website can you still hit it?

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much! I figured that the Tests would be able to start the IIS Server on their own. Unfortunately VS does not let you run tests while the website is running/debugging so you have to load up two different instances of Visual Studio, one to start the server and the other to run the tests.
Surely there must be a way to get the unit tests to run the website?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.