-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdataLoopExample1.js
114 lines (103 loc) · 5.59 KB
/
dataLoopExample1.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
// dataLoopExample1.js
//
// The example demos how to use an array of data and loop
// through the data to verify URL/TEXT and the page exists.
//
// This is a simple test script that does the following:
// open a website
// validate title
// validates page with many links
// each link is validated and the link is loaded
// To Run:
// $ mocha dataLoopExample1.js
// 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 URL Test for Web Driver IO - Tutorial Test Page Website', function() {
// Link data - link and text
var linkArray = [
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/tutorial1.js", "name" : "tutorial1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/linkTextURL1.js", "name" : "linkTextURL1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/copyright1.js", "name" : "copyright1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/formFillSubmit1.js", "name" : "formFillSubmit1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/showHideVerify1.js", "name" : "showHideVerify1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/dynamicBrowser.js", "name" : "dynamicBrowser.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/callbackPromise.js", "name" : "callbackPromise.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/debugExample1.js", "name" : "debugExample1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/formFieldValidation.js", "name" : "formFieldValidation.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/common/commonLib.js", "name" : "commonLib.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/dataLoopExample1.js", "name" : "dataLoopExample1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/dataLoopExample2.js", "name" : "dataLoopExample2.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/cssValidation1.js", "name" : "cssValidation1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/saucelabs.js", "name" : "saucelabs.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/gruntSaucelabs.js", "name" : "gruntSaucelabs.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/Gruntfile.js", "name" : "Gruntfile.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/Gruntfile-dataLoopExample2.js", "name" : "Gruntfile-dataLoopExample2.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/Gruntfile-gruntSaucelabs.js", "name" : "Gruntfile-gruntSaucelabs.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/wdio.conf-saucelabs-dataLoopExample2.js", "name" : "wdio.conf-saucelabs-dataLoopExample2.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/wdio.conf-dataLoopExample2.js", "name" : "wdio.conf-dataLoopExample2.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/restAPIExample1.js", "name" : "restAPIExample1.js"},
{"link" : "https://github.com/onewithhammer/web-driver-io-tutorial/blob/master/dbDataLoopExample.js", "name" : "dbDataLoopExample.js"}
];
// set timeout to 240 seconds since there are so many links to check
this.timeout(240000);
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 linkArray
linkArray.forEach(function(d) {
it('should contain text/link then goto page - ' + d.name, 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");
})
// find the URL
.getAttribute('a=' + d.name, "href").then(function (link) {
(link).should.equal(d.link);
console.log('URL found: ' + d.link);
})
// go to URL page and verify it exists (wait 15 seconds before timeout)
.click('a=' + d.name)
.waitForVisible("#js-repo-pjax-container", 15000).then(function () {
console.log('Github Page Found');
});
});
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});