使用Robot Framework脚本和chromedriver在Android设备中打开Chrome浏览器?

时间:2015-12-29 09:11:25

标签: android robotframework selenium-chromedriver

Ubuntu 14.04上的自动化设置:

Robot Framework 2.9.2 (Python 2.7.6 on linux2)
selenium2library-1.7.4
ChromeDriver 2.20.353124
Device under testing:  Nexus 7 (KitKat 4.4, Chrome v. 47)

使用Python运行以下示例测试时,一切正常   - >在Nexus设备的Chrome上正确启动了网址。

    from selenium import webdriver
capabilities = {
  'chromeOptions': {
    'androidPackage': 'com.android.chrome',
  }
}
driver = webdriver.Remote('http://localhost:9515', capabilities)
driver.get('http://google.com')
driver.quit()

但是当我尝试使用Robot Framework脚本时,实际问题仍然存在。 我尝试了几种方法但总是只在桌面Chrome浏览器上打开网址 - 而不是在移动设备(Nexus平板电脑)中打开网址。

以下RF脚本是我最近的尝试。 我认为问题在某种程度上与 desired_capabilities 相关,但我还没找到应该如何定义的正确方法

*** Settings ***
Library         Selenium2Library
*** Variables ***
${chromedriver}    http://localhost:9515
${android} =    Create List   androidPackage    com.android.chrome  
${desired_capabilities} =    Create Dictionary   {chromedriver}    chromeOptions    ${android}

*** Keywords ***
Open Page
    Open Browser    http://www.google.com 
    ... browser=chrome   
    ... desired_capabilities=${desired_capabilities}

有人有同样的问题吗?我做错了什么?

1 个答案:

答案 0 :(得分:1)

所需的能力参数是not processed for local webdrivers。 在解决此问题之前,您可以使用更灵活的Create Webdriver关键字代替Open Browser。我不能说这是否是在Android上启动Chrome的最佳方式,但这里是您的Python代码的直接翻译:

${options}=    Create Dictionary    androidPackage=com.android.chrome
${caps}=    Create Dictionary    chromeOptions=${options}
Create Webdriver    Remote    command_executor=http://localhost:9515    desired_capabilities=${caps}
Go To    http://google.com
Close Browser