-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test_script_Darya_Sayenka.js
133 lines (112 loc) · 4.63 KB
/
Test_script_Darya_Sayenka.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const fs = require('fs')
const puppeteer = require('puppeteer')
const lighthouse = require('lighthouse/lighthouse-core/fraggle-rock/api.js')
const waitTillHTMLRendered = async (page, timeout = 30000) => {
const checkDurationMsecs = 1000;
const maxChecks = timeout / checkDurationMsecs;
let lastHTMLSize = 0;
let checkCounts = 1;
let countStableSizeIterations = 0;
const minStableSizeIterations = 3;
while(checkCounts++ <= maxChecks){
let html = await page.content();
let currentHTMLSize = html.length;
let bodyHTMLSize = await page.evaluate(() => document.body.innerHTML.length);
if(lastHTMLSize != 0 && currentHTMLSize == lastHTMLSize)
countStableSizeIterations++;
else
countStableSizeIterations = 0; //reset the counter
if(countStableSizeIterations >= minStableSizeIterations) {
console.log("Fully Rendered Page: " + page.url());
break;
}
lastHTMLSize = currentHTMLSize;
await page.waitForTimeout(checkDurationMsecs);
}
};
async function captureReport() {
const browser = await puppeteer.launch({"headless": false, args: ['--allow-no-sandbox-job', '--allow-sandbox-debugging', '--no-sandbox', '--ignore-certificate-errors', '--disable-storage-reset=true']});
const page = await browser.newPage();
const baseURL = "http://localhost/";
await page.setViewport({"width":1920,"height":1080});
await page.setDefaultTimeout(10000);
const navigationPromise = page.waitForNavigation({timeout: 30000, waitUntil: ['domcontentloaded']});
await page.goto(baseURL);
await navigationPromise;
const flow = await lighthouse.startFlow(page, {
name: 'demoblaze',
configContext: {
settingsOverrides: {
throttling: {
rttMs: 40,
throughputKbps: 10240,
cpuSlowdownMultiplier: 1,
requestLatencyMs: 0,
downloadThroughputKbps: 0,
uploadThroughputKbps: 0
},
throttlingMethod: "simulate",
screenEmulation: {
mobile: false,
width: 1920,
height: 1080,
deviceScaleFactor: 1,
disabled: false,
},
formFactor: "desktop",
onlyCategories: ['performance'],
},
},
});
//================================NAVIGATE================================
await flow.navigate(baseURL, {
stepName: 'open main page'
});
console.log('main page is opened');
//================================PAGE_ACTIONS================================
await flow.startTimespan({ stepName: 'Navigate to "Tables" tab' });
await page.waitForSelector('.main-menu a[href="/category/tables"]')
await page.click('.main-menu a[href="/category/tables"]')
await waitTillHTMLRendered(page);
await page.waitForSelector('.pro-same-action a[href="/product/olive-table"]');
await flow.endTimespan();
console.log('"Navigate to Tables" is completed');
await flow.startTimespan({ stepName: 'Open a table product' });
await page.waitForSelector('.product-content a[href="/product/olive-table"]')
await page.click('.product-content a[href="/product/olive-table"]')
await waitTillHTMLRendered(page);
await page.waitForSelector('.pro-details-cart button')
await flow.endTimespan();
console.log('"Open a table product" is completed');
await flow.startTimespan({ stepName: 'Add table to Cart' });
await page.waitForSelector('.pro-details-cart button')
await page.click('.pro-details-cart button')
await waitTillHTMLRendered(page);
await page.waitForSelector('.shopping-cart-content');
await flow.endTimespan();
console.log('"Add table to Cart" is completed');
await flow.startTimespan({ stepName: 'Open Cart' });
await page.waitForSelector('button.icon-cart')
await page.click('button.icon-cart')
await waitTillHTMLRendered(page);
await page.waitForSelector('.shopping-cart-content');
await page.waitForSelector('.shopping-cart-btn a[href="/cart"]');
await page.click('.shopping-cart-btn a[href="/cart"]')
await waitTillHTMLRendered(page);
await page.waitForSelector('.grand-totall > a[href="/checkout"]');
await flow.endTimespan();
console.log('"Open Cart" is completed');
await flow.startTimespan({ stepName: 'Proceed to checkout' });
await page.waitForSelector('.grand-totall > a[href="/checkout"]')
await page.click('.grand-totall > a[href="/checkout"]')
await waitTillHTMLRendered(page);
await page.waitForSelector('button.btn-hover');
await flow.endTimespan();
console.log('"Proceed to checkout" is completed');
//================================REPORTING================================
const reportPath = __dirname + '/Darya_Sayenka.user-flow.report.html';
const report = await flow.generateReport();
fs.writeFileSync(reportPath, report);
await browser.close();
}
captureReport();