package com.example.ibm_admin.appiumapplication;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Calculator {
public static WebDriver driver;
@BeforeClass
public static void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "5.1.1");
capabilities.setCapability("deviceName","Galaxy On7");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCal() throws Exception {
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.tagName()
WebElement results=driver.findElement(By.tagName("EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
}
@AfterClass
public static void teardown(){
//close the app
driver.quit();
}
我正在使用android studio运行Appium脚本,想要启动计算器并执行一些基本操作(上面提到的相同脚本) 配置细节: 手机:Android Galaxy On7版本5.1.1
=============================================== ========================
" C:\ Program Files \ Android \ Android Studio1 \ jre \ bin \ java" -Didea.launcher.port = 7535" -Didea.launcher.bin.path = C:\ Program Files \ Android \ Android Studio1 \ bin" -Didea.junit.sm_runner -Dfile.encoding = UTF-8 -classpath" C:\ Program Files \ Android \ Android Studio1 \ lib \ idea_rt.jar; C:\ Program Files \ Android \ Android Studio1 \ plugins \的junit \ lib中\的junit-rt.jar中; C:\用户\ IBM_ADMIN \应用程序数据\本地\的Android \ SDK \平台\机器人-25 \数据\ RES; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\建立\中间体\类\测试\调试; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\建立\中间体\类\调试; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ cssparser-0.9.20。罐; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\公地-IO-2.5.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ GSON-2.3.1.jar; C: \用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\公地EXEC-1.3.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ hamcrest库-1.3.jar; C:\用户\ IBM_ADMIN .android \打造缓存\ f5e11fb9a80aecc042b1e5a0a008e22616eef103 \输出\罐\ CLA sses.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ f5e11fb9a80aecc042b1e5a0a008e22616eef103 \输出\ RES; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\共享记录-1.2.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\公地lang3-3.4.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ XML的API-1.4.01.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\串行 - 2.7.2.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ HttpClient的-4.5.2.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的HtmlUnit核-JS-2.23.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ネ-的HtmlUnit-2.23.jar; C:\用户\ IBM_ADMIN.android \建立高速缓冲存储器\ 31ed20e205fe04e88f6f9c1d682c13d2177bc509 \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 31ed20e205fe04e88f6f9c1d682c13d2177bc509 \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ 2fe2ad2b678efc4ad73f69c8a3492615b d8c329d \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 2fe2ad2b678efc4ad73f69c8a3492615bd8c329d \输出\ RES; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\网页套接字的客户端 - 9.2。 15.v20160210.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\公地编解码器1.10.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ JNA平台-4.1。 0.jar; C:\用户\ IBM_ADMIN \应用程序数据\本地\ Android的\ SDK \演员\机器人\ m2repository \ COM \机器人\ SUPPORT \支持的注解\ 25.3.1 \支持的注解 - 25.3.1.jar; C ^ :\用户\ IBM_ADMIN.android \建立缓存\ b99db0eff410f981260c96c15666c5f8fe9a49ab \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ b99db0eff410f981260c96c15666c5f8fe9a49ab \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ phantomjsdriver-1.3.0.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 44bed11ecf8df53c9723650ed9ff51385b015d22 \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 44bed1 1ecf8df53c9723650ed9ff51385b015d22 \输出\ RES; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\网状-3.5.7.Final.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ SAC-1.3。罐; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的Xalan-2.7.2.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ xercesImpl-2.11.0.jar; C: \用户\ IBM_ADMIN.android \建立缓存\ 4e891577e853101408c8d4643249ea1f5e61aaeb \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ 4e891577e853101408c8d4643249ea1f5e61aaeb \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\码头-util的-9.2.13.v20150730.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的WebSocket-API-9.2.15.v20160210.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\客户联合3.0.1-nodeps.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 56dfe4f79683d5a268a8fd83c825385ee11d17fa \输出\ RES; C:\用户\ IBM_ADMIN.a ndroid \建立缓存\ 56dfe4f79683d5a268a8fd83c825385ee11d17fa \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 786a62bf30d44d628103e6d67d25594af339666b \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建设 - 缓存\ 786a62bf30d44d628103e6d67d25594af339666b \输出\ RES; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ CGLIB的节点p-3.2.4.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ websocket-共9.2.15.v20160210.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的HtmlUnit-2.23.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ JNA-4.1。 0.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\码头-IO-9.2.13.v20150730.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ de3291f937c3d61774b897952ccc113f29a25f23 \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ de3291f937c3d61774b897952ccc113f29a25f23 \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ 4a692d1d348a979cd770289fd fe056689d947924 \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ 4a692d1d348a979cd770289fdfe056689d947924 \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ Java的客户端 - 4.14。罐; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ httpmime-4.5.2.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\番石榴19.0.jar; C:\用户\ IBM_ADMIN \应用程序数据\本地\ Android的\ SDK \演员\ m2repository \ COM \机器人\ SUPPORT \约束\约束的布局求解器\ 1.0.2 \约束的布局求解器-1.0.2.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的HttpCore-4.4.4.jar; C:\用户\ IBM_ADMIN.gradle \缓存\模块-2 \文件-2.1 \ org.hamcrest \ hamcrest核\ 1.3 \ 42a25dc3219429f0e5d060061f71acb49bf010a0 \ hamcrest -core-1.3.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\ hamcrest核-1.3.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的javax.servlet-API -3.1.0.jar; C:\用户\ IBM_ADMIN.gradle \ CA CHES \模块-2 \文件-2.1 \的junit \的junit \ 4.12 \ 2973d150c0dc1fefe998f834810d68f278ea58ec \的junit-4.12.jar; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\库\的junit-4.12.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 584b968c37726e3ea7b73a3cc08f74a47959bd80 \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 584b968c37726e3ea7b73a3cc08f74a47959bd80 \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ 3b2edeb370f0e07064b0570bcce8b89a5d8dc9c6 \输出\罐\ classes.jar; C:\用户\ IBM_ADMIN.android \建立缓存\ 3b2edeb370f0e07064b0570bcce8b89a5d8dc9c6 \输出\ RES; C:\用户\ IBM_ADMIN.android \建立缓存\ 6462712a35fa855d973b09af396f58c2f8321516 \输出\罐子\类。罐; C:\用户\ IBM_ADMIN.android \建立缓存\ 6462712a35fa855d973b09af396f58c2f8321516 \输出\ RES; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \应用\建立\中间体\ sourceFolderJavaResources \测试\调试; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \程序\编译\中间体\ sourceFolderJavaResources \调试; C:\用户\ IBM_ADMIN \ AndroidStudioProjects \ AppiumApplication \建立\生成\ mockable-机器人-25.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.example.ibm_admin.appiumapplication.CalculatorTest 2017年7月12日下午9:44:34 org.openqa.selenium.remote.ProtocolHandshake createSession 信息:尝试双方言会议,假设Postel的法律在远程端是正确的
org.openqa.selenium.SessionNotCreatedException:无法创建新会话。 (原始错误:用于启动应用程序的活动不存在或无法启动!确保它存在并且是可启动的活动)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:0毫秒 建立信息:版本:'未知',修订版:' 1969d75',时间:' 2016-10-18 09:43:45 -0700' 系统信息:主机:' IBM372-PC09Z6VS',ip:' 192.168.1.5',os.name:' Windows 7',os.arch:&# 39; amd64',os.version:' 6.1',java.version:' 1.8.0_112-release' 驱动程序信息:driver.version:RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:161)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
at com.example.ibm_admin.appiumapplication.CalculatorTest.setUp(CalculatorTest.java:59)
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.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
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:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
测试被忽略。 显示java.lang.NullPointerException at com.example.ibm_admin.appiumapplication.CalculatorTest.End(CalculatorTest.java:89) 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) 在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50) 在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33) 在org.junit.runners.ParentRunner.run(ParentRunner.java:363) 在org.junit.runner.JUnitCore.run(JUnitCore.java:137) 在com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) 在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) 在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) 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) 在com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
处理以退出代码-1
结束答案 0 :(得分:0)
在提出我自己的变体之前,我已经与这个着名的例子搏斗了一段时间。实际的驱动程序创建显示为下面的方法,驱动程序类型变为AndroidDriver:
{{1}}