-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdataLoopExample2.js
106 lines (94 loc) · 3.26 KB
/
dataLoopExample2.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
// dataLoopExample2.js
//
// This is a simple test script that does the following:
// open a website
// validate title
// The example demos how to use an array of data
// Loop through the data to populate form fields, then submit the form
// Wait for results page
// Verify first / last name on the results page
// To Run:
// $ mocha dataLoopExample2.js OR $ grunt --gruntfile Gruntfile-dataLoopExample2.js webdriver
// Updated to support version >4 of webdriverio
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Loop Data Form Field Test for Web Driver IO - Tutorial Test Page Website', function() {
// data array - firstName and lastName
var dataArray = [
{"firstName" : "Tony", "lastName" : "Keith"},
{"firstName" : "John", "lastName" : "Doe"},
{"firstName" : "Jane", "lastName" : "Doe"},
{"firstName" : "Don", "lastName" : "Johnson"}
];
// set timeout to 30 seconds
this.timeout(30000);
var driver = {};
// hook to run before tests
before( function () {
// check for global browser (grunt + grunt-webdriver)
if(typeof browser === "undefined") {
// load the driver for browser
driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
return driver.init();
} else {
// grunt will load the browser driver
driver = browser;
return;
}
});
// a test spec - "specification"
it('should be load correct page and title', function () {
// load page, then call function()
return driver
.url('http://www.tlkeith.com/WebDriverIOTutorialTest.html')
// get title, then pass title to function()
.getTitle().then( function (title) {
// verify title
(title).should.be.equal("Web Driver IO - Tutorial Test Page");
// uncomment for console debug
// console.log('Current Page Title: ' + title);
});
});
// loop through each dataArray
dataArray.forEach(function(d) {
it('should populate fields, submit form, wait for results and verify data', function () {
return driver
// make sure you are on the starting page
.url('http://www.tlkeith.com/WebDriverIOTutorialTest.html')
.getTitle().then( function (title) {
// verify title
(title).should.be.equal("Web Driver IO - Tutorial Test Page");
})
.setValue("#fname", d.firstName)
.getValue("#fname").then( function (e) {
(e).should.be.equal(d.firstName);
console.log("First Name: " + e);
})
.setValue("#lname", d.lastName)
.getValue("#lname").then( function (e) {
(e).should.be.equal(d.lastName);
console.log("Last Name: " + e);
})
.submitForm("#search-form").then( function() {
console.log('Submit Search Form');
})
.waitForVisible("#search-results", 10000).then(function () {
console.log('Result Page Found');
})
.getText("//h1").then(function (link) {
console.log('Text found: ' + link);
(link).should.equal("Welcome " + d.firstName + " " + d.lastName + ".");
});
});
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});