• 微信 webview 的自动化技术 at January 10, 2017

    @dzousigma @weijiatiancai

    from appium import webdriver
    ***********
    def setUp(self):

    desired_caps = {
    'platformName': 'Android',
    'fastReset': 'false',
    'deviceName': 'm1_note',
    'appPackage': 'com.tencent.mm',
    'appActivity': '.ui.LauncherUI',
    'fullReset': 'false',
    'unicodeKeyboard': 'True',
    'resetKeyboard': 'True',
    'chromeOptions': {
    'androidProcess' : 'com.tencent.mm:appbrand3'
    }
    }

    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    com.tencent.mm:appbrand3这个根据webview的context改
    这是setUp方法的写法,已经可以切到微信的webview了,不过有一些webview控件定位的细节还是不太懂,谁弄明白搞一份示例代码贴出来谢谢了

  • 微信 webview 的自动化技术 at January 10, 2017

    @seveniruby 可以了!谢谢

  • 微信 webview 的自动化技术 at January 10, 2017

    @seveniruby 没有哇,无论如何就是切不到webview,contests是可以打印出来的,这是代码

    #encoding: utf-8
    import os
    import unittest
    import selenium
    from appium import webdriver
    from time import sleep

    PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
    )

    class xcxTests(unittest.TestCase):
    def setUp(self):
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['fastReset'] = 'false'
    desired_caps['fastReset'] = 'false'
    desired_caps['deviceName'] = 'm1_note'
    desired_caps['appPackage'] = 'com.tencent.mm'
    desired_caps['appActivity'] = '.ui.LauncherUI'
    desired_caps['fullReset'] = 'false'
    desired_caps['unicodeKeyboard'] = 'True'
    desired_caps['resetKeyboard'] = 'True'

    options = selenium.webdriver.ChromeOptions()
    options.add_experimental_option('androidProcess', 'com.tencent.mm:tools')

    desired_caps['ChromeOptions.CAPABILITY'] = 'options'

    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
    self.driver.quit()

    def test_didibus(self):
    self.driver.find_element_by_name('发现').click()
    self.driver.find_element_by_name('小程序').click()
    self.driver.find_element_by_name('搜索').click()
    sleep(5)
    self.driver.find_element_by_class_name('android.widget.EditText').send_keys('滴滴公交查询')
    os.popen('adb shell ime set com.meizu.flyme.input/com.meizu.input.MzInputService')
    self.driver.find_element_by_class_name('android.widget.EditText').click()
    os.popen('adb shell input keyevent 66')
    sleep(5)
    print(self.driver.contexts)
    self.driver.switch_to.context(u'WEBVIEW_com.tencent.mm:tools')
    self.driver.find_element_by_class_name('search_item_inner').click()

    if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(xcxTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

    搞了一天了。。。

  • 微信 webview 的自动化技术 at January 09, 2017

    你好,driver切换到webview失败,appium日志如下,请问如何解决

    > info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:tools
    > info: [debug] Connecting to chrome-backed webview
    > info: Chromedriver: Changed state to 'starting'
    > info: Chromedriver: Set chromedriver binary as: D:\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
    > info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
    > info: Chromedriver: No old chromedrivers seemed to exist
    > info: Chromedriver: Spawning chromedriver with: D:\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
    > info: Chromedriver: [STDOUT] Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 9515
    > Only local connections are allowed.
    > info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
    > info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.14393\"}}}"
    > info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"71MBBKU24CU7"}}}
    > info: [debug] Didn't get a new command in 60 secs, shutting down...
    > info: Shutting down appium session
    > info: [debug] Pressing the HOME button
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s 71MBBKU24CU7 shell "input keyevent 3"
    > info: [debug] Resetting IME to 'com.meizu.flyme.input/com.meizu.input.MzInputService'
    > info: [debug] executing cmd: D:\android-sdk-windows\platform-tools\adb.exe -s 71MBBKU24CU7 shell "ime set com.meizu.flyme.input/com.meizu.input.MzInputService"
    > info: [debug] Stopping logcat capture
    > info: [debug] Logcat terminated with code null, signal SIGTERM
    > info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
    > info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
    > info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
    > info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
    > info: [debug] [UIAUTOMATOR STDOUT] [CDS]close[4724]
    > info: [debug] [BOOTSTRAP] [debug] Closed client connection
  • 😰 地址挂了