forked from saucelabs/sample-app-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
191 lines (157 loc) · 4.06 KB
/
login.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
import { getTextOfElement } from '../helpers/utils';
import Base from './base';
import { DEFAULT_TIMEOUT } from '../helpers/e2eConstants';
class LoginScreen extends Base {
constructor() {
super(`~test-${ driver.selectors.login.screen }`);
}
get SELECTORS() {
return driver.selectors;
}
get screen() {
return $(`~test-${ this.SELECTORS.login.screen }`);
}
get username() {
return $(`~test-${ this.SELECTORS.login.username }`);
}
get password() {
return $(`~test-${ this.SELECTORS.login.password }`);
}
get biometryButton() {
return $(`~test-${ this.SELECTORS.login.biometry }`);
}
get iosAllowBiometry() {
return $('~Don’t Allow');
}
get allowBiometry() {
return $('~OK');
}
get iosRetryBiometry() {
return $('~Try Again');
}
get androidBiometryAlert() {
return $('*//*[@resource-id="com.swaglabsmobileapp:id/fingerprint_icon"]');
}
get loginButton() {
return $(`~test-${ this.SELECTORS.login.loginButton }`);
}
get errorMessage() {
return $(`~test-${ this.SELECTORS.login.errors.container }`);
}
get standardUser() {
return $(`~test-${ this.SELECTORS.login.loginText.standard }`);
}
get lockedUser() {
return $(`~test-${ this.SELECTORS.login.loginText.locked }`);
}
get problemUser() {
return $(`~test-${ this.SELECTORS.login.loginText.problem }`);
}
/**
* Sign in
*
* @param {object} userDetails
* @param {string} userDetails.username
* @param {string} userDetails.password
*/
signIn(userDetails = {}) {
const { password, username } = userDetails;
if (username && username !== '') {
this.username.addValue(username);
}
if (password && password !== '') {
this.password.addValue(password);
}
this.loginButton.click();
}
/**
* Submit biometric login
*
* @param {boolean|number} successful
*/
submitBiometricLogin(successful) {
// Touch / Face ID needs to be triggered differently on iOS
if (driver.isIOS) {
// Determine Face / Touch ID
return this.submitIosBiometricLogin(successful);
}
return this.submitAndroidBiometricLogin(successful ? 1234 : 4321);
}
/**
* Verify that the biometric login failed
*
* return {boolean}
*/
isBiometryAlertShown() {
if (driver.isIOS) {
return this.iosRetryBiometry.waitForDisplayed({ timeout: DEFAULT_TIMEOUT });
}
// We need to pause here to make sure the biometric log in has been executed
driver.pause(1000);
return this.androidBiometryAlert.waitForDisplayed({ timeout: DEFAULT_TIMEOUT });
}
/**
* Submit iOS biometric login
*
* @param {boolean} successful
*
* @return {Promise<void>}
*/
submitIosBiometricLogin(successful) {
// Check if biometric usage is allowed
if (!driver.config.services.includes('sauce')) {
this.allowIosBiometricUsage();
return driver.execute('mobile:sendBiometricMatch', { type: this.isFaceId() ? 'faceId' : 'touchId', match: successful });
}
return driver.touchId(successful);
}
/**
* Allow biometric usage on iOS if it isn't already accepted
*/
allowIosBiometricUsage() {
if (!driver.isBioMetricAllowed) {
// Wait for the alert
this.iosAllowBiometry.waitForDisplayed({ timeout: DEFAULT_TIMEOUT });
this.allowBiometry.click();
// Set it to accept
driver.isBioMetricAllowed = true;
}
}
/**
* Check if this is the biometric login supports FaceID
*
* @return {boolean}
*/
isFaceId() {
return $(`~test-${ this.SELECTORS.login.faceRecognition }`).isDisplayed();
}
/**
* Submit Android biometric login
*
* @param {number} fingerprintId
*
* @return {Promise<void>}
*/
submitAndroidBiometricLogin(fingerprintId) {
this.androidBiometryAlert.waitForDisplayed({ timeout: DEFAULT_TIMEOUT });
return driver.fingerPrint(fingerprintId);
}
/**
* Get the text or the error message container
*
* @return {string}
*/
getErrorMessage() {
this.errorMessage.waitForDisplayed({ timeout: DEFAULT_TIMEOUT });
return getTextOfElement(this.errorMessage);
}
/**
* Check if the error message is displayed
*
* @return {boolean}
*/
isErrorMessageIsShown() {
return this.isShown(this.errorMessage);
}
}
export default new LoginScreen();