如何使用Robot Framework使用phantomJS下载文件? [英] How to download a file with phantomJS using Robot Framework?

查看:149
本文介绍了如何使用Robot Framework使用phantomJS下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Robot Framework与PhantomJS(无头浏览器)一起使用,并希望下载文件.但是PhantomJS没有像我们在Chrome中那样需要任何功能或选项来设置首选项.寻找任何建议或其他选项,以使用带有机器人框架的PhantomJS下载CSV文件.

I am using Robot Framework with PhantomJS (headless browser) and want to download a file. But PhantomJS is not having any desired Capabilities or options to set the preferences as we do in Chrome. Looking for any suggestions or other options to download a CSV file using PhantomJS with Robot Framework.

推荐答案

正如您所强调的,下载文件不是问题.以下是一个以无头模式启动Chrome的漫游器脚本示例.

As you highlighted that downloading files is not the issue. Below you'll find an example of Robot Script that starts Chrome in Headless mode.

*** 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

如果要在Grid环境中以无头模式运行,请使用以下示例:

In case you want to run in headless mode in a Grid environment use the following example:

*** 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 

这篇关于如何使用Robot Framework使用phantomJS下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆