-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidations.js
209 lines (178 loc) · 7.33 KB
/
validations.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
var webdriver = require('selenium-webdriver');
var until = require('selenium-webdriver').until;
var async = require('async');
var db = null;
//var config = require('./dataconfig');
var loggs =require('./logging');
var help = require('./helpers');
module.exports = {
//VALIDATIONS
validatepagetitle: function (Title) {
loggs.logtoconsole("validating pagetitle");
browser.wait(
browser.getTitle().then(function (title) {
loggs.logtoconsole("title = "+title)
loggs.logtoconsole("Title = "+Title)
if (title === Title) {
loggs.logtoconsole("Validation == PASS :: " + 'Page :' + Title + ' is displayed successfully');
return true;
} else {
loggs.assertEqualto(title, Title, 'Page:')
}
}),50000,'should be')
//cb(null,browser.manage().timeouts().implicitlyWait(10000))
},
validatenotpagetitle: function (Title) {
loggs.logtoconsole("validating pagetitle");
browser.getTitle().then(function (title) {
if (title !== Title) {
loggs.logtoconsole("Validation == PASS :: Page Title - " + title + 'is not Equal To '+Title);
return true;
} else {
loggs.assertNotEqualto(title, Title, 'Page:')
}
});
browser.manage().timeouts().implicitlyWait(10000);
},
//Rafa::: use this function to validate if any type of element is present
validateelementpresent: function (type, element, label) {
help.elementpresent(type, element).then(function (present) {
if (present) {
loggs.logtoconsole("Validation == PASS :: " + label + " is Present");
return true;
} else {
loggs.assertTrue(label,'present',present)
}
});
},
//Rafa::: use this function to validate if any type of element is displayed
validateelementdisplayed: function (type, element, label) {
module.exports.validateelementpresent(type, element, label);
help.findelement(type, element).isDisplayed().then(function (Link) {
loggs.logtoconsole(label+ ' is Displayed = ' + Link);
if (Link) {
loggs.logtoconsole("Validation == PASS :: " + label + " is displayed");
return true;
} else {
loggs.assertTrue(label,'displayed',Link)
}
}, function (err) {
loggs.errorroutine(err);
});
},
//Rafa::: use this function to validate if any type of element is selected
validateelementselected: function (type, element, label) {
module.exports.validateelementdisplayed(type, element, label);
help.findelement(type, element).isSelected().then(function (link) {
if (link) {
loggs.logtoconsole("Validation == PASS :: " + label + " is Selected");
return true;
} else {
loggs.assertTrue(label,'selected',link)
}
assert(help.findelement(type, element)).isSelected.isTrue();
}, function (err) {
loggs.errorroutine(err);
});
},
//Rafa::: use this function to validate the text of any type of element
validateelementtext: function (type, element, text,label) {
module.exports.validateelementpresent(type, element, label);
help.findelement(type, element).getText().then(function (Text) {
loggs.logtoconsole('Current text is :' + Text);
loggs.logtoconsole('Expected text is :' + text);
var link = (Text === text);
if (link) {
loggs.logtoconsole("Validation == PASS :: " +label + " text is equal to "+Text);
return true;
} else {
loggs.assertEqualto(Text,text,label)
}
});
},
//Rafa::: use this function to validate if any type of element contains a given text
validateelementcontainstext: function (type, element, text, label) {
async.series([function (callbackpro) {
module.exports.validateelementdisplayed(type, element, label);
help.findelement(type, element).getText().then(function (Text) {
loggs.logtoconsole('Current text is :' + Text);
loggs.logtoconsole('Expected text is :' + text);
var link = Text.indexOf(text) > -1;
if (link) {
loggs.logtoconsole("Validation == PASS :: " + text + " is found in " + Text);
return true;
} else {
loggs.assertContains(Text,text,label)
}
})
callbackpro(null);
}], function (err, result) {
if(err) {
loggs.errorroutine(err);
}
});
},
validateurl: function (url) {
browser.getCurrentUrl().then(function (link) {
loggs.logtoconsole('Actual URL is : ' + link);
loggs.logtoconsole('Expected URL is: ' + url);
var check = (link === url);
loggs.logtoconsole('link is equalto url :' + check);
if (check) {
loggs.logtoconsole("Correct URL Displayed");
loggs.logtoconsole('URL :' + link + ' is displayed');
loggs.logtoconsole('URL :' + url + ' should be displayed');
return true;
} else {
loggs.assertEqualto(url,link,'Url');
}
});
},
validatepagenot404: function (page) {
browser.getTitle().then(function (name) {
var result = (name.indexOf("404") !== 0)
if (result) {
loggs.logtoconsole("Page: " + page + " displayed successfully");
return true;
} else {
loggs.assertContains(name,'404',page);
}
});
},
//Rafa::: use this function to validate button is selected with any element
valradioBtnisselected: function (type, element, label) {
async.series([function (callbackpro) {
module.exports.validateelementpresent(type,element, label);
help.findelement(type, element).getAttribute('checked').then(function (attribute) {
if (attribute = 'checked') {
loggs.logtoconsole("Validation == PASS :: " + label + ' is selected')
} else {
loggs.assertEqualto(attribute,checked,label)
}
})
callbackpro(null);
}], function (err, result) {
if(err) {
loggs.errorroutine(err);
}
});
},
validatcurrwindowHandle: function (winHandle) {
browser.wait(function () {
loggs.logtoconsole("Getting current Window handle");
browser.getWindowHandle().then(function (Window) {
logs.logtoconsole("Current Window Handle: " + Window);
if (winHandle === Window) {
logs.logtoconsole("On current Window");
return true;
} else {
logs.logtoconsole("not on current window");
return false;
}
});
}, 6000).then(function () {
}, function (err) {
logs.errorroutine(err);
});
},
}