Using Selenium2Library for mobile emulation in Chrome

1,409 views
Skip to first unread message

Aidan Mahler

unread,
Feb 23, 2015, 5:02:00 PM2/23/15
to robotframe...@googlegroups.com
Is there any way to open a Mobile Emulation[1] instance of chrome for use with the Selenium2Library?

I tried to modify the instructions given by the chromedriver website[2] to work with RF, but it didn't work.

What I did was,
Make a python keyword:
def get_chrome_capabilities(self, device_name='Google Nexus 5'):
        mobile_emulation = { "deviceName": device_name }
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
        return chrome_options.to_capabilities() 


and then run a test case:
${desired_capabilities}    Get Chrome Capabilities   
Create Webdriver           Chrome     desired_capabilities=${desired_capabilities}


But it failed with the error:
WebDriverException: Message: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: mobileEmulation


[1] https://developer.chrome.com/devtools/docs/device-mode
[2] https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation

HelioGuilherme66

unread,
Feb 23, 2015, 5:52:27 PM2/23/15
to robotframe...@googlegroups.com
I don't know if this helps you, but there is an Appium RF library similar to Selenium:

Aidan Mahler

unread,
Feb 24, 2015, 10:24:13 AM2/24/15
to robotframe...@googlegroups.com
Thanks for the suggestion, I'll look further into Appium.

For now I've solved my problem by setting the user agent in via chrome_options.

I've made a python keyword:
from selenium import webdriver

def get_chrome_mobile_options(self, user_agent_string='Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--user-agent={0}".format(user_agent_string))
        return chrome_options


And a the test case:
${options}=         Get Chrome Mobile Options   
Create Webdriver    Chrome    chrome_options=${options}
Go To               http://en.wikipedia.org/wiki/Philosophy   
Close Browser 
      

And the page is rendered as if by a mobile device (iOS 5.0 in this case).
Reply all
Reply to author
Forward
0 new messages