Python+WebDriver 啟動Firefox時使用profile

來源:互聯網
上載者:User

標籤:python   firefox   測試   selenium   profile   

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

Python+WebDriver 啟動Firefox時使用profile

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.