1.建立FireFox的profile
1.1 dos切换到Firefox的安装目录,例如:C:\Program Files\Mozilla Firefox
1.2 dos中执行命令firefor -p,弹出创建窗口(如下:),新增一个profile。此处建立在c:\xxx下
1.3 创建完成后,点击上图中的"启动Firefox",在c:\xxx下可以看见生成一些文件(最重要的貌似是cert8.db)
2.写一个测试脚本test.py,执行观察结果
2.1脚本如下:
#coding=utf-8
import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestFireFoxProfile(unittest.TestCase):
def setUp(self):
profile = webdriver.FirefoxProfile(r‘c:\xxx‘)
self._browser = webdriver.remote.webdriver.WebDriver(\
command_executor=‘http://127.0.0.1:4444/wd/hub‘,\
browser_profile=profile,\
desired_capabilities=DesiredCapabilities.FIREFOX)
self._browser.get("http://www.baidu.com")
def test_tile(self):
assert "百度一下,你就知道" in self._browser.title
def tearDown(self):
self._browser.quit()
if __name__ == "__main__":
unittest.main()
2.2 启动Server ---主要是想看启动过程以及Remote方法的使用
2.3 执行test.py脚本,server显示如下信息:
22:18:40.495 INFO - Java: Sun Microsystems Inc. 11.0-b15
22:18:40.496 INFO - OS: Windows Vista 6.1 x86
22:18:40.507 INFO - v2.37.0, with Core v2.37.0. Built from revision a7c61cb
22:18:40.583 INFO - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPhone, version=}] does not match with current platform: VISTA
22:18:40.585 INFO - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPad, version=}] does not match with current platform: VISTA
22:18:40.632 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
22:18:40.634 INFO - Version Jetty/5.1.x
22:18:40.634 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
22:18:40.635 INFO - Started HttpContext[/selenium-server,/selenium-server]
22:18:40.635 INFO - Started HttpContext[/,/]
22:18:40.657 INFO - Started [email protected]
22:18:40.657 INFO - Started HttpContext[/wd,/wd]
22:18:40.660 INFO - Started SocketListener on 0.0.0.0:4444
22:18:40.660 INFO - Started [email protected]
22:18:55.135 INFO - Executing: [new session: {platform=ANY, firefox_profile=UEsDBBQAAAAIAKWurEYan7HfMwYAA..., javascriptEnabled=true, browserName=firefox, version=}] at URL: /session)
22:18:55.224 INFO - Creating a new session for Capabilities [{firefox_profile=UEsDBBQAAAAIAKWurEYan7HfMwYAAAAAAQAIAAAAY2VydDguZGLt3WtQVFUAB/Bz713WFURNEFB5
.................................省略....................
rEazUQ1nLgAAACwAAAAkAAAAAAAAAAAAAAC2gUAgAgBzYWZlYnJvd3NpbmcvdGVzdC1waGlzaC1z
aW1wbGUuY2FjaGVQSwECFAAUAAAACACkrqxGxNrTQgUAAAAQAAAAIwAAAAAAAAAAAAAAtoGwIAIA
c2FmZWJyb3dzaW5nL3Rlc3QtcGhpc2gtc2ltcGxlLnBzZXRQSwECFAAUAAAACACkrqxGOr4ZNE8A
AADoAAAAJgAAAAAAAAAAAAAAtoH2IAIAc2FmZWJyb3dzaW5nL3Rlc3QtcGhpc2gtc2ltcGxlLnNi
c3RvcmVQSwECFAAUAAAACAClrqxG6sGSGmxvDQBJig0AIgAAAAAAAAAAAAAAtoGJIQIAc3RhcnR1
cENhY2hlL3N0YXJ0dXBDYWNoZS40LmxpdHRsZVBLBQYAAAAAJAAkAFsJAAA1kQ8AAAA=
, platform=ANY, javascriptEnabled=true, browserName=firefox, version=}]
22:19:03.237 INFO - Done: /session
22:19:03.340 INFO - Executing: [get: http://www.baidu.com] at URL: /session/2a7bc3e0-d62c-465c-8dba-2e4f962af4d7/url)
22:19:06.251 INFO - Done: /session/2a7bc3e0-d62c-465c-8dba-2e4f962af4d7/url
22:19:06.255 INFO - Executing: [get title] at URL: /session/2a7bc3e0-d62c-465c-8dba-2e4f962af4d7/title)
22:19:06.299 INFO - Done: /session/2a7bc3e0-d62c-465c-8dba-2e4f962af4d7/title
22:19:06.328 INFO - Executing: [delete session: 2a7bc3e0-d62c-465c-8dba-2e4f962af4d7] at URL: /session/2a7bc3e0-d62c-465c-8dba-2e4f962af4d7)
22:19:06.528 INFO - Done: /session/2a7bc3e0-d62c-465c-8dba-2e4f962af4d7