-
Notifications
You must be signed in to change notification settings - Fork 23
/
modal1.js
124 lines (112 loc) · 3.81 KB
/
modal1.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
// modal1.js
//
// This is a simple test script that shows how to interact with a modal (bootstrap) using 2 methods (ID/Xpath)
// It does the following:
// open a website (parent)
// validate title
// click on modal button
// wait for modal to open
// validate body text
// click close button
// wait until modal closes
// verify copyright (parent)
//
// To Run:
// $ mocha modal1.js
// Updated to support version >4 of webdriverio
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Modal Test for Web Driver IO - Tutorial Test Page Website', function() {
// set timeout to 10 seconds
this.timeout(10000);
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;
}
});
it('should be load correct page and title', function () {
// load page
return driver
.url('http://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);
});
});
// easy method - use ID selector
it('should verify text from modal body and click Close button (easy)', function () {
return driver
// click button by id
.click("#modalbutton").then (function () {
console.log('Clicked modal button');
})
// wait for modal to be visable
.waitForVisible("#myModal", 5000)
.getText("//div[@class='modal-body']").then(function (text) {
console.log('Text found: ' + text);
(text).should.equal("I agree to the following...");
})
// click the close button
.click("#closebutton").then (function () {
console.log('Clicked Close button in modal');
});
});
it('should contain Copyright text', function () {
return driver
// wait for modal to close and parent to be visual
.waitForVisible("#copyright", 5000)
.getText("#copyright").then(function (link) {
console.log('Copyright found: ' + link);
(link).should.equal("Tony Keith - tlkeith.com @ 2015-2017 - All rights reserved.");
});
});
// harder method - use xpath
it('should verify text from modal body and click (X) button', function () {
return driver
// click button by id
.click("#modalbutton").then (function () {
console.log('Clicked modal button');
})
// wait for modal to be visable
.waitForVisible("#myModal", 5000)
.getText("//div[@class='modal-body']").then(function (text) {
console.log('Text found: ' + text);
(text).should.equal("I agree to the following...");
})
// click the X close button
.click("//button[@class='close']").then (function () {
console.log('Clicked (X) button in modal');
});
});
it('should contain Copyright text', function () {
return driver
// wait for modal to close and parent to be visual
.waitForVisible("#copyright", 5000)
.getText("#copyright").then(function (link) {
console.log('Copyright found: ' + link);
(link).should.equal("Tony Keith - tlkeith.com @ 2015-2017 - All rights reserved.");
});
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});