Selenium / TestNG:afterClass后配置失败

时间:2017-02-13 09:49:19

标签: java selenium testng

我在这里搜索stackoverflow,似乎很多人都有类似的问题。但是,这些线程中的所有修复都不适用于我的情况,因此我陷入困境并决定创建另一个有关此问题的问题。

我觉得我错过了一些小事。它起初有效,现在我总是遇到这些错误。

代码:

在课前,请注意,我在XML中使用参数来微调行为:

@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);
}

我已经在webdriver上创建了一个轻微的变体来赋予它全局状态(不要判断;)),但是我无法想象这会破坏这些东西:

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);
}

在我的测试用例库文件的末尾,我有这个:

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

问题:

这会导致下一个错误:

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

如果您缺少某些代码,请不要犹豫,我会将其添加到问题中。

提前致谢

0 个答案:

没有答案