- Cypress 教程
- Cypress - 首頁
- Cypress - 簡介
- Cypress - 架構和環境設定
- Cypress - 測試執行器
- Cypress - 建立第一個測試
- Cypress - 支援的瀏覽器
- Cypress - 基本命令
- Cypress - 變數
- Cypress - 別名
- Cypress - 定位器
- Cypress - 斷言
- Cypress - 文字驗證
- Cypress - 非同步行為
- Cypress - 處理 XHR
- Cypress - jQuery
- Cypress - 複選框
- Cypress - 標籤頁
- Cypress - 下拉列表
- Cypress - 警報
- Cypress - 子視窗
- Cypress - 隱藏元素
- Cypress - 框架
- Cypress - 網頁表格
- Cypress - 滑鼠操作
- Cypress - Cookie
- Cypress - GET 和 POST 請求
- Cypress - 檔案上傳
- Cypress - 資料驅動測試
- Cypress - 提示彈出視窗
- Cypress - 儀表盤
- Cypress - 截圖和影片
- Cypress - 除錯
- Cypress - 自定義命令
- Cypress - Fixtures
- Cypress - 環境變數
- Cypress - Hooks
- Cypress - JSON 檔案配置
- Cypress - 報告
- Cypress - 外掛
- Cypress - GitHub
- Cypress 有用資源
- Cypress - 快速指南
- Cypress - 有用資源
- Cypress - 討論
Cypress - 基本命令
Cypress 基本命令如下:
以及
它用於建立斷言,是 .should() 的別名。
使用方法如下:
//element is visible & enabled
cy.get('#txt').should('be.visible').and('be.enabled')
//element is checked
cy.contains('Subject').and('be.checked')
作為
它為後續使用提供別名。
使用方法如下:
//alias element as parent
cy.get('#txt').find('li').first().as('parent')
失去焦點
它使獲得焦點的元素失去焦點。
使用方法如下:
//blur input
cy.get('#txt'). type('abc').blur()
選中
它選中單選按鈕或複選框,適用於具有 input 標籤的元素。
使用方法如下:
//checks element having class attribute chkbox
cy.get('.chkbox').check()
子元素
它獲取元素的子元素。
使用方法如下:
//obtains children of element n
cy.get('n').children()
清空
它刪除 textarea 或 input 中的值。
使用方法如下:
//removes input abc
cy.get('#txt'). type('abc').clear()
清除 Cookie
它刪除特定的瀏覽器 Cookie。
使用方法如下:
//clear abc cookie
cy.clearCookie('abc')
清除所有 Cookie
它刪除現有域和子域的瀏覽器 Cookie。
使用方法如下:
//clear all cookies cy.clearCookies()
清除本地儲存
它刪除現有域和子域的本地儲存資料。
使用方法如下:
//clear all local storage cy. clearLocalStorage ()
點選
它點選文件物件模型 (DOM) 中的元素。
使用方法如下:
//click on element with id txt
cy.get('#txt').click()
包含
它獲取包含特定文字的元素。該元素可以包含超過文字的部分,但仍然匹配。
使用方法如下:
//returns element in #txt having Tutor text
cy.get('#txt').contains('Tutor')
雙擊
它雙擊文件物件模型 (DOM) 中的元素。
使用方法如下:
//double clicks element with id txt
cy.get('#txt').dblclick()
除錯
它設定偵錯程式,並返回先前命令返回的對數值。
使用方法如下:
//pause to debug at start of command
cy.get('#txt').debug()
文件
它獲取活動頁面上的 window.document。
使用方法如下:
cy.document()
每個
它迭代具有 length 屬性的陣列。
使用方法如下:
//iterate through individual li
cy.get('li').each(() => {...})
結束
它結束命令鏈。
使用方法如下:
//obtain null instead of input
cy.contains('input').end()
第 N 個
它引用元素陣列中特定索引處的元素。
使用方法如下:
//obtain third td in tr
cy.get('tr>td').eq(2)
執行
它執行系統命令。
使用方法如下:
cy.exec('npm init')
查詢
它獲取特定定位器的後代元素。
使用方法如下:
//obtain td from tr
cy.get('tr').find('td')
第一個
它獲取一組元素中的第一個元素。
使用方法如下:
//obtain first td in tr
cy.get('tr>td').first()
獲取
它根據定位器獲取單個或多個元素。
使用方法如下:
//obtain td from tr
查詢
它獲取特定定位器的後代元素。
使用方法如下:
//obtain all td from tr in list
cy.get('tr>td')
獲取 Cookie
它根據名稱獲取特定的瀏覽器 Cookie。
使用方法如下:
cy.getCookie('abc')
獲取所有 Cookie
它獲取所有 Cookie。
使用方法如下:
cy.getCookies()
跳轉
它在瀏覽器歷史記錄中向前或向後移動到下一個或上一個 URL。
使用方法如下:
//like clicking back button
cy.go('back')
//like clicking forward button
cy.go('forward')
訪問
它啟動一個 URL。
使用方法如下:
cy.visit('https://tutorialspoint.tw/index.htm')
下一個
它獲取文件物件模型 (DOM) 中一組元素中元素的緊鄰兄弟元素。
使用方法如下:
//gives the following link in element l.
cy.get('l a:first').next()
父元素
它獲取 DOM 中一組元素的父元素。
使用方法如下:
//get parent of element with class h
cy.get('.h').parent()
應該
它用於建立斷言,是 .and() 的別名。
使用方法如下:
//assert element is visible & enabled
cy.get('#txt').should('be.visible').and('be.enabled')
等待
在執行後續步驟之前,等待特定毫秒數或等待一個別名元素。
使用方法如下:
cy.wait(1000)
標題
它獲取活動頁面的 document.title。
使用方法如下:
cy.title()
視口
它管理螢幕的尺寸和位置。
使用方法如下:
// viewport to 100px and 500px cy.viewport(100, 500)
日誌
它將訊息列印到命令日誌中。
使用方法如下:
cy.log('Cypress logging ')
重新載入
它用於頁面重新載入。
使用方法如下:
cy.reload()