Freddy
Freddy

Reputation: 521

In robotframework how do you configure the chrome driver and viewport settings?

For the past days I've been trying everything I can to configure a robotframework test to open in Chrome but be viewed with mobile settings by altering the viewport. I finally got past the chrome driver issue (Mac OS) but the viewport modification is still confusing.

Do I need to (a) Create Webdriver or (b) pass the settings from a python file as illustrated here Mobile Emulation

Upvotes: 1

Views: 4851

Answers (1)

ombre42
ombre42

Reputation: 2384

You could use Open Browser if you are using a non-local webdriver, but using Create Webdriver works either way. Here is a translation of the page you referenced (worked for me):

*** Settings ***
Test Teardown     Close All Browsers
Library           Selenium2Library

*** Test Cases ***
Specifying a Known Mobile Device
    ${mobile emulation}=    Create Dictionary    deviceName=Google Nexus 5
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome options}    add_experimental_option    mobileEmulation    ${mobile emulation}
    Create Webdriver    Chrome    chrome_options=${chrome options}
    Goto    https://stackoverflow.com
    Sleep    10 secs

Specifying Individual Device Attributes
    ${device metrics}=    Create Dictionary    width=${360}    height=${640}    pixelRatio=${3.0}    userAgent=Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19
    ${mobile emulation}=    Create Dictionary    deviceMetrics=${device metrics}
    ${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome options}    add_experimental_option    mobileEmulation    ${mobile emulation}
    Create Webdriver    Chrome    chrome_options=${chrome options}
    Goto    https://stackoverflow.com
    Sleep    10 secs

Upvotes: 6

Related Questions