如何使用Robot Framework下载带有phantomJS的文件?

时间:2017-11-28 10:59:14

标签: phantomjs robotframework

我正在使用Robot Framework和PhantomJS(无头浏览器)并想下载文件。但PhantomJS没有任何所需的功能或选项来设置首选项,就像我们在Chrome中一样。寻找任何建议或其他选项,使用PhantomJS和Robot Framework下载CSV文件。

1 个答案:

答案 0 :(得分:0)

正如您所强调的那样,下载文件不是问题。您将在下面找到一个以无头模式启动Chrome的Robot Script示例。

*** Settings ***
Library    Selenium2Library

Suite Teardown    Close All Browsers

*** Test Cases ***
Headless Chrome - Open Browser
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    ${prefs}    Create Dictionary   credentials_enable_service=${false}                 # Verberg de sla wachtwoord op pop-up

    Call Method    ${chrome_options}    add_experimental_option    prefs    ${prefs}
    Call Method    ${chrome options}    add_argument    start-maximized                 # Open de browser in gemaximaliseerd.
    Call Method    ${chrome_options}    add_argument    --headless
    Call Method    ${chrome_options}    add_argument    --disable-gpu    
    Call Method    ${chrome_options}    add_argument    --window-size\=1920,1080
    Create Webdriver    Chrome    chrome_options=${chrome options}

    Go To    http://cnn.com

    Capture Page Screenshot

如果您想在网格环境中以无头模式运行,请使用以下示例:

*** Settings ***
Library    Selenium2Library

Suite Teardown    Close All Browsers

*** Test Cases ***
Headless Chrome - Create Webdriver2
    ${chrome options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}   add_argument   --window-size\=1920,1080
    Call Method    ${chrome options}   add_argument   --start-maximized
    Call Method    ${chrome options}   add_argument   --headless
    Call Method    ${chrome options}   add_argument   --disable-gpu
    ${options}=     Call Method     ${chrome_options}    to_capabilities      

    Create Webdriver    Remote   command_executor=http://localhost:4444/wd/hub    desired_capabilities=${options}

    Go to     http://cnn.com

    Capture Page Screenshot