我为Android应用程序编写了一些自动化测试一切正常但是当我在测试完成后停止AppiumDriverLocalService时它会中断.....
这是代码(使用JUnit编写)
@AfterClass
public static void stopServer(){
service.stop(); //this is where the code breaks
}
堆栈跟踪
java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Kernel32
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.openqa.selenium.os.ProcessUtils.killWinProcess(ProcessUtils.java:133)
at org.openqa.selenium.os.ProcessUtils.killProcess(ProcessUtils.java:81)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.destroyHarder(UnixProcess.java:247)
at org.openqa.selenium.os.UnixProcess$SeleniumWatchDog.access$2(UnixProcess.java:246)
at org.openqa.selenium.os.UnixProcess.destroy(UnixProcess.java:125)
at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
at io.appium.java_client.service.local.AppiumDriverLocalService.destroyProcess(AppiumDriverLocalService.java:141)
at io.appium.java_client.service.local.AppiumDriverLocalService.stop(AppiumDriverLocalService.java:135)
at com.example.MyTests.stopServer(MyTests.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.platform.win32.Kernel32
奇怪的是,在我的班级中创建了另一个名为“Class Configuration”的测试用例,我还没写过。
我错过了一些jar文件吗?我很确定缺少一些东西。请详细说明一下。提前谢谢。
答案 0 :(得分:-1)
您的问题是由于缺少jar(在项目的参考库中)包含:
com/sun/jna/platform/win32/Kernel32
您应该可以在此处下载它的依赖项:
http://www.java2s.com/Code/Jar/j/Downloadjna330platformjar.htm
http://www.java2s.com/Code/Jar/j/Downloadjna330jar.htm
将它们导入您的项目。
也是您停止服务的方式,这是错误的,因为可能是由于某些其他原因您的服务已经终止。请使用以下代码检查服务是否确实存在。
private void stopAppiumServer() {
if (service != null) {
service.stop();
System.out.println("Appium Server Stopped");
}