1

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

2
  • Isn't your linux code just using selenium-grid? Commented Feb 27, 2018 at 8:09
  • @ChukUltima Nope, i don't use selenium grid Commented Feb 27, 2018 at 8:15

1 Answer 1

2

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 :

class Anton { static { // if something goes wrong ExceptionInInitializerError will be thrown } } 

Static variables are initialized in static blocks and can throw these errors.


Problem :

  • In your Linux Driver Initialization code block, initially you have mentioned :

    private static DesiredCapabilities capability = DesiredCapabilities.chrome(); 
  • Then invoked the RemoteWebDriver as follows :

    driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capability); 
  • But in the following steps you have again tried to :

    System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); 

This sequence of events creates the error.

Solution :

  • As you have already declared the WebDriver instance as :

    public static WebDriver driver; 
  • Next, use System.setProperty() :

    System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); // <- remove the .exe part here following Linux style 
  • Now you need to initialize the RemoteWebDriver instance as follows :

    driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"),capability); 
  • As the WebDriver instance (which is static) and Web Browser instance is active now you must not change the attributes during the Test Execution.

Note : You can find a detailed discussion in exception in initializer error

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

4 Comments

1)System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); // <- remove the .exe part here following Linux style this part is commented on. it does't use 2) my linux code work well. 3) I need driver for linux that will work after changing System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver/for_linux");' If i do like that now, it throws me ExceptionInInitializerError
Why do you want to change System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver/for_linux"); once the driver for linux starts working ? If it is a separate usecase with different environmental settings quit() the driver and initiate a new one.
it seems that we can't understand each other:^) At windows machine i use //System.setProperty("webdriver.chrome.driver","chromedriver.exe"); on linux i tried System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver/for_linux"); but it doesn't work on linux. What i should to do in order to System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver/for_linux"); will work
As Windows setup is working, leave out Windows related discussion. Specify the problem you are facing on your Linux System.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.