-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_test_nodeJS.js
86 lines (83 loc) · 3.54 KB
/
parallel_test_nodeJS.js
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 webdriver = require('selenium-webdriver');
const { By } = require('selenium-webdriver');
const assert = require('assert');
async function runTestWithCaps(cap) {
let driver = new webdriver.Builder().usingServer(`https://hub-cloud.browserstack.com/wd/hub`).withCapabilities(cap).build();
try{
await driver.get("https://bstackdemo.com/");
await driver.wait(webdriver.until.titleMatches(/StackDemo/i), 10000);
// locating product on webpage
const productOnScreen = await driver.wait(webdriver.until.elementLocated(By.xpath('//*[@id="1"]/p')), 10000)
// getting name of the product when the product is visible
const productText = await driver.wait(webdriver.until.elementIsVisible(productOnScreen, 10000)).getText();
// clicking the 'Add to cart' button
await driver.wait(webdriver.until.elementIsVisible(driver.findElement(By.xpath('//*[@id="1"]/div[4]'), 10000))).click();
// waiting until the Cart pane has been displayed on the webpage
await driver.wait(webdriver.until.elementIsVisible(driver.findElement(By.className('float-cart__content'), 10000)));
// locating product in cart
const productInCart = await driver.wait(webdriver.until.elementLocated(By.xpath('//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]')), 10000);
// getting name of the product in cart if the product is visible on web page
const productCartText = await driver.wait(webdriver.until.elementIsVisible(productInCart, 10000)).getText();
// checking whether product has been added to cart by comparing product name
assert(productText === productCartText);
//marking the test as Passed if product has been added to the cart
await driver.executeScript(
'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Product has been successfully added to the cart!"}}'
);
} catch(e) {
//marking the test as Failed if product has not been added to the cart
console.log("Error:", e.message)
await driver.executeScript(
'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Some elements failed to load."}}'
);
}
await driver.quit();
}
// Input capabilities
var capabilities = [
{
'bstack:options' : {
"os" : "OS X",
"osVersion" : "Sierra",
"buildName" : "parallel-snippet-test",
"sessionName" : "Selenium-4 Nodejs snippet test",
"local" : "false",
"seleniumVersion" : "4.0.0",
"userName" : "",
"accessKey" : "",
},
"browserName" : "Chrome",
"browserVersion" : "latest",
},
{
'bstack:options' : {
"os" : "OS X",
"osVersion" : "Sierra",
"buildName" : "parallel-snippet-test",
"sessionName" : "Selenium-4 Nodejs snippet test",
"local" : "false",
"seleniumVersion" : "4.0.0",
"userName" : "",
"accessKey" : "",
},
"browserName" : "Firefox",
"browserVersion" : "latest",
},
{
'bstack:options' : {
"os" : "OS X",
"osVersion" : "Sierra",
"buildName" : "parallel-snippet-test",
"sessionName" : "Selenium-4 Nodejs snippet test",
"local" : "false",
"seleniumVersion" : "4.0.0",
"userName" : "",
"accessKey" : "",
},
"browserName" : "Edge",
"browserVersion" : "latest",
}
]
capabilities.map(async (caps) => {
await runTestWithCaps(caps);
});