-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcarouselExample1.js
More file actions
101 lines (90 loc) · 3.22 KB
/
carouselExample1.js
File metadata and controls
101 lines (90 loc) · 3.22 KB
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
// carouselExample1.js
//
// This is a simple test script that does the following tests:
// open a website
// validate title
// verify the number of images carousel
// verify carousel loads images with captions
// To Run:
// $ mocha carouselExample1.js
// Updated to support version >4 of webdriverio
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Carousel Test for Web Driver IO - Tutorial Test Page Website', function() {
// data array - firstName and lastName
var dataArray = [
{"id" : "1", "caption" : "Caption #1", "image" : "http://placehold.it/250/FF0000"},
{"id" : "2", "caption" : "Caption #2", "image" : "http://placehold.it/250/00FF00"},
{"id" : "3", "caption" : "Caption #3", "image" : "http://placehold.it/250/FFFF00"},
{"id" : "4", "caption" : "Caption #4", "image" : "http://placehold.it/250/0000FF"},
{"id" : "5", "caption" : "Caption #5", "image" : "http://placehold.it/250/CCFFFF"}
];
// set timeout to 60 seconds
this.timeout(60000);
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);
});
});
// verify the number of images carousel
it('should count the number of images in carousel', function () {
return driver
.elements(".item").then( function (s) {
(s.value.length).should.be.equal(5);
console.log('Count: ' + s.value.length);
});
});
// loop through each dataArray
dataArray.forEach(function(d) {
// verify carousel loads images with captions
it('should load carousel image #' + d.id + ' with caption', function () {
return driver
// wait for caption to be visible
.waitForVisible("//div[@id='item" + d.id + "']/div", 20000).then(function () {
console.log('Item #' + d.id + ' found');
})
// verify caption
.getText("//div[@id='item" + d.id + "']/div").then(function (link) {
console.log('Caption Found: ' + link);
(link).should.equal(d.caption);
})
// verify image
.getAttribute("//div[@id='item" + d.id + "']/img", "src").then(function (link) {
console.log('Image: ' + link);
(link).should.equal(d.image);
});
});
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});