0

i have created unit tests for my web project but i have come across an error whereby the tests are being ignored and Visual Studio 2012 is running my localhost instead. i cannot use localhost to run my tests as there are a lot of java resources and overlays which aren't displayed. Essentially that is the point to UI testing that you test the correct interface.

The code i used in a blank project - runs perfectly and completes the test with no issues but since i need to include this into my web project, i need a way to stop Visual Studio running the localhost and get it to execute the console application test so that my selenium webdriver can run the test properly.

using: Visual Studio 2012 Selenium (webdriver) chrome driver (latest version) c#.Net

example code:

IWebDriver _driver;

        ChromeOptions options = new ChromeOptions();
        options.AddArgument("--start-maximized");

       _driver = new ChromeDriver(options);
       _driver.Url = "http://theURLimTesting.com/";
        var verificationErrors = new StringBuilder();


        _driver.Navigate().GoToUrl("http://theURLimTesting.com/");
            _driver.FindElement(By.Id("Username")).Clear();

if anyone could help me and provide a solution as to how to run these tests without excluding them from the project and without having to create a proxy - i would be very grateful, as i am very much a novice.

UPDATE: as @mutt 's answer helped steer me towards the right direction with being able to resolve my question i marked the answer as right - i have managed to configure the error and create a work around and tweaking some settings to get this to work and now i can run all tests inside of the web application properly and they all function properly with executing and closing themselves in the background when done.

harrison
  • 79
  • 1
  • 11

1 Answers1

0

Separate your unit tests from the web project and it should work. Since you have them together your webapp probably has a default start page so when you "play" it will load that and VS is scoped to that browser running on IIS Express instead of the regular browser.

Personally I would have thought it would still work since Selenium is hitting the driver package that is referencing the browser, but I'm not sure what all VS is doing when it runs the webapp. If you want it with the console then move all your unit tests to the console project and they should still work on the WebApp because they will be hitting the server version and not the locally run project.

Update: It looks like it is process bound. So Selenium and visual studio are sharing the same process. VS2008 debugging with firefox as default browser - how to make the debugger stop/close on exit?

Update2: It looks like you should be able to determine if the process is being utilized. Then the question would be can you just kill it in your unit test script so that it will be forced to create a new one... Programmatically determine if code is running under IIS Express

Community
  • 1
  • 1
mutt
  • 783
  • 1
  • 7
  • 11
  • thanks and i mentioned when they arent in the web app they function fine the issue i have is i need them in the web app but i also need to be able to keep them in heir own projects within the web app as they are named conventionally for this, but apart from that you answer would be right im just trying to find out why or how i can stop VS over-riding the selenium driver to start with. @mutt – harrison Aug 27 '14 at 12:04
  • oh got ya...I missed that. I updated with an explanation...a little older, but I think it's the same issue., It doesn't solve the problem. If I find anything else I'll update again. – mutt Aug 27 '14 at 12:12