自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Selenium IDE命令行運(yùn)行器

開發(fā) 前端
本篇將介紹安裝 Selenium IDE 命令行運(yùn)行程序、并獲取必要的瀏覽器驅(qū)動(dòng)程序(如果在本地運(yùn)行測(cè)試)以及使用所需選項(xiàng)從命令提示符啟動(dòng)運(yùn)行程序等操作。

一、前言

Selenium IDE 通常是從 Chrome 或 Firefox 的 Web 應(yīng)用商店進(jìn)行安裝的,安裝后通過(guò)在瀏覽器的菜單欄中單擊其圖標(biāo)來(lái)啟動(dòng)它,并進(jìn)行腳本的錄制與編寫,之后回放執(zhí)行該腳本。

本篇將介紹安裝 Selenium IDE 命令行運(yùn)行程序、并獲取必要的瀏覽器驅(qū)動(dòng)程序(如果在本地運(yùn)行測(cè)試)以及使用所需選項(xiàng)從命令提示符啟動(dòng)運(yùn)行程序等操作。

二、安裝

1、首先需要安裝 Node.js(版本8或10)。

2、之后打開命令行安裝 selenium-side-runner(Selenium IDE 命令行運(yùn)行程序)即可。

npm install -g selenium-side-runner

3、安裝瀏覽器驅(qū)動(dòng)程序

Selenium 通過(guò)稱為瀏覽器驅(qū)動(dòng)程序的小型二進(jìn)制應(yīng)用程序與每個(gè)瀏覽器通信。每個(gè)瀏覽器都有自己的驅(qū)動(dòng)程序,可以手動(dòng)下載并添加到系統(tǒng)路徑,或者使用包管理器安裝最新版本的瀏覽器驅(qū)動(dòng)程序(推薦)。

(1)對(duì)于 Chrome,需要 ChromeDriver 驅(qū)動(dòng)。

下載地址:

https://chromedriver.chromium.org/?。

命令行安裝驅(qū)動(dòng):

npm install -g chromedriver

(2)對(duì)于 Edge,需要 EdgeDriver 驅(qū)動(dòng)。

下載地址:

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?。

命令行安裝驅(qū)動(dòng):

npm install -g edgedriver

(3)對(duì)于 Firefox,需要 geckodriver 驅(qū)動(dòng)。

下載地址:

https://github.com/mozilla/geckodriver?。

命令行安裝驅(qū)動(dòng):

npm install -g geckodriver

(4)對(duì)于 IE,需要 IEDriver 驅(qū)動(dòng)。

下載地址:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver?。

命令行安裝驅(qū)動(dòng):

npm install -g iedriver

(5)對(duì)于 Safari,需要 SafariDriver 驅(qū)動(dòng)。

下載地址:

https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari?。

三、運(yùn)行

使用 selenium-side-runner 命令,然后再調(diào)用已保存的項(xiàng)目文件路徑即可。

例如使用 Selenium IDE 進(jìn)行錄制腳本,并運(yùn)行成功,將腳本保存到 D 盤根目錄下,如D:\ test_demo.side。

圖片

打開命令行工具,執(zhí)行如下命令運(yùn)行腳本。

selenium-side-runner D:\test_demo.side

執(zhí)行成功。

圖片

如果有多個(gè) .side 文件,可以使用通配符(例如 D:\*.side)。

運(yùn)行多個(gè) .side 文件時(shí),它將在多個(gè)瀏覽器窗口中并行啟動(dòng)測(cè)試,分布在 n 個(gè)進(jìn)程中(其中 n 是計(jì)算機(jī)上可用 CPU 內(nèi)核的數(shù)量)。

注:提示如下報(bào)錯(cuò)信息,則進(jìn)行手動(dòng)下載驅(qū)動(dòng),并配置環(huán)境變量即可。

The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver fro

m http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.

(1)首先查看瀏覽器版本,并下載對(duì)應(yīng)版本的驅(qū)動(dòng)。

如瀏覽器版本106.0.5249.119。

圖片


則驅(qū)動(dòng)下載106.0.5249.61。

圖片

(2)將驅(qū)動(dòng)放在本地 chrome.exe 同級(jí)目錄里。

圖片

(3)在環(huán)境變量的 PATH 里添加 chromedriver.exe 同級(jí)目錄路徑,之后保存就可以了。

圖片

四、運(yùn)行時(shí)配置

1、在本地指定不同的瀏覽器上運(yùn)行。

selenium-side-runner -c "browserName=chrome"
selenium-side-runner -c "browserName='internet explorer'"
selenium-side-runner -c "browserName=edge"
selenium-side-runner -c "browserName=firefox"
selenium-side-runner -c "browserName=safari"

?2、在 Selenium Grid 上運(yùn)行。

selenium-side-runner --server http://localhost:4444/wd/hub -c "browserName='chrome' versinotallow='106.0' platform='Windows 10'"

3、指定并行進(jìn)程的數(shù)量

在 Selenium Grid 上運(yùn)行時(shí),你可能希望控制正在運(yùn)行的并行會(huì)話數(shù),可以使用 -w n 命令標(biāo)志(其中 n 是想要的進(jìn)程數(shù))。

selenium-side-runner -w 10 --server http://localhost:4444/wd/hub

4、Chrome 特定功能

如果你在計(jì)算機(jī)上的非標(biāo)準(zhǔn)位置安裝了 Chrome,則可以指定路徑,以便 ChromeDriver 知道要查找的位置。

selenium-side-runner -c "goog:chromeOptions.binary='/path/to/non-standard/Chrome/install'"

無(wú)頭運(yùn)行測(cè)試。

selenium-side-runner -c "goog:chromeOptions.args=[disable-infobars, headless]"

五、應(yīng)用于框架

1、更改基本 URL。

通過(guò)指定不同的基本 URL,可以輕松地將測(cè)試指向不同的環(huán)境(例如開發(fā)環(huán)境、測(cè)試環(huán)境、生產(chǎn)環(huán)境)。

selenium-side-runner --base-url https://localhost

2、過(guò)濾器測(cè)試

可以選擇使用 --filter target 命令標(biāo)志(其中 target 是正則表達(dá)式值)運(yùn)行測(cè)試的目標(biāo)子集。僅運(yùn)行包含給定搜索條件的測(cè)試名稱。

selenium-side-runner --filter smoke

3、將測(cè)試結(jié)果輸出到文件

如果需要將測(cè)試結(jié)果導(dǎo)出到文件中(例如,當(dāng)作為 CI 進(jìn)程的一部分運(yùn)行時(shí)),可以使用 --output-directory 和 --output-format。

--output-directory 定義了測(cè)試結(jié)果文件的放置位置,可以采用絕對(duì)路徑或相對(duì)路徑。

--output-format 定義用于測(cè)試結(jié)果文件的格式,可以是 jest(例如 JSON)或 junit(例如 XML),默認(rèn)格式為 jest(未指定類型)。

selenium-side-runner --output-directory=results
selenium-side-runner --output-directory=results --output-format=jest
selenium-side-runner --output-directory=results --output-format=junit

4、指定默認(rèn)配置

可以將運(yùn)行時(shí)參數(shù)存儲(chǔ)在配置文件中,而不是記住所有需要的命令行參數(shù)。

兩種配置方式。

方式一:

運(yùn)行測(cè)試的目錄里創(chuàng)建 .side.yml 文件,selenium-side-runner 會(huì)自動(dòng)識(shí)別它。下面是文件內(nèi)容的示例。

capabilities:
browserName: "firefox"
baseUrl: "https://www.seleniumhq.org"
server: "http://localhost:4444/wd/hub"

如果要忽略該文件并使用命令行參數(shù),請(qǐng)?jiān)谶\(yùn)行時(shí)與其他命令一起使用 --no-sideyml。

方式二:

替代 .side.yml 文件,可以在 YAML 文件中指定運(yùn)行時(shí)參數(shù),并使用選擇的名稱和位置,然后在運(yùn)行測(cè)試時(shí)指定其位置。

selenium-side-runner --config-file "/path/to/your/config.yaml"

六、高級(jí)選項(xiàng)

1、參數(shù)

指定自己獨(dú)特的運(yùn)行時(shí)參數(shù),可以通過(guò) --params 標(biāo)志使用它們。

(1)基本用法

指定參數(shù)的名稱和值,最基本的方法是指定一個(gè)字符串值。

selenium-side-runner --params "a='example-value'"

(2)嵌套參數(shù)

參數(shù)可以使用點(diǎn)表示嵌套。

selenium-side-runner --params "a.b='another example-value'"

(3)數(shù)組值

可以指定字母數(shù)字?jǐn)?shù)組。

selenium-side-runner --params "a.b.c=[1,2,3]"

(4)多個(gè)參數(shù)

--params 只能調(diào)用一次,但可以通過(guò)空格分隔指定多個(gè)參數(shù)。

selenium-side-runner --params "a='example-value' a.b='another example-value' a.b.c=[1,2,3]"

2、使用代理服務(wù)器

可以在運(yùn)行程序中使用以下選項(xiàng)將代理功能傳遞給瀏覽器。

(1)直接代理

此選項(xiàng)將 WebDriver 配置為繞過(guò)所有瀏覽器代理。

從命令行:

selenium-side-runner --proxy-type=direct

在 .side.yaml 文件中:

proxyType: direct

(2)手動(dòng)代理

手動(dòng)配置瀏覽器代理。

從命令行:

selenium-side-runner --proxy-type=manual --proxy-options="http=localhost:434 bypass=[http://localhost:434, http://localhost:8080]"

在 .side.yaml 文件中:

proxyType: manual
proxyOptions:
http: http://localhost:434
https: http://localhost:434
ftp: http://localhost:434
bypass:
- http://localhost:8080
- http://host:434
- http://somethingelse:32

(3)PAC 代理

配置 WebDriver 以使用給定 URL 的 PAC 文件設(shè)置瀏覽器代理。

從命令行:

selenium-side-runner --proxy-type=pac --proxy-options="http://localhost/pac"

在 .side.yaml 文件中:

proxyType: pac
proxyOptions: http://localhost/pac

(4)SOCKS 代理

為 SOCKS 代理創(chuàng)建代理配置。

從命令行:

selenium-side-runner --proxy-type=socks --proxy-options="socksProxy=localhost:434 socksVersinotallow=5"

在 .side.yaml 文件中:

proxyType: socks
proxyOptions:
socksProxy: localhost:434
socksVersion: 5

(5)系統(tǒng)代理

配置 WebDriver 以使用當(dāng)前系統(tǒng)的代理。

從命令行:

selenium-side-runner --proxy-type=system

在 .side.yaml 文件中:

proxyType: system
責(zé)任編輯:姜華 來(lái)源: AllTests軟件測(cè)試
相關(guān)推薦

2022-01-04 09:02:24

瀏覽器命令行ttyd

2010-03-04 09:10:34

Linux Chrom

2010-09-16 16:05:24

Java編譯器

2020-12-10 16:16:08

工具代碼開發(fā)

2020-12-11 06:44:16

命令行工具開發(fā)

2015-07-01 09:15:46

linuxQuora命令行

2009-08-11 09:11:06

linux打開瀏覽器命linux命令行瀏覽器linux命令行

2018-04-25 08:25:01

Linux命令行密碼管理器

2012-02-08 16:37:36

ibmdw

2010-03-10 17:23:37

Python 命令行參

2023-06-09 07:45:29

Kuberneteskubectl

2009-12-24 14:51:39

Linux命令行

2020-12-06 08:00:46

scanimage命令行Linux

2010-07-20 14:18:22

Perl命令行

2010-07-15 10:47:22

Perl命令行

2009-12-09 09:25:52

Linux命令行svn命令

2010-09-01 14:23:54

Linux命令行開發(fā)

2019-07-23 13:45:38

LinuxFedora權(quán)限

2009-07-20 09:55:30

華為命令行解析華為認(rèn)證

2010-07-15 09:37:47

Perl命令行
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)