forked from browserstack/jest-js-browserstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
86 lines (71 loc) · 2.79 KB
/
test.js
File metadata and controls
86 lines (71 loc) · 2.79 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const { Builder, By, Key, until, Capabilities } = require("selenium-webdriver");
const assert = require("assert");
describe("BStack demo test Module A", () => {
let driver;
beforeAll(async () => {
driver = new Builder()
.usingServer(`http://localhost:4444/wd/hub`)
.withCapabilities(Capabilities.chrome())
.build();
await driver.get("https://bstackdemo.com");
await driver.wait(until.titleMatches(/StackDemo/i), 10000);
});
afterAll(async () => {
await driver.quit();
})
test(
"flaky test - add products to cart",
async () => {
let elementLocator = Math.random() < 0.5 ? '//*[@id="1"]/p' : '//*[@id="random"]/p';
// locating product on webpage and getting name of the product
await driver.wait(until.elementLocated(By.xpath(elementLocator)));
let productText = await driver
.findElement(By.xpath('//*[@id="1"]/p'))
.getText();
// clicking the 'Add to cart' button
await driver.findElement(By.xpath('//*[@id="1"]/div[4]')).click();
// waiting until the Cart pane has been displayed on the webpage
await driver.wait(until.elementLocated(By.className("float-cart__content")));
await driver.findElement(By.className("float-cart__content"));
// locating product in cart and getting name of the product in cart
let productCartText = await driver
.findElement(
By.xpath(
'//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]'
)
)
.getText();
// checking whether product has been added to cart by comparing product name
expect(productText).toBe(productCartText);
},
10000
);
test("always failing test - missing element 1", async () => {
await driver.wait(until.elementLocated(By.xpath('//*[@id="non-existent-1"]/p')));
}, 2000);
test("always failing test - same stacktrace 1", async () => {
await driver.wait(until.elementLocated(By.xpath('//*[@id="common-error"]/p')));
}, 2000);
test("always failing test - same stacktrace 2", async () => {
await driver.wait(until.elementLocated(By.xpath('//*[@id="common-error"]/p')));
}, 2000);
test("always passing test - example F", async () => {
assert(true);
}, 10000);
test("always passing test - example G", async () => {
assert(true);
}, 10000);
test("always passing test - example H", async () => {
assert(true);
}, 10000);
test("always passing test - example I", async () => {
assert(true);
}, 10000);
test("always passing test - example A", async () => {
assert(true);
}, 10000);
test("always passing test - verify page title", async () => {
await driver.get("https://bstackdemo.com");
await driver.wait(until.titleMatches(/StackDemo/i), 10000);
}, 10000);
});