How to automate Firefox Mobile with Selenium?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 17:13:51

问题


I need to run Selenium tests in Firefox Mobile. Could anybody describe an easy way to do this? My investigation shows that:

  1. Firefox Mobile is not supported in Appium (one, two).
  2. Firefox Desktop has built-in Responsive Design Mode like shown on the picture:
  3. It seems that Geckodriver does not support Firefox mobile. Compared to Chromedriver Geckodriver has no mobile-specific code.
  4. There is (or there was) some way to open mobile emulation using Firefox prefs. It works by switching Firefox from CONTENT to CHROME context using Marionette API calls and then pressing keyboard shortcut with Selenium.

Did not manage to succeed with any of these solutions. Any idea how to automate Firefox Mobile?


回答1:


You can try to emulate it on the FireFox Desktop app by using Geckodriver and changing User Agent and device size (width and height). Here is an example in Python 3:

user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"

profile = webdriver.FirefoxProfile() 
profile.set_preference("general.useragent.override", user_agent)
driver = webdriver.Firefox(profile)
driver.set_window_size(360,640)



回答2:


binary = FirefoxBinary('geckodriver.exe')
capabilities = {
    'browserName': 'firefox',
    'firefoxOptions': {
        'mobileEmulation': {
            'deviceName': 'iPhone X'
        }
    }
}

browser = webdriver.Firefox(firefox_binary=binary, desired_capabilities=capabilities)

This should work. Havent tested it so try it and let me know.



来源:https://stackoverflow.com/questions/46771456/how-to-automate-firefox-mobile-with-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!