使用机器人框架运行测试时,禁用chrome上的Flash插件

时间:2016-08-24 06:30:00

标签: google-chrome selenium-webdriver robotframework

我正在尝试模拟一个基于vjs播放器播放视频的测试,因此我需要禁用Flash插件才能使其正常工作(默认播放器是jwplayer)。下面是我的代码(作为关键字),但仍然不适用于我:

*** Keywords ***
Open Chrome Without Flash
  [Arguments]         ${url}
  ${options}=         Evaluate                  sys.modules['selenium.webdriver'].ChromeOptions()     sys, selenium.webdriver
  ${profile}=         Create Dictionary         plugins.plugins_disabled=Adobe Flash Player
  Call Method         ${options}    add_experimental_option    prefs    ${profile}
  Create Webdriver    Chrome                    chrome_options=${options}
  Go To               ${url}

我的环境设置:

  • Google Chrome 52.0.2743.116
  • Robot Framework 3.0
  • Selenium2Library 1.7.4
  • Chromedriver 2.23.409687

也许有人知道如何使其适用于机器人框架?

2 个答案:

答案 0 :(得分:0)

这就是我设法禁用它的方法(使用其他StackOverflow答案中建议的丑陋技术)。

*** Settings ***
Documentation     Test disabling Flash Plugin in Chrome
Library           Selenium2Library    15.0    5.0

*** Test Cases ***
    Open Chrome And Disable Flash    https://www.adobe.com/devnet/video/articles/fmp_player/_jcr_content/articlecontentAdobe/videomodal_0.content.html

*** Keywords ***
Open Chrome And Disable Flash
    [Arguments]    ${url}
    Open Browser    about://plugins    Chrome
    Wait Until Page Contains    Plug-ins
    ${myElement}=    Get Web Element    xpath=//div[2]/div[2]/div[2]/table/tbody/tr/td/div[1]/div[1]/span[.='Adobe Flash Player']/../../../div[contains(@class,'plugin-actions')]/span/a[contains(@class,'disable-group-link')]
    Click Element    ${myElement}
    Go To    ${url}

我的环境设置:

  • Linux - Fedora发布22(二十二)x64bit
  • Python 2.7.10
  • Google Chrome 52.0.2743.116
  • Robot Framework 3.0
  • Selenium2Library 1.8.0b2
  • 硒2.53.6
  • Chromedriver 2.22.397932

答案 1 :(得分:0)

您的案例有点未经测试,但这是我在如何在Chrome中停用插件时发现的:

*** Test Cases ***
Open Chrome
  Set Options
  Goto  ${SOME_URL}

*** Keywords ***
Set Options
  ${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
  ${disabled}=  Create List  Adobe Flash Player
  ${preferences}=  Create Dictionary  plugins.plugins_disabled=${disabled}
  Call Method  ${options}  add_experimental_option  prefs  ${preferences}
  Create WebDriver  Chrome  chrome_options=${options}

您可能需要验证Flash插件的名称(上面代码中为Adobe Flash Player)。