-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathformFieldValidation.js
More file actions
126 lines (109 loc) · 4.56 KB
/
formFieldValidation.js
File metadata and controls
126 lines (109 loc) · 4.56 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
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
// formFieldValidation.js
//
// This is a simple test script that does the following:
// open a website
// validate title
//
// verifies the form field errors using both local commands and reusable commands.
// To Run:
// $ mocha formFieldValidation.js
// Updated to support version 4 of webdriverio
// required libraries
var webdriverio = require('webdriverio'),
should = require('should'),
// require the reusable command - commonLib
common = require('./common/commonLib');
// a test script block or suite
describe('Form Field Test for Web Driver IO - Tutorial Test Page Website', function() {
// set timeout to 20 seconds
this.timeout(20000);
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'} });
// bind the commands
driver.addCommand('verifyFirstNameError', common.verifyFirstNameCheckError.bind(driver));
driver.addCommand('verifyLastNameError', common.verifyLastNameCheckError.bind(driver));
driver.addCommand('verifyAddressError', common.verifyAddressCheckError.bind(driver));
driver.addCommand('verifyCityError', common.verifyCityCheckError.bind(driver));
driver.addCommand('verifyStateError', common.verifyStateCheckError.bind(driver));
driver.addCommand('verifyInvalidStateError', common.verifyInvalidStateError.bind(driver));
return driver.init();
} else {
// grunt will load the browser driver
driver = browser;
// bind the commands
driver.addCommand('verifyFirstNameError', common.verifyFirstNameCheckError.bind(driver));
driver.addCommand('verifyLastNameError', common.verifyLastNameCheckError.bind(driver));
driver.addCommand('verifyAddressError', common.verifyAddressCheckError.bind(driver));
driver.addCommand('verifyCityError', common.verifyCityCheckError.bind(driver));
driver.addCommand('verifyStateError', common.verifyStateCheckError.bind(driver));
driver.addCommand('verifyInvalidStateError', common.verifyInvalidStateError.bind(driver));
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);
});
});
// non reusable function method
it('should contain 5 errors: first/last/address/city/state', function () {
// not using reusable functions - in commonLib library
return driver
.getText("//ul[@class='alert alert-danger']/li[1]").then(function (e) {
console.log('Error found: ' + e);
(e).should.be.equal('Please enter first name');
})
.getText("//ul[@class='alert alert-danger']/li[2]").then(function (e) {
console.log('Error found: ' + e);
(e).should.be.equal('Please enter last name');
})
.getText("//ul[@class='alert alert-danger']/li[3]").then(function (e) {
console.log('Error found: ' + e);
(e).should.be.equal('Please enter address');
})
.getText("//ul[@class='alert alert-danger']/li[4]").then(function (e) {
console.log('Error found: ' + e);
(e).should.be.equal('Please enter city');
})
.getText("//ul[@class='alert alert-danger']/li[5]").then(function (e) {
console.log('Error found: ' + e);
(e).should.be.equal('Please enter state');
});
});
// reusable function method - reading errors in error div
it('should contain 5 errors: first/last/address/city/state', function () {
// call the reusable functions - in commonLib library
return driver
.verifyFirstNameError(1)
.verifyLastNameError(2)
.verifyAddressError(3)
.verifyCityError(4)
.verifyStateError(5);
});
// reusable function method - reading errors in form input field
it('should contain 1 error: invalid state', function () {
// call the reusable functions - in commonLib library
return driver.verifyInvalidStateError();
});
// a "hook" to run after all tests in this block
after(function() {
if(typeof browser === "undefined") {
return driver.end();
} else {
return;
}
});
});