第八期_移动自动化测试实战_20190303

Android测试进阶

uiautomator定位

  • new UiSelector().className(“android.widget.TextView”).instance(5)
  • new UiSelector().text(“开启”)
  • new UiScrollable(new UiSelector().scrollable(true).instance(1)).getChildByText(new UiSelector().className(“android.widget.TextView”), “燕京啤酒”)
  • new UiScrollable(new UiSelector().className(“android.widget.ListView”).instance(0)).scrollIntoView(new UiSelector().text(“WebView”).instance(0))
  • new UiScrollable(new UiSelector().className(“android.support.v7.widget.RecyclerView”).instance(1)).scrollIntoView(new UiSelector().text(“燕京啤酒”).instance(0))

Toast

WebDriver协议分析

[HTTP] --> POST /wd/hub/session/a346f8c2-6d47-4023-9bb6-fb1c9d92ef14/element
[HTTP] {"using":"xpath","value":"//*[@text='Search']","sessionId":"a346f8c2-6d47-4023-9bb6-fb1c9d92ef14"}
[debug] [W3C (a346f8c2)] Calling AppiumDriver.findElement() with args: ["xpath","//*[@text='Search']","a346f8c2-6d47-4023-9bb6-fb1c9d92ef14"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [JSONWP Proxy] Matched '/element' to command name 'findElement'
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d/element] with body: {"strategy":"xpath","selector":"//*[@text='Search']","context":"","multiple":false}
[JSONWP Proxy] Got an unexpected response: {"sessionId":"a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d","status":7,"value":"An element could not be located on the page using the given search parameters."}
[debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[debug] [BaseDriver] Waited for 296 ms so far
[debug] [JSONWP Proxy] Matched '/element' to command name 'findElement'
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d/element] with body: {"strategy":"xpath","selector":"//*[@text='Search']","context":"","multiple":false}
[JSONWP Proxy] Got an unexpected response: {"sessionId":"a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d","status":7,"value":"An element could not be located on the page using the given search parameters."}
[debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[debug] [BaseDriver] Waited for 1695 ms so far
[debug] [JSONWP Proxy] Matched '/element' to command name 'findElement'
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d/element] with body: {"strategy":"xpath","selector":"//*[@text='Search']","context":"","multiple":false}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d","status":0,"value":{"ELEMENT":"a01cdaef-f2ea-4054-8f58-8d593cc37f01"}}
[debug] [W3C (a346f8c2)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"a01cdaef-f2ea-4054-8f58-8d593cc37f01"}
[HTTP] <-- POST /wd/hub/session/a346f8c2-6d47-4023-9bb6-fb1c9d92ef14/element 200 2687 ms - 88
[HTTP]
[HTTP] --> POST /wd/hub/session/a346f8c2-6d47-4023-9bb6-fb1c9d92ef14/element/a01cdaef-f2ea-4054-8f58-8d593cc37f01/click
[HTTP] {"id":"a01cdaef-f2ea-4054-8f58-8d593cc37f01","sessionId":"a346f8c2-6d47-4023-9bb6-fb1c9d92ef14"}
[debug] [W3C (a346f8c2)] Calling AppiumDriver.click() with args: ["a01cdaef-f2ea-4054-8f58-8d593cc37f01","a346f8c2-6d47-4023-9bb6-fb1c9d92ef14"]
[debug] [JSONWP Proxy] Matched '/element/a01cdaef-f2ea-4054-8f58-8d593cc37f01/click' to command name 'click'
[debug] [JSONWP Proxy] Proxying [POST /element/a01cdaef-f2ea-4054-8f58-8d593cc37f01/click] to [POST http://localhost:8200/wd/hub/session/a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d/element/a01cdaef-f2ea-4054-8f58-8d593cc37f01/click] with body: {"element":"a01cdaef-f2ea-4054-8f58-8d593cc37f01"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"a929b6dd-f6cc-490a-bd14-3ead9ba0ff7d","status":0,"value":true}
[debug] [W3C (a346f8c2)] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/a346f8c2-6d47-4023-9bb6-fb1c9d92ef14/element/a01cdaef-f2ea-4054-8f58-8d593cc37f01/click 200 120 ms - 14
[HTTP]

webdriver协议基础知识要懂

session_id获取
session_id=`curl http://127.0.0.1:4723/wd/hub/sessions | awk -F\\" '{print $8}' `
element id获取
curl -X POST   http://127.0.0.1:4723/wd/hub/session/$session_id/elements \\
--data-binary '{"using":"xpath","value":"//*[@class=\\"android.widget.Toast\\"]"}' \\
-H "Content-Type: application/json;charset=UTF-8"
元素属性获取
curl http://127.0.0.1:4723/wd/hub/session/$session_id/element/$element_id/attribute/text
元素动作
curl -X POST http://127.0.0.1:4723/wd/hub/session/$session_id/element/$element_id/click

8200端口也是可以接受post请求完成自动化的

WebView

    def test_webview_sim_image(self):
        self.loaded()
        self.driver.find_element_by_xpath("//*[@text='交易']").click()
        self.driver.find_element_by_accessibility_id("15da75b0b28c2b23feda8fe7").click()


    def test_webview_sim_h5(self):
        self.loaded()
        self.driver.find_element_by_xpath("//*[@text='交易']").click()
        for i in range(10):
            sleep(0.5)
            print(self.driver.contexts)
            print(self.driver.current_context)

·

[debug] [Chromedriver] The following Chromedriver executables were found:
[debug] [Chromedriver]     /usr/local/lib/node_modules/appium/node_modules/_appium-chromedriver@4.9.0@appium-chromedriver/chromedriver/mac/chromedriver (minimum Chrome version '69.0.3497')

[debug] [Chromedriver] Found Chrome bundle 'com.android.webview' version '44.0.2403'
[Chromedriver] Error: No Chromedriver found that can automate Chrome '44.0.2403'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details.

使用特定版本的chromedriver https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md

  • appium --chromedriver-executable /Users/seveniruby/projects/chromedriver/2.20/chromedriver
  • caps设置 chromedriverExecutableDir chromedriverExecutable chromedriverChromeMappingFile

真机做webview的测试 https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews?hl=zh-cn

移动测试实战 基于Page Object完成测试用例设计与实现

作业1

封装一个滚动方法,swipe(by, director) return element

作业2

用shell封装换一个简单的function find “//*[@text=‘xxx’]” click input

作业3

交易 -> 基金 -> 已有蛋卷基金账户登录 -> 使用密码登陆 -> 输入用户名密码 -> 登录

作业4

添加股票到自选改造为po

关闭