如何使用Selenium自动化Firefox Mobile?

时间:2017-10-16 13:24:36

标签: selenium firefox mobile browser-automation

我需要在Firefox Mobile中运行Selenium测试。有谁可以形容一个简单的方法来做到这一点?我的调查表明:

  1. Appiumonetwo)不支持Firefox移动版。
  2. Firefox桌面内置了Responsive Design Mode,如图所示:responsive-ui-mode
  3. 似乎Geckodriver不支持Firefox移动版。与Chromedriver相比,Geckodriver没有特定于移动设备的代码。
  4. is(或者有)使用Firefox prefs打开移动模拟的方法。它的工作原理是使用Marionette API调用将Firefox从CONTENT切换到CHROME上下文,然后用Selenium按键盘快捷键。
  5. 无法通过任何这些解决方案取得成功。知道如何自动化Firefox Mobile吗?

2 个答案:

答案 0 :(得分:1)

您可以尝试使用Geckodriver并更改用户代理和设备大小(宽度和高度)在FireFox桌面应用上模拟它。这是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)

答案 1 :(得分:0)

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

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

这应该有效。 Havent已对其进行了测试,请尝试并让我知道。