3

I searched around here on stackoverflow, and it seems that many people have similar issues. However, all the fixes in those thread didn't apply to my case, so I am stuck and decided to create another question regarding this problem.

I feel like I am missing some small thing. It has worked in the beginning and now I always get these errors.

Code:

The before class, note, I use parameters in my XML to finetune behaviour:

@Parameters({"env","cleanup"})
@BeforeClass(alwaysRun=true)
public void beforeClass(String env, String cleanup) {
    System.setProperty(ESCAPE_PROPERTY, "false");
    Reporter.setEscapeHtml(false);
    ChromeOptions chromeOptions = new ChromeOptions();
    Map<String, Object> preferences = new Hashtable<String, Object>();
    chromeOptions.setExperimentalOption("prefs", preferences);
 // disable flash and the PDF viewer
    preferences.put("plugins.plugins_disabled", new String[]{
        "Adobe Flash Player", "Chrome PDF Viewer"});
    preferences.put("download.default_directory",downloadFolder+"\\"+getTestName()+" ("+env+")");

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    chromeOptions.setBinary("folder\\chrome.exe");
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);


    System.setProperty("webdriver.chrome.driver", "C:\\Users\\myname\\ChromeDriver.exe");
    driver = new AGDriver(capabilities);  
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    driver.cleanup_required = cleanup.equals("yes");
    driver.saveVariable("env", env);
}

I have created a slight variation on the webdriver to give it global state (dont judge ;) ), however I can't imagine this breaking things:

public class AGDriver extends ChromeDriver {
Map<String, String> map = new HashMap<String, String>();


public AGDriver(DesiredCapabilities capabilities) {
    super(capabilities);
}

public void saveVariable(String name, String value) {
    map.put(name, value);
}

public String getVariable(String name) {
    return map.get(name);
}

public boolean hasVariable(String name) {
    return map.containsKey(name);
}

At the end of my test case base file, I have this:

@AfterClass(alwaysRun=true)
public void afterClass() {
    try {
        if(driver.cleanup_required) {
            driver.quit();
        }
    } catch(Exception e) {
        System.out.println("Driver teardown failed");
        e.printStackTrace();
    }
}

Problem:

This results in the next errors:

afterClass 0,000s java.lang.NoClassDefFoundError: org/openqa/selenium/os/Kernel32

org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:133)
org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81)
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:247)
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:246)
org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:125)
org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:155)
org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:196)
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:94)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:701)
org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:526)
Tests.BrowserTest.afterClass(BrowserTest.java:120)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
java.lang.reflect.Method.invoke(Method.java:508)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:220)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.lang.Thread.run(Thread.java:785)

afterClass 0,000s java.lang.NoClassDefFoundError: org/openqa/selenium/os/Kernel32

org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:133)
org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81)
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:247)
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:246)
org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:125)
org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:155)
org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:196)
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:94)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:701)
org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:526)
Tests.BrowserTest.afterClass(BrowserTest.java:120)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
java.lang.reflect.Method.invoke(Method.java:508)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:220)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.lang.Thread.run(Thread.java:785)

afterClass 0,000s java.lang.NoClassDefFoundError: ##

com.sun.jna.platform.win32.Kernel32
java.lang.ClassLoader.defineClassImpl(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:346)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:154)
java.net.URLClassLoader.defineClass(URLClassLoader.java:727)
java.net.URLClassLoader.access$400(URLClassLoader.java:95)
java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1182)
java.security.AccessController.doPrivileged(AccessController.java:686)
java.net.URLClassLoader.findClass(URLClassLoader.java:602)
java.lang.ClassLoader.loadClassHelper(ClassLoader.java:846)
java.lang.ClassLoader.loadClass(ClassLoader.java:825)
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325)
java.lang.ClassLoader.loadClass(ClassLoader.java:805)
org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:133)
org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81)
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:247)
org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:246)
org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:125)
org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:155)
org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:196)
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:94)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:701)
org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:526)
Tests.BrowserTest.afterClass(BrowserTest.java:120)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
java.lang.reflect.Method.invoke(Method.java:508)
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:220)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.lang.Thread.run(Thread.java:785)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.win32.Kernel32

If some code is missing that you need, don't hesitate to ask and I will add it to the question.

Thanks in advance

TimoV
  • 51
  • 1
  • 3
  • instead of `driver.quit` try `driver.close()` method in `AfterClass` method – Naveen Kumar R B Feb 13 '17 at 09:54
  • @Naveen That seems to work. Any idea why quit wouldn't work? As far as I understand, quit is used to clean up the driver and browser when you're done, close just closes a window. Am I wrong to expect quit to work in this case? – TimoV Feb 13 '17 at 10:01
  • what you assumed is correct. close is for current window. quit is for complete cleanup (kill driver processes). what I suggested is workaround. I am not sure why `quit` is NOT working. Might be a bug in `3.0` version. – Naveen Kumar R B Feb 13 '17 at 10:05
  • Just tried. In my case restarting `Eclipse` with `Admin Privileges` solve similar issue in `Windows 10`. my answer here http://stackoverflow.com/a/42202681/2575259 – Naveen Kumar R B Feb 13 '17 at 11:15
  • what selenium jars are you using? client or server? In my case, `selenium-standalone-server-3.0.1` ran without any issues for `driver.quit` after restarting the eclipse with admin privileges. – Naveen Kumar R B Feb 13 '17 at 11:18
  • I am not supposed to run these tests with admin privilege. These are to run unattended on a server. I am using Selenium-java-2.53 (client I guess), jna 4.1 and testng 6.9.9, on windows 7 – TimoV Feb 13 '17 at 15:07

0 Answers0