Skip to content

Commit

Permalink
add day22 for Data-Driven Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smalltide committed Oct 8, 2019
1 parent 4a4764e commit a54107b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions day22/TestCafeExamplePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Selector } from "testcafe"; // 引入 testcafe 的 html element 選擇器
const dataSet = require("./data.json");

fixture`測試案例集`.page`http:https://devexpress.github.io/testcafe/example`; // 1. 進入 TestCafe Example Page

dataSet.forEach(data => {
const { name, feature, os, interfaceOption, resultText } = data;

test(`Example Page Test Name = ${name}`, async t => {
// 使用 TestCafe 鏈式 Selector API
const inputSelector = Selector(".column").find("label");
const interfaceSelect = Selector("#preferred-interface");

await t
// 2. 直接使用 html element id,識別 input 並根據 data 的設定輸入 name
.typeText("#developer-name", name)
// 3. 透過預定義的 selector inputSelector 並根據 data 的設定勾選
.click(inputSelector.withText(feature).child("input"))
// 4. 透過預定義的 selector inputSelector 並根據 data 的設定勾選
.click(inputSelector.withText(os).child("input"))
// 5.1 透過預定義的 selector interfaceSelect,按下選單彈出選項
.click(interfaceSelect)
// 5.2 使用 TestCafe 鏈式 Selector API,找到 interfaceSelect 並根據 data 的設定選擇 Option
.click(interfaceSelect.find("option").withText(interfaceOption))
// 6. 按下 Submit 按鈕
.click("#submit-button")
// 7. 確認結果等於 data 的 resultText
.expect(Selector("#article-header").innerText)
.eql(resultText);
});
});
16 changes: 16 additions & 0 deletions day22/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": "ice1",
"feature": "Support for testing on remote devices",
"os": "MacOS",
"interfaceOption": "JavaScript API",
"resultText": "Thank you, ice1!"
},
{
"name": "ice2",
"feature": "Advanced traffic and markup analysis",
"os": "Linux",
"interfaceOption": "Both",
"resultText": "Thank you, ice2!"
}
]

0 comments on commit a54107b

Please sign in to comment.