-
Notifications
You must be signed in to change notification settings - Fork 0
/
conference-registration-test-NR.js
269 lines (228 loc) · 11.6 KB
/
conference-registration-test-NR.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* Generated script for New Relic Synthetics
* Generated using se-builder with New Relic Synthetics Formatter
*
* Welcome to the Synthetics JavaScript IDE - Browser Edition
* You can think of it like node.js lite. Everything you'd expect to find in a
* node.js environment is also available here, with a few notable exceptions:
*
* - 'require' is limited to a useful subset of modules, get the full list from
* https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/scripting-monitors/writing-scripted-browsers
*
* - We've added a few top-level vars to the scope, all starting with '$':
*
* $browser - Synthetics-flavored WebDriver session for browser automation
* $driver - Main WebDriver public API module
* $http - 'request' node.js module (for making HTTP requests)
* $util - Common tools to aid with grunt work
*
* Feel free to explore, or check out the full documentation for details:
* https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/scripting-monitors/writing-scripted-browsers
*/
/** CONFIGURATIONS **/
// Script-wide timeout for wait and waitAndFind functions (in ms)
var DefaultTimeout = 10000;
// Change to any User Agent you want to use.
// Leave as "default" or empty to use the Synthetics default.
var UserAgent = "default";
/** HELPER FUNCTIONS **/
var assert = require('assert'),
By = $driver.By,
startTime = new Date(),
thisStep = 0,
VARS = {};
var log = function(msg) {
var elapsedSecs = (new Date() - startTime) / 1000.0;
console.log('Step ' + thisStep + ': ' + elapsedSecs.toFixed(1) + 's: ' + msg);
thisStep++;
};
// 1st log is sometimes ignored for some reason, so this is a dummy
log('init');
function isAlertPresent() {
try {
var thisAlert = $browser.switchTo().alert();
return true;
} catch (err) { return false; }
}
function isElementSelected(el) { return $browser.findElement(el).isSelected(); }
function isTextPresentIn(text, sourceEl) {
return sourceEl.getText()
.then(function (wholetext) {
log("Assert Text Present: '" + text +"'");
assert.notEqual(wholetext.indexOf(text), -1, "Text Not Found: '" + text + "'");
});
}
function isTextPresent(text) {
return isTextPresentIn(text, $browser.findElement(By.tagName('html')));
}
/** BEGINNING OF SCRIPT **/
// Setting User Agent is not then-able, so we do this first (if defined and not default)
if ((typeof UserAgent !== 'undefined') && (UserAgent != 'default')) {
$browser.addHeader('User-Agent', UserAgent);
log('Setting User-Agent to ' + UserAgent);
}
// Get browser capabilities and do nothing with it, so that we start with a then-able command
$browser.getCapabilities().then(function () { })
.then(function () {
log('get "http://pdstest.impulsecreative.com/twenty-sixteen-conference"');
return $browser.get("http://pdstest.impulsecreative.com/twenty-sixteen-conference");
})
.then(function () {
log('setElementText "company_name"');
return $browser.waitForAndFindElement(By.name("company_name"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("Derek Foster\'s Company"); })
.then(function () {
log('setElementText "company_address"');
return $browser.waitForAndFindElement(By.name("company_address"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("123 Random Address"); })
.then(function () {
log('setElementText "company_city"');
return $browser.waitForAndFindElement(By.name("company_city"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("Fort Tester"); })
.then(function () {
log('setElementSelected "//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[4]/div/select//option[15]"');
return $browser.waitForAndFindElement(By.xpath("//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[4]/div/select//option[15]"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.xpath("//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[4]/div/select//option[15]"))).perform(); } })
.then(function () {
log('setElementText "company_zip"');
return $browser.waitForAndFindElement(By.name("company_zip"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("12384"); })
.then(function () {
log('setElementText "company_website"');
return $browser.waitForAndFindElement(By.name("company_website"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("http://stackoverflow.com"); })
.then(function () {
log('setElementSelected "//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[8]/div/select//option[2]"');
return $browser.waitForAndFindElement(By.xpath("//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[8]/div/select//option[2]"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.xpath("//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[8]/div/select//option[2]"))).perform(); } })
.then(function () {
log('setElementSelected "//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[9]/div/select//option[3]"');
return $browser.waitForAndFindElement(By.xpath("//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[9]/div/select//option[3]"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.xpath("//div[1]/form[1]/div[1]/div/div[2]/fieldset/div[1]/div[9]/div/select//option[3]"))).perform(); } })
.then(function () {
log('setElementText "conference_contact_name"');
return $browser.waitForAndFindElement(By.name("conference_contact_name"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("Derrick Fawster"); })
.then(function () {
log('setElementText "conference_contact_email"');
return $browser.waitForAndFindElement(By.name("conference_contact_email"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("fawster@gmail.com"); })
.then(function () {
log('setElementText "attendee_one_name"');
return $browser.waitForAndFindElement(By.name("attendee_one_name"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("Jimmy Bob"); })
.then(function () {
log('setElementText "attendee_one_email"');
return $browser.waitForAndFindElement(By.name("attendee_one_email"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("jimbob@gmail.com"); })
.then(function () {
log('setElementText "attendee_two_name"');
return $browser.waitForAndFindElement(By.name("attendee_two_name"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("Stephanie Stars"); })
.then(function () {
log('setElementText "attendee_two_email"');
return $browser.waitForAndFindElement(By.name("attendee_two_email"), DefaultTimeout); })
.then(function (el) {
el.clear();
el.sendKeys("starstruck@gmail.com"); })
.then(function () {
log('clickElement "input.btn.btn-primary-green"');
return $browser.waitForAndFindElement(By.css("input.btn.btn-primary-green"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('clickElement "label"');
return $browser.waitForAndFindElement(By.css("label"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('setElementSelected "eventSponsor"');
return $browser.waitForAndFindElement(By.id("eventSponsor"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.id("eventSponsor"))).perform(); } })
.then(function () {
log('clickElement "div.checkbox > label"');
return $browser.waitForAndFindElement(By.css("div.checkbox > label"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('setElementSelected "electricity"');
return $browser.waitForAndFindElement(By.name("electricity"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.name("electricity"))).perform(); } })
.then(function () {
log('setElementSelected "//div[@class=\'form-horizontal\']/div[8]/div[1]/select//option[4]"');
return $browser.waitForAndFindElement(By.xpath("//div[@class=\'form-horizontal\']/div[8]/div[1]/select//option[4]"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.xpath("//div[@class=\'form-horizontal\']/div[8]/div[1]/select//option[4]"))).perform(); } })
.then(function () {
log('setElementSelected "//div[@class=\'form-horizontal\']/div[10]/div[1]/select//option[3]"');
return $browser.waitForAndFindElement(By.xpath("//div[@class=\'form-horizontal\']/div[10]/div[1]/select//option[3]"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.xpath("//div[@class=\'form-horizontal\']/div[10]/div[1]/select//option[3]"))).perform(); } })
.then(function () {
log('clickElement "//div[1]/form[2]/div[3]/input[2]"');
return $browser.waitForAndFindElement(By.xpath("//div[1]/form[2]/div[3]/input[2]"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('clickElement "div.billing-info-container__left-column.col-lg-6 > div.radio > label"');
return $browser.waitForAndFindElement(By.css("div.billing-info-container__left-column.col-lg-6 > div.radio > label"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('setElementSelected "by_check"');
return $browser.waitForAndFindElement(By.id("by_check"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.id("by_check"))).perform(); } })
.then(function () {
log('clickElement "div.well.well-md > div.radio > label"');
return $browser.waitForAndFindElement(By.css("div.well.well-md > div.radio > label"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('setElementSelected "halfOrFull"');
return $browser.waitForAndFindElement(By.name("halfOrFull"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.name("halfOrFull"))).perform(); } })
.then(function () {
log('clickElement "em"');
return $browser.waitForAndFindElement(By.css("em"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('setElementSelected "agreed_to_terms"');
return $browser.waitForAndFindElement(By.name("agreed_to_terms"), DefaultTimeout); })
.then(function(el) { return el.isSelected(); })
.then(function(bool) { if (!bool) { $browser.actions().click($browser.findElement(By.name("agreed_to_terms"))).perform(); } })
.then(function () {
log('clickElement "//div[1]/form[3]/div[3]/input"');
return $browser.waitForAndFindElement(By.xpath("//div[1]/form[3]/div[3]/input"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function () {
log('clickElement "h1.purple-text"');
return $browser.waitForAndFindElement(By.css("h1.purple-text"), DefaultTimeout); })
.then(function (el) { $browser.actions().click(el).perform(); })
.then(function() {
log('Browser script execution SUCCEEDED.');
}, function(err) {
log ('Browser script execution FAILED.');
throw(err);
});
/** END OF SCRIPT **/