-
Notifications
You must be signed in to change notification settings - Fork 23
/
formFillSubmit1.js
131 lines (116 loc) · 3.96 KB
/
formFillSubmit1.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
125
126
127
128
129
130
131
// formFillSubmit1.js
//
// This is a simple test script that does the following:
// open a website
// validate title
// fills/validates first name using id
// clears first name
// fills/validates first name using xpath from input
// clears first name
// fills/validates first name using xpath from form
// fills/validates last name using id
// submit the form
// wait for search results page
// To Run:
// $ mocha formFillSubmit1.js
// Updated to support version >4 of webdriverio
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Form Field 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://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);
});
});
// Set the first name using id to: Tony
it('should set first name to Tony', function () {
return driver.setValue("#fname", "Tony")
.getValue("#fname").then( function (e) {
(e).should.be.equal("Tony");
console.log("First Name: " + e);
});
});
// Clear the first name using id
it('should clear first name', function () {
return driver.clearElement("#fname")
.getValue("#fname").then( function (e) {
(e).should.be.equal("");
console.log("First Name: " + e);
});
});
// Set the first name using xpath from input to: Tony
it('should set first name to Tony', function () {
return driver.setValue("//input[@name='fname']", "Tony")
.getValue("//input[@name='fname']").then( function (e) {
(e).should.be.equal("Tony");
console.log("First Name: " + e);
});
});
// Clear the first name using xpath from input
it('should clear first name', function () {
return driver.clearElement("//input[@name='fname']")
.getValue("//input[@name='fname']").then( function (e) {
(e).should.be.equal("");
console.log("First Name: " + e);
});
});
// Set the first name using xpath from form to: Tony
it('should set first name to Tony', function () {
return driver.setValue("//form[@id='search-form']/input[1]", "Tony")
.getValue("//form[@id='search-form']/input[1]").then( function (e) {
(e).should.be.equal("Tony");
console.log("First Name: " + e);
});
});
// Set the last name using id to: Keith
it('should set last name to Keith', function () {
return driver.setValue("#lname", "Keith")
.getValue("#lname").then( function (e) {
(e).should.be.equal("Keith");
console.log("Last Name: " + e);
});
});
// Submit form and wait for search results
it('should submit form and wait for results', function () {
return driver.submitForm("#search-form").then( function(e) {
console.log('Submit Search Form');
})
.waitForVisible("#search-results", 10000).then(function (e) {
console.log('Search Results Found');
});
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});