我正在使用appium来自动化移动应用程序但是当我尝试在应用程序上执行某些操作,即单击登录按钮时,在模拟器或移动设备上启动应用程序之后发生上述异常...是否有人知道什么是错误的?它> Error Screenshot
完整代码如下
import static org.junit.Assert.*;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
public class selendriodCase {
@Test
public void test() throws MalformedURLException, InterruptedException {
File appDir = new File("src");
File app = new File(appDir, "EZMD1.apk");
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
// specify the application package that we copied from appium
cap.setCapability("appPackage", "com.mentor.mobile.csp.ezmobiledocs");
// specify the application activity that we copied from appium
cap.setCapability("appActivity", "com.mentor.mobile.csp.ezmobiledocs.SplashActivity");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "100");
System.out.println("ahmad");
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
AndroidDriver ds = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
//AndroidDriver driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap );
System.out.println("ahmad");
Thread.sleep(10000);
ds.findElementById("com.mentor.mobile.csp.ezmobiledocs:id/facebook").click();
}
}
执行单击操作时,它会显示以下异常
org.openqa.selenium.WebDriverException: No command or response codec has been defined. Unable to proceed
Build info: version: 'unknown', revision: '3169782', time: '2016-09-29 10:24:50 -0700'
System info: host: 'PKL-AIQBAL-W7', ip: '137.202.157.127', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:153)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:369)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:418)
at DesiredCap.test(DesiredCap.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
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:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)enter code here
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
答案 0 :(得分:3)
尝试使用下面的最新jar文件
http://central.maven.org/maven2/io/appium/java-client/4.0.0/java-client-4.0.0.jar
ds = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
试试这个它会起作用。
答案 1 :(得分:2)
请将您的java-client
版本(jar文件)更新为最新版本。我从4.0更新到4.1.2,它对我有用。
Here