线下第二期_Appium 多语言用例_20180602

依赖基础

客户端安装:pip install Appium-Python-Client
IDE:PyCharm
Python多版本隔离工具:VEnv
国内依赖源:http://pypi.douban.com/simple/
测试框架:unittest、pytest、nose

示例代码

import unittest
from appium import webdriver

class TestUnit(unittest.TestCase):
    def setUp(self):
        caps = {}
        caps['platformName'] = 'android'
        caps['deviceName'] = 'demo'
        caps['appPackage'] = "com.xueqiu.android"
        caps["appActivity"] = ".view.WelcomeActivityAlias"
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        self.driver.implicitly_wait(5)

    def test_xueqiu(self):
        self.driver.find_element_by_xpath("//*[@text='牛人牛股']").click()
        self.driver.find_element_by_xpath("//*[@text='港股掘金']").click()

    def test_xueqiu_login(self):
        self.driver.find_element_by_xpath("//*[@text='登录']").click()


生成junit styple的结果文件

pytest  --junit-xml=junit.xml test_pytest.py 

生成html结果报告

需要安装pytest

pytest  --junit-xml=junit.xml --html=report.html --self-contained-html test_pytest.py 

chromedrivewr

学会选择正确的chromedriver的版本

adb shell dumpsys package com.android.webview | grep versionName
adb shell dumpsys package com.android.chrome | grep versionName

/Users/seveniruby/projects/chromedriver/2.20/chromedriver --url-base=wd/hub --port=8000 --adb-port=5037 --verbose

示例代码

import unittest
from appium import webdriver

class TestUnit(unittest.TestCase):
    def setUp(self):
        pass

    def test_chrome(self):
        capabilities = {
            'chromeOptions': {
                'androidPackage': 'com.android.browser',
                'androidActivity': '.BrowserActivity'
            }
        }
        driver = webdriver.Remote('http://localhost:8000/wd/hub', capabilities)
        driver.get('http://www.baidu.com')

    def test_android_browser(self):

        caps = {}
        caps['platformName'] = 'android'
        caps['deviceName'] = 'demo'
        caps['browserName'] = 'Browser'
        caps['chromedriverExecutableDir']='/Users/seveniruby/projects/chromedriver/2.20'
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)

        self.driver.get("http://sogou.com")


Android里所有打开webview debug开关的进程,都会生成一个domain socket

adb shell cat /proc/net/unix | grep webview
adb forward tcp:$port  localabstract:webview_devtools_remote_$pid

http://localhost:8888/json/version

{
   "Android-Package": "com.xueqiu.android",
   "Browser": "Chrome/44.0.2403.119",
   "Protocol-Version": "1.1",
   "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Android SDK built for x86 Build/MASTER; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36",
   "WebKit-Version": "537.36 (@200258)"
}

json接口

[ {
   "description": "{\\"attached\\":true,\\"empty\\":false,\\"height\\":1478,\\"screenX\\":0,\\"screenY\\":190,\\"visible\\":true,\\"width\\":1080}",
   "devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@200258/inspector.html?ws=localhost:8888/devtools/page/BC234761-FB9F-4F48-BFF3-3D7B71CA777D",
   "faviconUrl": "https://danjuanapp.com/images/favicon_128.png",
   "id": "BC234761-FB9F-4F48-BFF3-3D7B71CA777D",
   "title": "蛋卷基金",
   "type": "page",
   "url": "https://danjuanapp.com/my-money?channel=1300100158&refer=xq_trade",
   "webSocketDebuggerUrl": "ws://localhost:8888/devtools/page/BC234761-FB9F-4F48-BFF3-3D7B71CA777D"
}, {
   "description": "{\\"attached\\":true,\\"empty\\":false,\\"height\\":1478,\\"screenX\\":0,\\"screenY\\":190,\\"visible\\":true,\\"width\\":1080}",
   "devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@200258/inspector.html?ws=localhost:8888/devtools/page/7BBB43F1-AF4B-44C1-9266-74A6F74A90BE",
   "faviconUrl": "https://assets.imedao.com/broker-us/static/images/favicon.9b631977.png",
   "id": "7BBB43F1-AF4B-44C1-9266-74A6F74A90BE",
   "title": "雪盈证券",
   "type": "page",
   "url": "https://www.snowballsecurities.com/trade",
   "webSocketDebuggerUrl": "ws://localhost:8888/devtools/page/7BBB43F1-AF4B-44C1-9266-74A6F74A90BE"
}, {
   "description": "{\\"attached\\":true,\\"empty\\":false,\\"height\\":1478,\\"screenX\\":0,\\"screenY\\":190,\\"visible\\":true,\\"width\\":1080}",
   "devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@200258/inspector.html?ws=localhost:8888/devtools/page/638B1591-F251-499F-8DDD-0EE2EE399B5C",
   "id": "638B1591-F251-499F-8DDD-0EE2EE399B5C",
   "title": "实盘交易",
   "type": "page",
   "url": "file:///android_asset/h5/modules/broker/tradeHome.html",
   "webSocketDebuggerUrl": "ws://localhost:8888/devtools/page/638B1591-F251-499F-8DDD-0EE2EE399B5C"
} ]

作业

用手机浏览器访问 testerhome.com,把截图贴到回复

关闭