使用Firefox user agent进行移动端网页测试

Selenium 真是个强大的网页测试工具,设置Firefox user agent, 就可以轻松模拟手机端浏览器进行网页测试。
Demo Code

# -*- coding:utf8 -*-

import unittest
from selenium import webdriver class MobileTestDemo(unittest.TestCase): def setUp(self):
fp = webdriver.FirefoxProfile()
fp.set_preference("general.useragent.override", "Mozilla/5.0()\
(iPhone; U; CPU iPhone OS 5_0_1 like Mac OS X;\
en-us) AppleWebkit/533.17.0 (KHTML, like Gecko)\
Version/5.0.2 Mobile/8H7 Safari/6533.18.")
fp.update_preferences() cap = webdriver.DesiredCapabilities.FIREFOX
cap['firefox_profile'] = fp.encoded
self.driver = webdriver.Firefox(firefox_profile=fp) def tearDown(self):
self.driver.close() def test_mobile(self):
driver = self.driver
driver.get("http://www.google.com")
self.assertIn(u'Google', driver.title) if __name__ == "__main__":
unittest.main()
上一篇:[Python 3.x 官方文档翻译]Whetting Your Appetite 欢迎您的使用


下一篇:ios 上下滑动粘滞问题