I'm creating tests(ui tests) on windows 10 machine. They works well, but few days ago my boss told me that we need to run our tests on linux. I'm downloaded linux driver and change it in System.setProperty("webdriver.chrome.driver", "chromedriver");
but after trying to run this test i got java.lang.ExceptionInInitializerError
(it was latest driver with latest browser). After it i changed my code that allow me to run test, but connection to driver is remote. I don't like this way. May be some one of you know which driver will work on linux without code change in driver initialization part?
E.g. windows driver initialization :
private static WebDriver driver = new ChromeDriver();
private static WebDriverWait wait = new WebDriverWait(driver, 30);
@Given("^blah blah$")
public void some_method() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
}
linux driver initialization :
public abstract class InitDrivers{
private static DesiredCapabilities capability = DesiredCapabilities.chrome();
public static WebDriver driver;
static {
try {
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public static WebDriverWait wait = new WebDriverWait(driver, 30);
public class CallDoctorTestStep extends InitDrivers{
@Given("^blah blah$")
public void some_method() throws MalformedURLException{
//System.setProperty("webdriver.chrome.driver","chromedriver.exe");
}
See solution in Selenium NoSuchSession on linux
java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
implies that an unexpected exception has occurred in a Static Initializer. This error is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.An ExceptionInInitializerError is raised if something goes wrong in the static initializer block. An example below :
Static variables are initialized in static blocks and can throw these errors.
Problem :
In your Linux Driver Initialization code block, initially you have mentioned :
Then invoked the RemoteWebDriver as follows :
But in the following steps you have again tried to :
This sequence of events creates the error.
Solution :
As you have already declared the WebDriver instance as :
Next, use
System.setProperty()
:Now you need to initialize the RemoteWebDriver instance as follows :
As the WebDriver instance (which is
static
) and Web Browser instance is active now you must not change the attributes during the Test Execution.