Android Chrome浏览器上的Youtube页面(WebView)自动化

时间:2014-05-26 19:17:14

标签: google-chrome webview youtube appium

能够从Appium 1.0.0.3中的Android chrome浏览器成功运行Youtube页面(WebView)。

伙计们,我被击中了。请帮助我实现目标。

- I can't able to identify elements inside WebView using "uiautomatorviewer.bat"

- I can't able to switch to WebView through following code
       - driver.switch_to.context('WEBVIEW')
          one more I tried
       - driver.switch_to.context(webview)

我的目标:

场景1:

在Android Chrome浏览器上打开Youtube页面。   选择任何视频进行播放。   点击暂停并播放。   点击全屏按钮。

场景2:

在Android Chrome浏览器上打开网址:“http://m.youtube.com/watch?v=7-7knsP2n5w”。   点击播放按钮。

示例代码:

from appium import webdriver

desired_caps = {}
desired_caps['automationName'] = 'Appium'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = 'Nexus 7'
desired_caps['browserName'] = 'Chrome'

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

driver.get('http://m.youtube.com')

driver.switch_to.context('WEBVIEW')    # Unable to switch to webview. Getting following error.

Python解释器错误:

Traceback (most recent call last):
File "C:\Python27\lib\bdb.py", line 400, in run
exec cmd in globals, locals
File "C:\Data\VVO\Automation\ROBOT_FRAMEWORK\AndroidTest\Appium\tmp_browser.py", line 2, in <module>
from appium import webdriver
File "build\bdist.win32\egg\appium\webdriver\switch_to.py", line 31, in context
self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 172, in execute
self.error_handler.check_response(response)
File "build\bdist.win32\egg\appium\webdriver\errorhandler.py", line 29, in check_response
raise wde
WebDriverException: Message: 'unknown command: session/d6c14715e9f6ca685030f9f56a2b698e/context'

Appium服务器日志:

POST /wd/hub/session/74354d82912ad3db704d67eeb04a295b/url 200 18052ms - 85b
debug: Appium request initiated at /wd/hub/session/74354d82912ad3db704d67eeb04a295b/context
debug: Request received with params:    {"sessionId":"74354d82912ad3db704d67eeb04a295b","name":"WEBVIEW"}
debug: Proxying command to 127.0.0.1:9515
info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/74354d82912ad3db704d67eeb04a295b/
context","method":"POST","json":{"sessionId":"74354d82912ad3db704d67eeb04a295b","name":"WEBVIEW"}}
debug: Proxied response received with status 404: "unknown command:   session/74354d82912ad3db704d67eeb04a295b/context"
POST /wd/hub/session/74354d82912ad3db704d67eeb04a295b/context 404 8ms - 65b

1 个答案:

答案 0 :(得分:0)

初始化webdriver时,网址应设置为http://0.0.0.0:9515/wd/hub/

您在切换上下文时遇到问题,因为Appium没有成功与该应用程序通信。

尝试print driver.page_source当它工作时(并打印出页面xml),其余部分(切换上下文等)也应该有用。