For our BDD tests we use Specflow that talks to selenium 2 webdriver (Chrome driver in this instance).
While running on local host (Yes, “it works on my machine” has came up in conversation a few times) the tests work fine. They setup the data and a new webdriver, do the test and then tear down the webdriver and data. Even if a test goes horribly wrong because I’m using correct attributes the tear down is always hit and therefore driver.Quit() is run destroying the browser and the driver.
The problem arises when I run it on our server [Windows Server 2008 r2] using our continuous integration [TeamCity]. For some reason it will start to run multiple driver instances which cause the tests to fail.
Has anyone ran into this problem before and found a fix? We need a solution that uses a driver that isn’t HtmlUnitDriver.
Extra information:
- Language = C#
- Server = Windows Server 2008 R2
- CI = TeamCity
EDIT:
The Webdriver is set up by making sure that it isn’t already created and then creates a new instance of the ChromeDriver. Pseudo/real code example bellow shows how its set up, sorry I cant show the full code as it has to much fluff in that we use for other options that we stick in (e.g zap or fiddler integration / language changes etc).
Setup
[SetUp]
[BeforeScenario()]
public static void BeforeWebScenario()
{
if driver == null
driver = new ChromeDriver();
// Code to start page
}
Tear down
[TearDown]
[AfterScenario()]
public static void AfterWebScenario()
{
try
{
driver.Quit();
} catch (Exception)
{
throw Exception
}
driver = null;
}
I had this problem too. I fixed it by killing any running instances of chromedriver.exe in my testSetup() method. I used a VBScript and some Groovy code to run the scripts. Sorry this answer is kind of long.
I had this in my setUp):
isRunningByCommandLineContents:
killProcessByCommandLineContents:
And the “run the scripts part”: