Though, when I start a test, it launches two instances of my custom webdriver. The first without a profile, and the second correct. Interestingly, the first one stays in the background and does nothing. The second one works like a charm. Ok, to the problem in the debugger: I run the test, and it runs to...
>Runs to WebDriverFactory.class->newWebdriverInstance(driverClass), and in that to cause = this.providedDriver();
>In WebdriverFactory.class providedDriver() is called, and there new ProvidedDriverConfiguration(this.environmentVariables);
>In ProvidedDriverConfiguration.class the constructor is called
>Now in providedDriver() in WebDriverFactory.class the return sourceConfig.getDriverSource().newDriver() in the try/catch-block is executed
>In ProvidedDriverConfiguration.class the getDriverSource() is executed, this.getDriverName() leads to "myFirefoxName"
>In its try/catch-block, the return (DriverSource)Class.forName(providedImplementation).newInstance() calls constructors of FirefoxDriver.java,
which leads 1st Firefox window to show up, with null profile
>In ProvidedDriverConfiguration.class->getDriverSource() the try/catch-block is further executed, and the newDriver() part of return sourceConfig.getDriverSource().newDriver() is called
>Now it runs through my custom webdriver, and in the end I make a new (customized) firefox, so FirefoxDriver.java constructors are called (well, the super(), as before)
>New firefox window pops up, with my profile
>Now WebDriverFactory.class->providedDriver() has ended, jumps back to newWebdriverInstance(), and test runs normaly. Though, the first null-profile firefox stays open
and does nothing.
The problem is, therefore, that in return sourceConfig.getDriverSource().newDriver(); both .getDriverSource() and .newDriver() create a new Webdriver.
In .getDriverSource() the return (DriverSource)Class.forName(providedImplementation).newInstance() creates a webdriver too, and afterwards, the .newDriver()
is called, making another webdriver. Same is true for custom phantomjs. My custom webdriver classes have nothing fancy, it's like
public class myFirefoxName implements IAppWebDriver,DriverSource {
String testClassName;
@Override
public WebDriver newDriver(){
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "de");
return new FirefoxDriver(profile);
}
@Override
public boolean takesScreenshots(){
return true;
}
@Override
public String getTestClassName() {
return testClassName;
}
@Override
public void setTestClassName(String testClassName) {
this.testClassName = testClassName;
}
}
When I remove the IAppWebDriver implementation, and of course the setter and getter, only one working instance is created. Bug or feature?