Search code examples
selenium-grid2

Could not initialize class org.openqa.selenium.os.Kernel32


I am new to Selenium grid. My hub and the node is running. I tried a test to automate in the node. But I am getting the error "Could not initialize class org.openqa.selenium.os.Kernel32". I could not find the solution anywhere. Please help

My code is :

import org.testng.Assert;    
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.net.MalformedURLException;

public class TestGrid {
    WebDriver driver;
    String baseURL, nodeURL;

@BeforeTest
public void setup() throws MalformedURLException{
    baseURL = "http://newtours.demoaut.com/";
    nodeURL = "http://192.168.0.6:5566/wd/hub";
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    capability.setBrowserName("firefox");
    capability.setPlatform(Platform.WIN8);
    driver = new RemoteWebDriver(new URL(nodeURL), capability);
}

@Test
public void verifyTitle() {

   String actualTitle = driver.getTitle();
   String expectedTitle = "Welcome: Mercury Tours";
   Assert.assertEquals(actualTitle, expectedTitle);

}

@AfterTest
public void closeSetup(){
   driver.quit();
}
}

Solution

  • I had the same problem. And there was another error message appearing frequently.

    org.openqa.selenium.WebDriverException: Native library (com/sun/jna/windows-x86-64/jnidispatch.dll) not found in resource path ([file:/C:/Users/admin/work/Selenium-batch-files/Windows/selenium-server-standalone-2.47.1.jar])


    To solve the problem, I manually create selenium standalone jar file with jnidispatch.dll in correct path.

    The steps below.

    1) unzip selenium-server-standalone-2.47.1.jar using 7-zip. Then find out the "jnidispatch.dll" does exist, but no /com/sun/jna/windows-x86-64/ directory.

    2) Create a directory .../com/sun/jna/windows-x86-64/ and copy "jnidispatch.dll" in. 3) create jar file.

    "C:\Program Files\Java\jdk1.8.0_45\bin\jar.exe" cf yournewselenium.jar *

    Note: you need to be in unzipped folder.

    4) To run runSeleniumHub.bat and runSeleniumNode.bat, still complain "no menifest attribute". To fix this, change file

    From:

    call java -jar selenium-server-standalone-2.47.1.jar -role hub

    To:

    call java -cp yournewselenium.jar org.openqa.grid.selenium.GridLauncher -role hub

    And on runSeleniumNode.batch

    From:

    call java -Dos.name=windows -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe -jar selenium-server-standalone-2.47.1.jar -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS"

    To:

    call java -Dos.name=windows -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe -cp yournewselenium.jar org.openqa.grid.selenium.GridLauncher -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS"


    After the above changes, the problem is fixed. The error message not appear any more.