-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathsteps.js
More file actions
68 lines (56 loc) · 2.55 KB
/
steps.js
File metadata and controls
68 lines (56 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
const { Given, When, Then, Before, BeforeStep } = require('@cucumber/cucumber');
const assert = require('assert');
Given('module A - flaky test - random product selection', async function () {
const randomProductIndex = Math.random() > 0.5 ? "1" : "2000";
const productOnScreen = await this.driver.findElement({ xpath: `//*[@id="${randomProductIndex}"]/p` });
const productOnScreenText = await productOnScreen.getText();
const addToCart = await this.driver.findElement({ xpath: `//*[@id="${randomProductIndex}"]/div[4]` });
await addToCart.click();
const productInCart = await this.driver.findElement({ xpath: '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]' });
let textMatch = false;
for (let i = 0; i < 10; i++) {
const cartText = await productInCart.getText();
if (cartText.match(productOnScreenText)) {
textMatch = true;
break;
}
await new Promise(res => setTimeout(res, 500));
}
assert.ok(textMatch, 'Cart product text did not match selected product');
});
Given('module A - always failing test - missing element 1', async function () {
await this.driver.findElement({ xpath: '//*[@id="non-existent-1"]/p' }).then(el => el.click());
});
Given('module A - always failing test - same stacktrace 1', async function () {
await this.driver.findElement({ xpath: '//*[@id="common-error"]/p' }).then(el => el.click());
});
Given('module A - always failing test - same stacktrace 2', async function () {
await this.driver.findElement({ xpath: '//*[@id="common-error"]/p' }).then(el => el.click());
});
Given('module A - always passing test - example B', async function () {
assert(true);
});
Given('module A - always passing test - example C', async function () {
assert(true);
});
Given('module A - always passing test - example D', async function () {
assert(true);
});
Given('module A - always passing test - example E', async function () {
assert(true);
});
Given('module A - passing test - verify page title', async function () {
const title = await this.driver.getTitle();
assert.match(title, /StackDemo/i);
});
Given('module A - Test with framework-level retry - 2 retries configured', async function () {
assert(Math.random() > 0.7, "Test failed, retrying...");
});
Given('module A - Another Test with framework-level retry - 2 retries configured', async function () {
assert(Math.random() > 0.7, "Test failed, retrying...");
});
Given('module A - always passing test - example A', async function () {
const url = await this.driver.getCurrentUrl();
assert.ok(url.includes("bstackdemo"));
});