selenium工具python快速入門1簡介
概述
Selenium是一個開源自動化測試套件,適用於跨瀏覽器和平臺的Web應用程式。 它是一組軟體工具,每種工具都有不同的方法來支援測試自動化。
Selenium3.*的元件如下:
- Selenium IDE(整合開發環境 Integrated Development Environment)
- Selenium WebDriver
- Selenium Grid
Selenium3. 停止直接使用Selenium RC。 Selenium Core已從最新版本的Selenium 3. 中完全刪除。
官網: http://www.seleniumhq.org/

圖片.png
Selenium開源,基於Apache 2.0 License。github: https://github.com/SeleniumHQ/selenium

圖片.png
Selenium IDE
Selenium IDE的介紹請參考 https://www.jianshu.com/p/2259f4a8d4c4 ,實際上Katalon Recorder更好用。
- python測試開發專案實戰-目錄 https://china-testing.github.io/practices.html
- python工具書籍下載-持續更新 https://china-testing.github.io/python_books.html
- python 3.7極速入門教程 - 目錄 https://china-testing.github.io/python3_quick.html
Selenium WebDriver
Selenium WebDriver是瀏覽器自動操作的程式設計介面,更好地支援動態網頁。
- 支援很多瀏覽器,如Chrome,IE,Edge,Firefox,Opera,Safar。
- 支援很多程式語言,如Java,C#,Ruby,Python,JavaScript(Node)
Selenium WebDriver有兩種系統配置。
-
只有Selenium Client
圖片.png
安裝請自行搞定。
快速入門示例:

圖片.png
執行結果:

圖片.png
Selenium客戶端和瀏覽器驅動程式使用JsonWireProtocol通過HTTP方法相互通訊。 當我們執行如上所述的自動操作的程式碼時,Selenium Client在內部使用JsonWireProtocol與瀏覽器驅動程式互動並執行瀏覽器操作。
在JsonWireProtocol網站上,我們可以檢查命令是否自動執行。
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol

圖片.png
- Selenium Client + Selenium Server

圖片.png
主要適用於PHP等非官方支援的語言及Selenium Grid。
參考資料
- 討論qq群144081101 591302926 567351477
- 本文最新版本地址
- 本文涉及的python測試開發庫 謝謝點贊!
- 本文相關海量書籍下載
- selenium 書籍下載: https://china-testing.github.io/selnium_books.html
Selenium Grid
Selenium Grid允許我們在不同的機器上並行執行不同瀏覽器的測試。也就是說,針對執行不同瀏覽器和作業系統的不同計算機同時執行多個測試。 Selenium Grid與Selenium WebDriver一起使用。
Selenium官方網站有關於Selenium Grid的詳細解釋。
http://www.seleniumhq.org/docs/07_selenium_grid.jsp
圖片.png
Selenium Grid由Hub和Node組成。在下圖中,Node由三臺機器(Linux,Windows10,macOS)組成,每個節點可以使用兩個瀏覽器。

圖片.png
Hub知道Node的資訊,當來自User Code的執行請求到來時,Hub向相應的Node發出執行請求,並在請求的Node上執行自動操作。

圖片.png
由於Selenium Grid支援並行執行,當Hub同時從使用者程式碼接收多個執行請求時,Hub同時向相應的節點發出多個執行請求。

圖片.png
Selenium Grid的執行,我們在後面有空會介紹。