换了Mac,之前Windows运行的例子也需要实践起来了
appium用得比较多,范围也广,先配置起来
appium安装
确认已安装以下软件
java git ruby brew node npm
通过 -v 检验是否安装
xcode自带git,Android studio自带SDK
如果都有安装,可以开始安装appium了
appium有两种安装方式:一种命令行、一种dmg直接安装
命令行安装:
npm install -g appium (-g是全局的意思)
npm --registry http://registry.cnpmjs.org install -g appium (国内镜像)
npm install wd
appium官网给出安装appium客户端的方法。会安装失败,可以GitHub下载appium分支下的Python-client,cd到该文件夹下,使用python setup.py install进行安装
dmg安装:
上官网下载dmg(appium下载地址),直接傻瓜式安装即可
安装xcode & sdk
安装appium-doctor。网上的资料都说appium提供了一个工具用来检测是否安装完全,但是没人说appium-doctor是需要安装的,结果试了老半天,结果都是command not found
npm install -g appium-doctor
直接使用dmg安装的appium,就不用下载安装appium-doctor了,默认在安装路径下就有了(/Applications/Appium.app/Contents/Resources/node_modules)
配置环境变量
打开终端,依次输入命令
touch .bash_profile (创建文件或修改文件时间)
open -e .bash_profile (-e Opens with TextEdit)
此时会自动打开文本,在文本中添加然后保存
export ANDROID_HOME=/Users/apple/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home(jdk安装版本根据本机已安装的选择)
export JAVA_HOME
export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools":
export PATH=${PATH}:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$JAVA_HOME/bin
其中ANDROID_HOME为下载的sdk存放的路径
然后在终端中输入命令
source .bash_profile
ok,环境变量设置好了,现在可以试试在终端窗口输入adb回车,不显示command not found即为成功
输出某个环境变量的值
echo $ANDORID_HOME
****使用dmg安装时,如果是新版的系统10.12,会提示不支持,需要更改本机system.js文件**
参考appium不支持Mac10.12
**本机的命令行如果有更改成zsh,需要更新下文件~/.zshrc,解决每次都要输入source ~/.bash_profile才能生效配置文件的问题
在终端输入vim ~/.zshrc
加一句source ~/.bash_profile
下载与本机相对应的chromedriver替换
路径:/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac
好了,配置成功一切,可以开始运行了
1.启动appium
2.打开idea,新建maven项目(按照正常步骤新建即可)
先来一个appium实践手机版网页的例子
public class BrowserTest {
AppiumDriver driver;
@BeforeMethod
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
// File app=new File("./apk/Chrome-Browser.apk");
capabilities.setCapability("device","Android");
capabilities.setCapability("deviceName","YQ601");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("platformVersion", "5.1.1");
capabilities.setCapability("unicodeKeyboard",true);//解决非英文字符的输入问题
capabilities.setCapability("resetKeyboard",true);
capabilities.setCapability("browserName","Chrome");
// capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("noReset",true);//不重装app
capabilities.setCapability("noSign",true);//不进行重签名
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity","com.google.android.apps.chrome.ChromeTabbedActivity");
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
}
@Test
public void testBrowser() throws Exception {
Thread.sleep(20000);
driver.get("http://www.baidu.com");
driver.findElement(By.id("index-kw")).sendKeys("selenium 配置");
driver.findElement(By.id("index-bn")).click();
Thread.sleep(2000);
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
}
查看appium上的日志(好长好长啊)
/**把setup的信息传给appium**/
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.android.chrome","appActivity":"com.google.android.apps.chrome.ChromeTabbedActivity","noReset":true,"noSign":true,"platformVersion":"5.1.1","browserName":"Chrome","unicodeKeyboard":true,"platformName":"Android","device":"Android","deviceName":"YQ601","resetKeyboard":true}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"appPackage":"com.android...
[Appium] Creating new AndroidDriver session
[Appium] Capabilities:
[Appium] appPackage: 'com.android.chrome'
[Appium] appActivity: 'com.google.android.apps.chrome.ChromeTabbedActivity'
[Appium] noReset: true
[Appium] noSign: true
[Appium] platformVersion: '5.1.1'
[Appium] browserName: 'Chrome'
[Appium] unicodeKeyboard: true
[Appium] platformName: 'Android'
[Appium] device: 'Android'
[Appium] deviceName: 'YQ601'
[Appium] resetKeyboard: true
[Appium] automationName: 'Appium'
[BaseDriver] The following capabilities were provided, but are not recognized by appium: device.
[BaseDriver] Session created with session id: ffbac030-bed2-4b09-865a-4eba369bdd08
/**获取Java版本**/
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_121
/**chrome项目,获取package和mainactivity**/
[AndroidDriver] We're going to run a Chrome-based session
[AndroidDriver] Chrome-type package and activity are com.android.chrome and com.google.android.apps.chrome.Main
/**获取adb信息**/
[ADB] Checking whether adb is present
[ADB] Using adb from /Users/apple/Library/Android/sdk/platform-tools/adb
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android 5.1.1
[debug] [ADB] Setting device id to ee1fcdf
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","getprop","ro.build.version.release"]
[AndroidDriver] Using device: ee1fcdf
[ADB] Checking whether adb is present
[ADB] Using adb from /Users/apple/Library/Android/sdk/platform-tools/adb
[debug] [ADB] Setting device id to ee1fcdf
[AndroidDriver] App file was not listed, instead we're going to run com.android.chrome directly on the device
[debug] [AndroidDriver] Checking whether package is present on the device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","pm","list","packages","com.android.chrome"]//查找第三方软件
[AndroidDriver] Starting Android session
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","echo","ping"]
[debug] [Logcat] Starting logcat capture
/**解决非英文字符的问题**/
[debug] [AndroidDriver] Enabling Unicode keyboard support
[debug] [AndroidDriver] Pushing unicode ime to device...
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","install","/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk"]//安装UnicodeIME-debug.apk
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","settings","get","secure","default_input_method"]
[debug] [AndroidDriver] Unsetting previous IME com.iflytek.inputmethod.smartisan/com.iflytek.inputmethod.FlyIME
[debug] [AndroidDriver] Setting IME to 'io.appium.android.ime/.UnicodeIME'
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","ime","enable","io.appium.android.ime/.UnicodeIME"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","ime","set","io.appium.android.ime/.UnicodeIME"]//设置默认输入法
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","install","/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/io.appium.settings/bin/settings_apk-debug.apk"]
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","install","/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-unlock/bin/unlock_apk-debug.apk"]//安装不锁屏设置apk
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","getprop","ro.build.version.release"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","forward","tcp:4724","tcp:4724"]
/**开始运行。。底层是UiAutomator**/
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","push","/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar","/data/local/tmp/"]//把AppiumBootstrap.jar推到手机/data/local/tmp目录下
/**确认本机只有一个uiautomator在运行**/
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","ps","uiautomator"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: -P, 5037, -s, ee1fcdf, shell, uiautomator, runtest, AppiumBootstrap.jar, -c, io.appium.android.bootstrap.Bootstrap, -e, pkg, com.android.chrome, -e, disableAndroidWatchers, false, -e, acceptSslCerts, false
[debug] [UiAutomator] Moving to state 'online'
[AndroidBootstrap] Android bootstrap socket is now connected
[AndroidDriver] Starting a chrome-based browser session
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver.*--port=9515"
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=9515 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 9515
Only local connections are allowed.
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"stat...
[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"ch...
[JSONWP Proxy] Got response with status 200: {"sessionId":"5d1763a273913...
[debug] [Chromedriver] Changed state to 'online'
[Appium] New AndroidDriver session created successfully, session ffbac030-bed2-4b09-865a-4eba369bdd08 added to master session list
[MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webSto...
[HTTP] <-- POST /wd/hub/session 200 9547 ms - 934
/**打开url**/
[HTTP] --> POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/url {"url":"http://www.baidu.com"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/url] to [POST http://127.0.0.1:9515/wd/hub/session/5d1763a2739131f1be2f46463e661418/url] with body: {"url":"http://www.baidu.com"}
[JSONWP Proxy] Got response with status 200: {"sessionId":"5d1763a273913...
[JSONWP Proxy] Replacing sessionId 5d1763a2739131f1be2f46463e661418 with ffbac030-bed2-4b09-865a-4eba369bdd08
[HTTP] <-- POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/url 200 3250 ms - 76
[HTTP] --> POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element {"using":"id","value":"index-kw"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
/**查找元素**/
[JSONWP Proxy] Proxying [POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element] to [POST http://127.0.0.1:9515/wd/hub/session/5d1763a2739131f1be2f46463e661418/element] with body: {"using":"id","value":"inde...
[JSONWP Proxy] Got response with status 200: {"sessionId":"5d1763a273913...
[JSONWP Proxy] Replacing sessionId 5d1763a2739131f1be2f46463e661418 with ffbac030-bed2-4b09-865a-4eba369bdd08
[HTTP] <-- POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element 200 195 ms - 107
/**输入文本**/
[HTTP] --> POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element/0.39210579132394296-1/value {"id":"0.39210579132394296-1","value":["selenium 配置"]}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element/0.39210579132394296-1/value] to [POST http://127.0.0.1:9515/wd/hub/session/5d1763a2739131f1be2f46463e661418/element/0.39210579132394296-1/value] with body: {"id":"0.39210579132394296-...
[JSONWP Proxy] Got response with status 200: {"sessionId":"5d1763a273913...
[JSONWP Proxy] Replacing sessionId 5d1763a2739131f1be2f46463e661418 with ffbac030-bed2-4b09-865a-4eba369bdd08
[HTTP] <-- POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element/0.39210579132394296-1/value 200 1195 ms - 76
/**搜索按钮,并且点击**/
[HTTP] --> POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element {"using":"id","value":"index-bn"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element] to [POST http://127.0.0.1:9515/wd/hub/session/5d1763a2739131f1be2f46463e661418/element] with body: {"using":"id","value":"inde...
[JSONWP Proxy] Got response with status 200: {"sessionId":"5d1763a273913...
[JSONWP Proxy] Replacing sessionId 5d1763a2739131f1be2f46463e661418 with ffbac030-bed2-4b09-865a-4eba369bdd08
[HTTP] <-- POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element 200 139 ms - 107
[HTTP] --> POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element/0.39210579132394296-2/click {"id":"0.39210579132394296-2"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element/0.39210579132394296-2/click] to [POST http://127.0.0.1:9515/wd/hub/session/5d1763a2739131f1be2f46463e661418/element/0.39210579132394296-2/click] with body: {"id":"0.39210579132394296-2"}
[JSONWP Proxy] Got response with status 200: {"sessionId":"5d1763a273913...
[JSONWP Proxy] Replacing sessionId 5d1763a2739131f1be2f46463e661418 with ffbac030-bed2-4b09-865a-4eba369bdd08
[HTTP] <-- POST /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08/element/0.39210579132394296-2/click 200 8476 ms - 76
/**teardown**/
[HTTP] --> DELETE /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08 {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: ["ffbac030-bed2-4b09-865a-4...
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Stopping chromedriver for context CHROMIUM
[debug] [Chromedriver] Changed state to 'stopping'
[JSONWP Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/5d1763a2739131f1be2f46463e661418] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"5d1763a27...
[debug] [Chromedriver] Changed state to 'stopped'
[debug] [AndroidDriver] Resetting IME to com.iflytek.inputmethod.smartisan/com.iflytek.inputmethod.FlyIME
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","ime","set","com.iflytek.inputmethod.smartisan/com.iflytek.inputmethod.FlyIME"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","am","force-stop","io.appium.unlock"]
[debug] [ADB] Pressing the HOME button
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","input","keyevent",3]
[debug] [Logcat] Stopping logcat capture
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/apple/Library/Android/sdk/platform-tools/adb with args: ["-P",5037,"-s","ee1fcdf","shell","ps","uiautomator"]
[HTTP] --> GET /wd/hub/status {}
[MJSONWP] Calling AppiumDriver.getStatus() with args: []
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'
[Appium] Removing session ffbac030-bed2-4b09-865a-4eba369bdd08 from our master session list
[debug] [MJSONWP] Received response: null
[debug] [MJSONWP] But deleting session, so not returning
[MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/ffbac030-bed2-4b09-865a-4eba369bdd08 200 3128 ms - 76
[MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
[HTTP] <-- GET /wd/hub/status 200 56 ms - 83
再来个app的例子
public class AppiumTest01 {
AppiumDriver driver;
@BeforeMethod
public void setUp() throws Exception {
File app = new File("./apk/duokan.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","YQ601");
capabilities.setCapability("platformVersion", "5.1.1");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("noSign",true);//不进行重签名
capabilities.setCapability("unicodeKeyboard",true);//解决非英文字符的输入问题
capabilities.setCapability("resetKeyboard",true);
capabilities.setCapability("noReset",true);//不重装app
capabilities.setCapability("appActivity", "com.duokan.reader.DkReaderActivity");//获取app的启动activity
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
}
@Test
public void testAppium() throws Exception {
driver.findElement(By.id("com.duokan.reader:id/bookshelf__sign_in_view__sign")).click();
driver.findElement(By.id("android:id/up")).click();
driver.findElement(By.name("书城")).click();
// 转webview
Set<String> contextNames=driver.getContextHandles();
for (String contextName:contextNames){
System.out.println("-------------"+contextName);
}
String last=contextNames.toArray()[contextNames.size()-1].toString();
if (last.contains("WEBVIEW")){
driver.context(last);
}
WebDriverWait wait=new WebDriverWait(driver,10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"root\"]/div/ul[1]/li[5]/div/a")));
driver.findElement(By.xpath("//*[@id=\"root\"]/div/ul[1]/li[5]/div/a")).click();
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
}