-
Notifications
You must be signed in to change notification settings - Fork 0
/
jl_navigation.js
66 lines (51 loc) · 1.64 KB
/
jl_navigation.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
const fse = require("fs-extra");
module.exports = async function (context, commands) {
const webdriver = context.selenium.webdriver;
const driver = context.selenium.driver;
const until = webdriver.until;
const By = webdriver.By;
const Key = webdriver.Key;
//try{
await commands.measure.start("Home");
await driver.get("https://www.johnlewis.com");
await driver.wait(
until.elementLocated(By.xpath("//*[text()='Allow all']")),
15000
);
await commands.measure.stop();
await driver.findElement(By.xpath("//*[text()='Allow all']")).click();
await commands.wait.byTime(5000);
const keywords = await fse.readJson("search-term.json");
await driver
.findElement(By.name("search-term"))
.sendKeys(keywords.term[Math.floor(Math.random() * keywords.term.length)]);
await commands.measure.start("Search");
await driver
.findElement(By.xpath("//button[@type='submit']"))
.sendKeys(Key.ENTER);
await commands.wait.byTime(10000);
await commands.measure.stop();
let productEle = await driver.findElements(
By.xpath("//a[starts-with(@class, 'image_imageLink')]")
);
var productArray = [],
i = 0;
for (let e of productEle) {
productArray[i] = await e.getAttribute("href");
i++;
}
const productUrl =
productArray[Math.floor(Math.random() * productArray.length)];
await commands.measure.start("Product");
await driver.get(productUrl);
await driver.wait(
until.elementLocated(By.xpath("//*[text()='Add to your basket']")),
15000
);
await commands.measure.stop();
//}
// catch(e){
// await commands.error(productEle[0]);
// }
return commands.wait.byTime(10000);
};