-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmultiWindows1.js
74 lines (65 loc) · 2.3 KB
/
multiWindows1.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
// multiWindows1.js
//
// This is a simple test script that does the following:
// open a website
// validate title
// verify link text
//
// To Run:
// $ mocha multiWindow1.js
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Multiple Window Test for Web Driver IO - Tutorial Test Page Website', function() {
// set timeout to 20 seconds
this.timeout(20000);
var driver = {};
var handle = {};
// hook to run before tests
before( function () {
driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
return driver.init();
});
// 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')
.url('file:///Users/tkeith/Testing/Tutorial/HTML/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);
})
.windowHandles().then(function(result) {
handle = result;
console.log('Window handle: ' + handle.value + ' ' + handle.sessionId );
});
});
// click link to open new window and verify title
it('should Click link to open new window and verify title', function () {
return driver
// click link to open window
.click("//div[@id='multiWindows']/a").then (function () {
console.log('Clicked open window link');
})
.pause(5000)
.windowHandles().then(function(result) {
handle = result;
console.log('Window handle: ' + handle.value[0] + ' ' + handle.value[1] + ' ' + handle.value.length + ' ' + typeof handle.value[1]);
})
.window(handle.value[1])
.getTitle().then(function (title) {
// verify title
(title).should.be.equal("Tony Keith's Online Professional Resume and Information Site - Contact Page");
// uncomment for console debug
console.log('Current Page Title: ' + title);
});
});
after(function() {
return driver.end();
});
});