创建第一个Appium小程序
过程太不容易了,虽然代码是个简单的打开计算器的测试,但是执行的时候还是出现了各种问题,在国内网站上找都没有答案,最后终于在一个国外网站上找到了方法,着实不易。
1、执行的时候报异常
at io.appium.java_client.android.ListensToLogcatMessages.<clinit>(ListensToLogcatMessages.java:34)
at com.Test_appium.main(Test_appium.java:25)
Caused by: java.lang.ClassNotFoundException: javax.websocket.DeploymentException
at java.net .URLClassLoader.findClass(URLClassLoader.java:381)
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)
... 2 more
2、Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.remote.HttpCommandExecutor.<init>(Ljava/util/Map;Ljava/net/URL;Lorg/openqa/selenium/remote/http/HttpClient$Factory;)V
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:52)
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:63)
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:69)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
at a.com.main(com.java:21)
解决方法:把之前selenium-java-2.44.0这个包换成了selenium-java-2.46.0
导入的包如下:
链接: https://pan.baidu.com/s/1Tq_itEPAWeJ7cofsGvq-pw 密码: hfkd
附上个测试代码:
package a; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.remote.DesiredCapabilities; import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; public class com { public static void main(String[] args) throws InterruptedException, MalformedURLException { // TODO Auto-generated method stub AndroidDriver driver; DesiredCapabilities cap=new DesiredCapabilities(); cap.setCapability("deviceName","emulator-5554"); cap.setCapability("platformVersion", "5.1.1"); cap.setCapability("appPackage", "com.android.calculator2"); cap.setCapability("appActivity", ".Calculator"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); Thread.sleep(5000); driver.quit(); } }