iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 13
0
DevOps

持續測試三十天系列 第 13

[Day 13] TestCafe 測試流程三神器 SAA

本篇我們來看看 TestCafe 測試流程三神器,

TestCafe 提供的 CLI 和 API 功能非常豐富,筆者建議下列文件要仔細研讀
- Using TestCafe
- Test API

Day12 我們用 TestCafe 進行了一個非常簡單的測試。

今天會規劃一個,稍微複雜的自動化測試流程:

  1. 進入 TestCafe Example Page
  2. Your name 輸入 ice
  3. Which features are important to you 勾選 Support for testing on remote devices
  4. What is your primary Operating System 選取 MacOS
  5. Which TestCafe interface do you use 下拉選取 Both
  6. 按下 Submit 按鈕
  7. 確認結果等於 Thank you, ice!

上述的測試流程會使用到,

  1. Selectors 取得網頁上的 element,例如按鈕、文字方塊等。
  2. 對網頁上的 element 進行預定的 Actions 動作,例如按下按鈕、輸入文字等。
  3. 使用 Assertions,判斷執行特定動作後的結果,是否如預期。

只好好利用 Selectors, Actions, Assertions 三神器,就可以組合完成各種複雜的自動化測試流程。
所以大家務必要熟讀以上三神器的相關文件。

受限於時間,我們明天才會開始撰寫測試流程,
但筆者必須先介紹, CLI 的 --speed 參數,
學會調慢跑測試的速度,我們才能知道寫的流程是否如自己預期。

Specifies the test execution speed. Tests are run at the maximum speed by default.
You can use this option to slow the test down.factor should be a number between 1 (the fastest) and 0.01 (the slowest).
PS. 可設定區間,1 最快,0.01 最慢。

將 speed 調整為 0.3,應該就可以細看每個動作的執行過程。

cd day12

testcafe chrome HelloWorld.js

or

testcafe chrome HelloWorld.js --speed 0.3

如何抓取 Selector

Yes

常用 Action

  1. Click
  2. Right Click
  3. Double Click
  4. Drag Element
  5. Hover
  6. Take Screenshot
  7. Navigate
  8. Press Key
  9. Select Text
  10. Type Text
  11. Upload
  12. Resize Window

常用 Assertion

  1. Deep Equal
  2. Not Deep Equal
  3. Ok
  4. Not Ok
  5. Contains
  6. Not Contains
  7. Type of
  8. Not Type of
  9. Greater than
  10. Greater than or Equal to
  11. Less than
  12. Less than or Equal to
  13. Within
  14. Not Within
  15. Match
  16. Not Match

TestCafe 的 Smart Assertion 機制,
可以幫助我們更快判定執行結果,得到更好的自動化測試效率。

  1. 通常 Action 執行後,我們沒辦法非常確定,多久能夠得到結果 (例如 Ajax Call Server API) API 返回時間可能不一定,所以會設定一個等待時間,再去判定結果。
    https://ithelp.ithome.com.tw/upload/images/20190929/2012077579Wy20WCKT.png
  2. Smart Assertion 機制,在設定的 timeout 時間內,多次判定是否結果已經返回。
    https://ithelp.ithome.com.tw/upload/images/20190929/20120775mhy55fjhfV.png

上一篇
[Day 12] TestCafe 安裝與看見世界
下一篇
[Day 14] 用 TestCafe 三神器 SAA 自動化測試填表單
系列文
持續測試三十天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言