
- WebdriverIO 教程
- WebdriverIO - 首頁
- WebdriverIO - 簡介
- WebdriverIO - 前提條件
- WebdriverIO - 架構
- WebdriverIO - 使用 NodeJS 入門
- WebdriverIO - NPM 安裝
- WebdriverIO - VS Code 安裝
- WebdriverIO - package.json
- WebdriverIO - Mocha 安裝
- Selenium 獨立伺服器安裝
- WebdriverIO - 配置檔案生成
- WebdriverIO - VS Code 智慧提示
- WebdriverIO - wdio.conf.js 檔案
- WebdriverIO - XPath 定位器
- WebdriverIO - CSS 定位器
- WebdriverIO - 連結文字定位器
- WebdriverIO - ID 定位器
- WebdriverIO - 標籤名定位器
- WebdriverIO - 類名定位器
- WebdriverIO - 名稱定位器
- 斷言的 Expect 語句
- WebdriverIO - 成功路徑流程
- WebdriverIO - 常用瀏覽器命令
- WebdriverIO - 處理瀏覽器大小
- WebdriverIO - 瀏覽器導航命令
- 處理複選框和下拉選單
- WebdriverIO - 滑鼠操作
- 處理子視窗/彈出視窗
- WebdriverIO - 隱藏元素
- WebdriverIO - 框架
- WebdriverIO - 拖放
- WebdriverIO - 雙擊
- WebdriverIO - Cookie
- WebdriverIO - 處理單選按鈕
- Web元素上的 Chai 斷言
- WebdriverIO - 多個視窗/標籤頁
- WebdriverIO - 滾動操作
- WebdriverIO - 警報
- WebdriverIO - 除錯程式碼
- WebdriverIO - 捕獲螢幕截圖
- WebdriverIO - JavaScript 執行器
- WebdriverIO - 等待
- WebdriverIO - 並行執行測試
- WebdriverIO - 資料驅動測試
- 從命令列引數執行測試
- 使用 Mocha 選項執行測試
- 從 Allure 生成 HTML 報告
- WebdriverIO 有用資源
- WebdriverIO - 快速指南
- WebdriverIO - 有用資源
- WebdriverIO - 討論
WebdriverIO - 常用瀏覽器命令
下面列出了一些 WebdriverIO 中使用的通用瀏覽器命令:
browser.url(URL)
此命令用於啟動一個應用程式,其 URL 作為引數傳遞。
語法
語法如下:
browser.url('https://the-internet.herokuapp.com/redirector')
首先,按照標題為“使用 WebdriverIO 的成功路徑流程”章節中的步驟 1 到 5 進行操作,步驟如下:
步驟 1 - 安裝 NodeJS。有關如何執行此安裝的詳細資訊在標題為“使用 NodeJS 入門”的章節中詳細介紹。
步驟 2 - 安裝 NPM。有關如何執行此安裝的詳細資訊在標題為“NPM 安裝”的章節中詳細介紹。
步驟 3 - 安裝 VS Code。有關如何執行此安裝的詳細資訊在標題為“VS Code 安裝”的章節中詳細介紹。
步驟 4 - 建立配置檔案。有關如何執行此安裝的詳細資訊在標題為“配置檔案生成”的章節中詳細介紹。
步驟 5 - 建立一個規範檔案。有關如何執行此安裝的詳細資訊在標題為“Mocha 安裝”的章節中給出。
步驟 6 - 將以下程式碼新增到建立的 Mocha 規範檔案中。
// test suite name describe('Tutorialspoint application', function(){ //test case it('Identify element with Id', function(){ // launch url browser.url('https://the-internet.herokuapp.com/redirector') //identify element with id then click $("#redirect").click() //obtain page title console.log('Page title after click: ' + browser.getTitle()) }); });
browser.getTitle()
此命令用於獲取當前在瀏覽器中啟動的頁面的標題。該值以字串的形式返回。此命令不接受任何引數。如果頁面沒有標題,則返回空字串。
語法
語法如下:
browser.getTitle()
首先,按照標題為“使用 WebdriverIO 的成功路徑流程”章節中的步驟 1 到 5 進行操作,步驟如下:
步驟 1 - 安裝 NodeJS。有關如何執行此安裝的詳細資訊在標題為“使用 NodeJS 入門”的章節中詳細介紹。
步驟 2 - 安裝 NPM。有關如何執行此安裝的詳細資訊在標題為“NPM 安裝”的章節中詳細介紹。
步驟 3 - 安裝 VS Code。有關如何執行此安裝的詳細資訊在標題為“VS Code 安裝”的章節中詳細介紹。
步驟 4 - 建立配置檔案。有關如何執行此安裝的詳細資訊在標題為“配置檔案生成”的章節中詳細介紹。
步驟 5 - 建立一個規範檔案。有關如何執行此安裝的詳細資訊在標題為“Mocha 安裝”的章節中給出。
步驟 6 - 將以下程式碼新增到建立的 Mocha 規範檔案中。
// test suite name describe('Tutorialspoint Application', function () { // test case name it('Get Page Title', function (){ // URL launching browser.url("https://tutorialspoint.tw/about/about_careers.htm") //print page title in console console.log(browser.getTitle()) }); });
browser.getUrl()
此命令用於獲取當前在瀏覽器中啟動的頁面的 URL。該值以字串的形式返回。此命令不接受任何引數。
語法
語法如下:
browser.getUrl()
首先,按照標題為“使用 WebdriverIO 的成功路徑流程”章節中的步驟 1 到 5 進行操作,步驟如下:
步驟 1 - 安裝 NodeJS。有關如何執行此安裝的詳細資訊在標題為“使用 NodeJS 入門”的章節中詳細介紹。
步驟 2 - 安裝 NPM。有關如何執行此安裝的詳細資訊在標題為“NPM 安裝”的章節中詳細介紹。
步驟 3 - 安裝 VS Code。有關如何執行此安裝的詳細資訊在標題為“VS Code 安裝”的章節中詳細介紹。
步驟 4 - 建立配置檔案。有關如何執行此安裝的詳細資訊在標題為“配置檔案生成”的章節中詳細介紹。
步驟 5 - 建立一個規範檔案。有關如何執行此安裝的詳細資訊在標題為“Mocha 安裝”的章節中給出。
步驟 6 - 將以下程式碼新增到建立的 Mocha 規範檔案中。
// test suite name describe('Tutorialspoint Application', function () { // test case name it('Get Url', function (){ // URL launching browser.url("https://tutorialspoint.tw/index.htm") //print URL in console console.log(browser.getUrl()) }); });
browser.getPageSource()
此命令用於獲取當前在瀏覽器中啟動的頁面的頁面原始碼。該值以字串的形式返回。此命令不接受任何引數。
語法
語法如下:
browser.getPageSource()
首先,按照標題為“使用 WebdriverIO 的成功路徑流程”章節中的步驟 1 到 5 進行操作,步驟如下:
步驟 1 - 安裝 NodeJS。有關如何執行此安裝的詳細資訊在標題為“使用 NodeJS 入門”的章節中詳細介紹。
步驟 2 - 安裝 NPM。有關如何執行此安裝的詳細資訊在標題為“NPM 安裝”的章節中詳細介紹。
步驟 3 - 安裝 VS Code。有關如何執行此安裝的詳細資訊在標題為“VS Code 安裝”的章節中詳細介紹。
步驟 4 - 建立配置檔案。有關如何執行此安裝的詳細資訊在標題為“配置檔案生成”的章節中詳細介紹。
步驟 5 - 建立一個規範檔案。有關如何執行此安裝的詳細資訊在標題為“Mocha 安裝”的章節中給出。
步驟 6 - 將以下程式碼新增到建立的 Mocha 規範檔案中。
// test suite name describe('Tutorialspoint Application', function () { // test case name it('Get Page Source', function (){ // URL launching browser.url("https://tutorialspoint.tw/index.htm") //print URL in console console.log(browser.getPageSource()) }); });
browser.maximizeWindow()
此命令用於最大化當前瀏覽器視窗。
語法
語法如下:
browser.maximizeWindow()
首先,按照標題為“使用 WebdriverIO 的成功路徑流程”章節中的步驟 1 到 5 進行操作,步驟如下:
步驟 1 - 安裝 NodeJS。有關如何執行此安裝的詳細資訊在標題為“使用 NodeJS 入門”的章節中詳細介紹。
步驟 2 - 安裝 NPM。有關如何執行此安裝的詳細資訊在標題為“NPM 安裝”的章節中詳細介紹。
步驟 3 - 安裝 VS Code。有關如何執行此安裝的詳細資訊在標題為“VS Code 安裝”的章節中詳細介紹。
步驟 4 - 建立配置檔案。有關如何執行此安裝的詳細資訊在標題為“配置檔案生成”的章節中詳細介紹。
步驟 5 - 建立一個規範檔案。有關如何執行此安裝的詳細資訊在標題為“Mocha 安裝”的章節中給出。
步驟 6 - 將以下程式碼新增到建立的 Mocha 規範檔案中。
// test suite name describe('Tutorialspoint Application', function () { // test case name it('Maximise Browser', function (){ // URL launching browser.url("https://tutorialspoint.tw/questions/index.php") //maximize browser browser.maximizeWindow() }); });