【问题标题】:Opening Chrome browser in Android device using Robot Framework script and chromedriver?使用机器人框架脚本和 chromedriver 在 Android 设备中打开 Chrome 浏览器?
【发布时间】:2016-04-03 03:38:23
【问题描述】:

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 运行以下示例测试时一切正常 --> URL 在 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 浏览器上打开 URL——而不是在移动设备(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}

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

【问题讨论】:

    标签: android robotframework selenium-chromedriver


    【解决方案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
    

    【讨论】:

    • 谢谢!现在它可以工作了,Chrome 浏览器已在设备中打开,而不是在桌面中。你不相信我花了多少时间试图解决这个问题......
    • 你知道,我不确定以上是否有必要。您是否尝试将 remote_url=http://localhost:9515 添加到打开浏览器?我认为唯一的区别是“browserName”的附加功能:“chrome”、“platform”:“ANY”和“javascriptEnabled”:True。
    猜你喜欢
    • 2020-06-04
    • 2020-10-11
    • 2017-05-17
    • 2018-05-28
    • 1970-01-01
    • 2023-03-10
    • 2017-02-19
    • 2015-06-29
    • 2017-10-17
    相关资源
    最近更新 更多