每次运行都报错,该导入的jar包都导入了,具体报错如下:
java.lang.IncompatibleClassChangeError: Class io.appium.java_client.remote.AppiumCommandExecutor$$Lambda$5/1128096251 does not implement the requested interface java.util.function.Supplier
at java.util.Optional.orElseGet(Optional.java:267)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:100)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:83)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
at com_qppium.my_app.AppiumTestTest.setUp(AppiumTestTest.java:49)
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:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
java.lang.NullPointerException
at com_qppium.my_app.AppiumTestTest.tearDown(AppiumTestTest.java:72)
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:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
要不换成testng试试 去掉junit相关jar
testng你会吗?
@smileTest: maven工程里添加依赖
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.9.4</version> <scope>test</scope> </dependency>
@ycyzharry: 其实testng和Junit有什么不同?
@smileTest: 看你报错很多都是junit 我在想是不是缺少什么jar 或者有什么冲突引起的
@ycyzharry: 可以加QQ或微信聊吗
@smileTest: 有问题可私信问
@ycyzharry:用了testng还是报错啊
@smileTest: 报错贴出来
@ycyzharry:
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class TestCalculator1 {
private AppiumDriver driver;
@BeforeClass
public void setup() throws Exception {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.BROWSER_NAME, "");
cap.setCapability("platformName", "Android"); // 指定测试平台
cap.setCapability("deviceName", "Android Emulator");// 指定测试机的ID,通过adb命令`adb devices`获取
cap.setCapability("platformVersion", "4.2.2");
// 将上面获取到的包名和Activity名设置为值
cap.setCapability("appPackage", "com.android.calculator2");
cap.setCapability("appActivity", "com.android.calculator2.Calculator");
// A new session could not be created的解决方法
cap.setCapability("appWaitActivity", "com.android.calculator2.Calculator");
// 每次启动时覆盖session,否则第二次后运行会报错不能新建session
cap.setCapability("sessionOverride", true);
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
@Test
public void plus() {
// 获取1
//driver.findElementById("com.android.calculator2:id/digit1").click();
driver.findElementByXPath("//android.widget.Button[contains(@text,'1')]").click();;
// 获取+
//driver.findElementById("com.android.calculator2:id/plus").click();
driver.findElementByXPath("//android.widget.Button[contains(@text,'+')]");
// 获取2
//driver.findElementById("com.android.calculator2:id/digit2").click();
driver.findElementByXPath("//android.widget.Button[contains(@text,'2')]");
// 获取=
//driver.findElementById("com.android.calculator2:id/eq").click();
driver.findElementByXPath("//android.widget.Button[contains(@text,'=')]");
//driver.findElement(By.xpath("//*[text()=’退出’])"));
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
}
}
报错:
java.lang.IncompatibleClassChangeError: Class io.appium.java_client.remote.AppiumCommandExecutor$$Lambda$5/1402433372 does not implement the requested interface java.util.function.Supplier
@smileTest: 你用的库有冲突啊 是用maven管理的还是直接加jar到build path里
@ycyzharry: 直接加jar到buildpath里的
@ycyzharry:
@smileTest: 换成maven管理库
@ycyzharry: 怎么换
@smileTest: 新建maven工程 在pom.xml里配置所有依赖库
UI自动化测试维护成本高,学习成本也高,建议转接口自动化测试,这里有一个低成本做接口测试的平台,无需代码,推荐给你。www.ironz.com