Mac appium项目各种配置+简单例子

换了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();

    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,723评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,485评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,998评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,323评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,355评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,079评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,389评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,019评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,519评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,971评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,100评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,738评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,293评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,289评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,517评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,547评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,834评论 2 345

推荐阅读更多精彩内容