-
Notifications
You must be signed in to change notification settings - Fork 23
/
autoComplete1.js
94 lines (83 loc) · 2.6 KB
/
autoComplete1.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
// autoComplete1.js
//
// This is a simple test script that does the following tests:
// open a website
// validate title
// enter first 2 letter 'Be' to input
// wait for autocomplete to open
// click on entry 'Bengals'
// verify input is 'Cincinnati Bengals'
//
//
// To Run:
// $ mocha autoComplete1.js
// Updated to support version >4 of webdriverio
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Autocomplete 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;
}
});
// a test spec - "specification"
it('should be load correct page and title', function () {
// load page, then call function()
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);
});
});
// Set the input to "Be"
it('should set input to Be', function () {
return driver
.setValue("#autocomplete", "Be")
.getValue("#autocomplete").then( function (e) {
console.log("Set input to: " + e);
(e).should.be.equal("Be");
});
});
// Select from auto completion list
it('should select auto completion', function () {
// wait for auto complete to open
return driver
.waitForVisible("#ui-id-1", 5000)
// there should be 2 autocomplete items: Bears, Bengals
// select the second entry: Bengals
.getText("//ul[@id='ui-id-1']/li[2]").then( function(e) {
console.log('Text: ' + e);
})
.click("//ul[@id='ui-id-1']/li[2]")
.getValue("#autocomplete").then( function (e) {
// the autocomplete will add the city name to the
console.log("Input: " + e);
(e).should.be.equal("Cincinnati Bengals");
});
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});