-
Notifications
You must be signed in to change notification settings - Fork 0
/
synthetic-script-current.js
90 lines (73 loc) · 3.45 KB
/
synthetic-script-current.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
// ------------------------------------------------- current version
var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');
const getYYYYMMDD = (d0) => {
const d = new Date(d0)
return new Date(d.getTime() - d.getTimezoneOffset() * 60 * 1000).toISOString().split('T')[0]
}
const flowBuilderBlueprint = async function () {
// INSERT URL here
const checkin = new Date().setMonth(new Date().getMonth() + 3);
let url = `https://hoteldomain.com.au/#/arise/accm/f922?c_in=${getYYYYMMDD(checkin)}&c_out=${getYYYYMMDD(new Date(checkin).setDate(new Date().getDate() + 1) )}¤cy=LKR&adult=2&child=0`;
// Get synthetics configuration
let syntheticsConfig = synthetics.getConfiguration();
// Set configuration values
syntheticsConfig.setConfig({
screenshotOnStepStart : true,
screenshotOnStepSuccess: true,
screenshotOnStepFailure: true
});
let page = await synthetics.getPage();
// Navigate to the initial url
await synthetics.executeStep('navigateToUrl', async function (timeoutInMillis = 30000) {
await page.goto(url, {waitUntil: ['load', 'networkidle0'], timeout: timeoutInMillis});
});
// Execute customer steps
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"main-logo\"]", { timeout: 30000 });
});
// Execute customer steps
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"btn btn-primary canary-selector\"]", { timeout: 30000 });
});
await synthetics.executeStep('redirection', async function () {
await Promise.all([
page.waitForNavigation({ timeout: 30000 }),
await page.click("[class=\"btn btn-primary canary-selector\"]")
]);
});
await synthetics.executeStep('input', async function () {
await page.type("[id=\"fname\"]", "first name");
});
await synthetics.executeStep('input', async function () {
await page.type("[id=\"lname\"]", "last name");
});
await synthetics.executeStep('input', async function () {
await page.type("[id=\"email\"]", "test@email.com");
});
await synthetics.executeStep('input', async function () {
await page.type("[id=\"phone\"]", "0777777777");
});
await synthetics.executeStep('redirection', async function () {
await Promise.all([
page.waitForNavigation({ timeout: 30000 }),
await page.click("[id=\"confirmGuestInfo\"]")
]);
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"btn btn-primary\"]", { timeout: 30000 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("iframe");
const elementHandle = await page.$('div.creditcard-wrapper iframe');
const frame = await elementHandle.contentFrame();
await frame.waitForSelector("[id=\"cardholderName\"]", { timeout: 30000 });
await frame.waitForSelector("[id=\"cardNumber\"]", { timeout: 30000 });
await frame.waitForSelector("[id=\"expiryDateMonth\"]", { timeout: 30000 });
await frame.waitForSelector("[id=\"expiryDateYear\"]", { timeout: 30000 });
await frame.waitForSelector("[id=\"cvn\"]", { timeout: 30000 });
});
};
exports.handler = async () => {
return await flowBuilderBlueprint();
};