-
Notifications
You must be signed in to change notification settings - Fork 1
/
protractor-helpers.js
56 lines (45 loc) · 1.23 KB
/
protractor-helpers.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
"use strict";
/*Check if current url contains given string*/
exports.expectUrl = function( url ){
if ( !url ){
return false;
}
expect( browser.getCurrentUrl() ).toContain( url );
};
/*Find element by model name*/
exports.$model = function( model ){
if ( !model ){
return false;
}
return element( by.model( model ) );
};
/*Find first element by css selector*/
exports.$first = function( selector ){
if ( !selector ){
return false;
}
return element.all( by.css( selector ) ).first();
};
/*Expect element text to equal given string*/
exports.expectText = function( selector, text ){
if ( !selector || !text ){
return false;
}
//using element.all to supress "more than 1 element warning"
expect( element.all(by.css(selector)).first().getText() ).toBe( text );
};
/*Waits for browser to see alert with the specified text then dismisses the alert*/
exports.waitForAlertText = function( expectedAlertText ){
browser.wait(function(){
return browser.switchTo().alert().then(
function(){return true;},
function(){return false;}
);
}, 5000);
browser.switchTo().alert().then(function( alert ){
expect(alert.getText(function(alertText){
expect(alertText).toContain( expectedAlertText );
}));
alert.dismiss();
});
};