-
Notifications
You must be signed in to change notification settings - Fork 0
/
synthetic-script-sydney.js
124 lines (96 loc) · 4.54 KB
/
synthetic-script-sydney.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
// ----------------------------------------------------------------- sydni version
var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');
const getCheckOut = (gap) => {
const checkoutDate = new Date();
return checkoutDate.setDate(checkoutDate.getDate() + gap + 1);
}
const getCheckIn = (gap) => {
const checkInDate = new Date();
return checkInDate.setDate(checkInDate.getDate() + gap);
}
const formatDate = (date) => {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
const flowBuilderBlueprint = async function () {
let url = `https://hoteldomain.com.au/#/arise/accm/f922?c_in=${formatDate(getCheckIn(60))}&c_out=${formatDate(getCheckOut(60))}¤cy=USD&adult=2&child=0`;
log.info("Initial URL: " + url)
// 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});
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"main-logo\"]", { timeout: 30000 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"btn btn-primary float-right-custom\"]", { timeout: 30000 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"footer\"]", { timeout: 30000 });
});
await synthetics.executeStep('redirection', async function () {
await Promise.all([
page.waitForNavigation({ timeout: 30000 }),
await page.click("[class=\"btn btn-primary float-right-custom\"]")
]);
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"main-logo\"]", { timeout: 30000 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"start-rate\"]", { timeout: 30000 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"footer\"]", { timeout: 30000 });
});
await synthetics.executeStep('input', async function () {
await page.type("#name", "First Name");
await page.type("#name2", "Last Name");
await page.type("#name3", "synthatictest@mail.com");
await page.type("#name4", "0123456789");
await page.type("#name5", "Test note");
});
await synthetics.executeStep('redirection', async function () {
await Promise.all([
page.waitForNavigation({ timeout: 30000 }),
await page.click("[class=\"btn btn-primary\"]")
]);
});
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 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"main-logo\"]", { timeout: 30000 });
await page.waitForSelector("[class=\"start-rate\"]", { timeout: 30000 });
});
await synthetics.executeStep('verifySelector', async function () {
await page.waitForSelector("[class=\"footer\"]", { timeout: 30000 });
});
};
exports.handler = async () => {
return await flowBuilderBlueprint();
};