-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtests.e2e.ts
318 lines (293 loc) · 13.6 KB
/
tests.e2e.ts
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import { AppiumDriver, createDriver, SearchOptions, Direction } from "nativescript-dev-appium";
import { isSauceLab, runType } from "nativescript-dev-appium/lib/parser";
import { expect } from "chai";
import { ok } from "assert";
import { getPickerTime, clickOkBtn, scrollToElement, getPickerDate } from "./helper";
const fs = require('fs');
const addContext = require('mochawesome/addContext');
const rimraf = require('rimraf');
const isSauceRun = isSauceLab;
const deMonths = {
"Jan":"01",
"Feb":"02",
"Mär": "03",
"Apr": "04",
"Mai":"05",
"Jun":"06",
"Jul":"07",
"Aug":"08",
"Sep":"09",
"Okt":"10",
"Nov":"11",
"Dez":"12"
}
describe("DateTimePicker", () => {
const defaultWaitTime = 5000;
let driver: AppiumDriver;
before(async () => {
driver = await createDriver();
driver.defaultWaitTime = 15000;
let dir = "mochawesome-report";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
rimraf('mochawesome-report/*', function () { });
});
after(async () => {
if (isSauceRun) {
driver.sessionId().then(function (sessionId) {
console.log("Report https://saucelabs.com/beta/tests/" + sessionId);
});
}
await driver.quit();
console.log("Quit driver!");
});
afterEach(async function () {
if (this.currentTest.state && this.currentTest.state === "failed") {
let png = await driver.logScreenshot(this.currentTest.title);
fs.copyFile(png, './mochawesome-report/' + this.currentTest.title + '.png', function (err) {
if (err) {
throw err;
}
console.log('Screenshot saved.');
});
addContext(this, './' + this.currentTest.title + '.png');
}
});
it("Should verify demo title", async () => {
const title = await driver.findElementByText("DateTimePicker Demo", SearchOptions.contains);
expect(title).to.exist;
});
it("Should expand date picker field examples", async () => {
const dateFieldTitle = await driver.findElementByText("DatePickerField", SearchOptions.contains);
expect(dateFieldTitle).to.exist;
await dateFieldTitle.click();
});
it("Should select date and verify value of picker field", async () => {
const selectDateField = await driver.findElementByText("select date", SearchOptions.contains);
await selectDateField.click();
const date = await getPickerDate(driver);
await clickOkBtn(driver);
const dateSelected = await driver.findElementByText(date);
expect(dateSelected).to.exist;
});
it("Should select date from min/max limited field", async () => {
const minMaxDatePicker = await driver.findElementByText("tap to select", SearchOptions.contains);
await minMaxDatePicker.click();
const date = await getPickerDate(driver);
await clickOkBtn(driver);
console.log(date);
const dateSelected = await driver.findElementByText(date);
expect(dateSelected).to.exist;
});
it("Should verify modified texts field for date picker", async () => {
await scrollToElement(driver, "preferred locale: en_US", Direction.down);
const pickers = await driver.findElementsByText("tap to choose");
const datePicker = pickers[0];
await datePicker.click();
const date = await getPickerDate(driver);
const approveBtn = await driver.findElementByText("Approve", SearchOptions.contains);
const rejectBtn = await driver.findElementByText("Reject", SearchOptions.contains);
const title = await driver.findElementByText("Confirm predefined date selection", SearchOptions.contains);
expect(approveBtn).to.exist;
expect(rejectBtn).to.exist;
expect(title).to.exist;
await approveBtn.click();
const dateString = await driver.findElementByText(date);
expect(dateString).to.exist;
});
it("Should select date from de_De locale picker and verify format", async () => {
await scrollToElement(driver, "datum auswählen", Direction.down);
const deLocale = await driver.findElementByText("preferred locale: de_DE");
expect(deLocale).to.exist;
const datePicker = await driver.findElementByText("datum auswählen", SearchOptions.contains);
await datePicker.click();
const date = await getPickerDate(driver);
let selector = driver.isAndroid ? "android.widget.Button" : "Bestätigen";
let acceptBtn;
let rejectBtn;
if(driver.isAndroid){
let buttons = await driver.findElementsByClassName(selector);
acceptBtn = buttons[7];
rejectBtn = buttons[6];
}
else{
acceptBtn = await driver.findElementByText(selector, SearchOptions.contains);
rejectBtn = await driver.findElementByText("Stornieren", SearchOptions.exact);
}
const title = await driver.findElementByText("Datum auswählen", SearchOptions.exact);
expect(acceptBtn).to.exist;
expect(rejectBtn).to.exist;
expect(title).to.exist;
await acceptBtn.click();
let index = driver.isAndroid ? " " : "."
let day = date.substring(0, date.indexOf(index));
let dayNum = parseInt(day);
if(!driver.isAndroid && dayNum < 10){
day = "0" + day;
}
let month = date.substring(date.indexOf(" ") + 1, date.indexOf(","));
month = month.substring(0, 3);
let monthString = deMonths[month];
let year = date.substring(date.lastIndexOf(" ") + 1, date.length);
const dateString = day + "." + monthString + "." + year;
console.log(dateString);
const dateField = await driver.findElementByText(dateString);
expect(dateString).to.exist;
});
it("Should scroll to custom format and verify values", async () => {
await scrollToElement(driver, "binding", Direction.down);
const customFromatLabel = await driver.findElementByText("custom format");
expect(customFromatLabel).to.exist;
const customFormatDate = await driver.findElementByText("date: 24 February 2019", SearchOptions.exact);
expect(customFormatDate).to.exist;
});
it("Should scroll to css styled DatePicker and verify picker style", async () => {
let cssPickers = await driver.findElementsByText("Feb 24, 2019", SearchOptions.exact);
await cssPickers[cssPickers.length - 1].click();
await getPickerDate(driver);
await driver.compareScreen("cssDatePicker");
await clickOkBtn(driver);
});
it("Should scroll to binding example and verify picker and label values", async () => {
await scrollToElement(driver, "TimePickerField", Direction.down);
const bindingLabel = await driver.findElementByText("binding", SearchOptions.exact);
expect(bindingLabel).to.exist;
let selector = driver.isAndroid ? "android.widget.EditText" : "XCUIElementTypeTextField"
let fields = await driver.findElementsByClassName(selector);
let dateField;
if(driver.isAndroid){
dateField = fields[3];
}
else{
let index = fields.length;
console.log("index: " + index);
dateField = fields[index - 1];
}
await dateField.click();
let date = await getPickerDate(driver);
await clickOkBtn(driver);
let dateTime = new Date(date);
let year = dateTime.getFullYear().toString();
let dateLabel = dateTime.toString().substring(0, dateTime.toString().indexOf(year) + 4);
console.log(dateLabel);
let bindingDate = await driver.findElementByText(dateLabel, SearchOptions.contains);
});
it("Should expand time picker field examples", async () => {
const timeFieldTitle = await driver.findElementByText("TimePickerField", SearchOptions.contains);
expect(timeFieldTitle).to.exist;
await timeFieldTitle.click();
});
it("Should select time and verify value of picker field", async () => {
const selectTimeField = await driver.findElementByText("select time", SearchOptions.contains);
await selectTimeField.click();
const timeString = await getPickerTime(driver, 12);
await clickOkBtn(driver);
const timeSelected = await driver.findElementByText(timeString, SearchOptions.contains);
expect(timeSelected).to.exist;
});
it("Should open 12h time format and verify wheelers values", async () => {
const twelveHourFormat = await driver.findElementByText("4:00 PM", SearchOptions.contains);
await twelveHourFormat.click();
const timeString = await getPickerTime(driver, 12);
await clickOkBtn(driver);
expect(timeString).to.equal("4:00 PM");
});
it("Should open 24h format and verify wheeler value", async () => {
const twentyFourFormat = await scrollToElement(driver, "16:00", Direction.down);
await twentyFourFormat.click();
const timeString = await getPickerTime(driver, 24);
await clickOkBtn(driver);
expect(timeString).to.equal("16:00");
});
it("Should verify modified texts field for time picker", async () => {
await scrollToElement(driver, "tap to choose", Direction.down);
const datePicker = await driver.findElementByText("tap to choose");
await datePicker.click();
const time = await getPickerTime(driver, 12);
const approveBtn = await driver.findElementByText("Approve", SearchOptions.contains);
const rejectBtn = await driver.findElementByText("Reject", SearchOptions.contains);
const title = await driver.findElementByText("Confirm predefined time selection", SearchOptions.contains);
expect(approveBtn).to.exist;
expect(rejectBtn).to.exist;
expect(title).to.exist;
await approveBtn.click();
const dateString = await driver.findElementByText(time);
expect(dateString).to.exist;
});
it("Should select time from de_DE locale picker and verify format", async () => {
await scrollToElement(driver, "zeit wählen", Direction.down);
const timePicker = await driver.findElementByText("zeit wählen", SearchOptions.contains);
await timePicker.click();
const time = await getPickerTime(driver, 24);
let acceptBtn;
let rejectBtn;
if(driver.isAndroid){
let buttons = await driver.findElementsByClassName("android.widget.Button");
acceptBtn = buttons[5];
rejectBtn = buttons[4];
}
else{
acceptBtn = await driver.findElementByText("Bestätigen", SearchOptions.exact);
rejectBtn = await driver.findElementByText("Stornieren", SearchOptions.exact);
}
const title = await driver.findElementByText("Zeit wählen", SearchOptions.exact);
expect(acceptBtn).to.exist;
expect(rejectBtn).to.exist;
expect(title).to.exist;
await acceptBtn.click();
const dateField = await driver.findElementByText(time);
expect(time).to.exist;
});
it("Should scroll to custom format and verify values", async () => {
await scrollToElement(driver, "binding", Direction.down);
const customFromatLabel = await driver.findElementByText("custom format");
expect(customFromatLabel).to.exist;
const customFormatTime = await driver.findElementByText("time: 01:00", SearchOptions.exact);
expect(customFormatTime).to.exist;
});
it("Should scroll to css styled TimePicker and verify picker style", async () => {
const cssPickers = await driver.findElementsByText("1:00 AM", SearchOptions.exact);
await cssPickers[cssPickers.length - 1].click();
await getPickerTime(driver, 12);
await driver.compareScreen("cssTimePicker");
await clickOkBtn(driver);
});
it("Should expand custom buttons examples", async () => {
await scrollToElement(driver, "Custom Buttons", Direction.down);
const customButtonsTitle = await driver.findElementByText("Custom Buttons", SearchOptions.contains);
expect(customButtonsTitle).to.exist;
await customButtonsTitle.click();
});
it("Should tap button to select date and verify button text", async () => {
await scrollToElement(driver, "tap to select date and time", Direction.down);
let dateButton = await driver.findElementByText("tap to select date", SearchOptions.contains);
await dateButton.click();
const date = await getPickerDate(driver);
await clickOkBtn(driver);
const pickerDate = new Date(date);
let day = pickerDate.getDate();
let dayString = day.toString();
if(day < 10){
dayString = "0" + day.toString();
}
let month = pickerDate.getMonth() + 1;
let monthString = month.toString();
if(month < 10){
monthString = "0" + month.toString();
}
let year = pickerDate.getFullYear();
const dateString = dayString + "." + monthString+ "." + year;
console.log(dateString);
const dateField = await driver.findElementByText(dateString);
expect(dateString).to.exist;
})
it("Should tap button to select time and verify button text", async () => {
let timeButton = await driver.findElementByText("tap to select time", SearchOptions.contains);
await timeButton.click();
const time = await getPickerTime(driver, 24);
await clickOkBtn(driver);
timeButton = await driver.findElementByText(time);
expect(timeButton).to.exist;
});
});