Skip to content

Commit 73be694

Browse files
Dimitar TodorovDimitar Todorov
authored andcommitted
Add more tests for dateTimePicker
1 parent bf44253 commit 73be694

21 files changed

+143
-244
lines changed

demo-angular/e2e/helper.ts

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,56 @@ import { runType } from "nativescript-dev-appium/lib/parser";
44
const isAndroid: boolean = runType.includes("android");
55
const optionsText = "Options";
66
const moreOptionsID = "More options";
7+
let driver: AppiumDriver;
78

8-
export function getDateString() {
9-
const date = new Date();
10-
let year = date.getFullYear().toString();
11-
let month = date.toLocaleString('en-us', { month: 'short' });
12-
let day = date.getDate().toString();
13-
if (date.getDate() < 10) {
14-
day = "0" + date.getDay().toString();
15-
}
16-
const dateString = month + " " + day + ", " + year;
17-
return dateString;
18-
}
19-
20-
export async function getPickerTime() {
21-
let driver: AppiumDriver;
22-
driver = await createDriver();
23-
driver.defaultWaitTime = 15000;
9+
export async function getPickerTime(driver: AppiumDriver, format: number) {
2410
let selector = isAndroid ? "android.widget.EditText" : "XCUIElementTypePickerWheel";
2511
const pickerWheels = await driver.findElementsByClassName(selector);
2612
let hourWheel = await (await pickerWheels[0]).text();
2713
let minutesWheel = await (await pickerWheels[1]).text();
28-
const amPmWheel = await (await pickerWheels[2]).text();
2914
if(!isAndroid){
3015
hourWheel = hourWheel.slice(0, hourWheel.indexOf(" "));
3116
minutesWheel = minutesWheel.slice(0, minutesWheel.indexOf(" "));
3217
}
33-
const timeString = hourWheel + ":" + minutesWheel + " " + amPmWheel;
18+
let timeString = hourWheel + ":" + minutesWheel;
19+
if(format == 12){
20+
const amPmWheel = await (await pickerWheels[2]).text();
21+
timeString += " " + amPmWheel;
22+
}
3423
return timeString;
3524
}
3625

37-
export async function getPickerDate() {
38-
let driver: AppiumDriver;
39-
driver = await createDriver();
40-
driver.defaultWaitTime = 15000;
26+
export async function getPickerDate(driver: AppiumDriver) {
4127
let selector = isAndroid ? "android.widget.EditText" : "XCUIElementTypePickerWheel";
4228
const pickerWheels = await driver.findElementsByClassName(selector);
43-
let monthWheel = await (await pickerWheels[0]).text();
29+
let monthWheel = await (await pickerWheels[0]).text()
30+
let month = monthWheel.toString().substring(0, 3);
4431
let dayWheel = await (await pickerWheels[1]).text();
32+
if(parseInt(dayWheel) < 10){
33+
dayWheel = dayWheel.substring(1,2);
34+
}
4535
const yearWheel = await (await pickerWheels[2]).text();
46-
const timeString = monthWheel + ":" + dayWheel + " " + yearWheel;
47-
return timeString;
48-
}
36+
const dateString = month + " " + dayWheel + ", " + yearWheel;
37+
return dateString;
38+
}
39+
40+
export async function clickOkBtn(driver: AppiumDriver){
41+
const okBtn = await driver.findElementByText("OK", SearchOptions.exact);
42+
await okBtn.click();
43+
}
44+
45+
export async function scrollToElement(driver: AppiumDriver, element: string, direction: Direction = Direction.down) {
46+
let listView;
47+
if (isAndroid) {
48+
listView = await driver.findElementByClassName("android.widget.FrameLayout");
49+
}
50+
else {
51+
listView = await driver.findElementByClassName("XCUIElementTypeApplication");
52+
}
53+
const listItem = await listView.scrollTo(
54+
direction,
55+
() => driver.findElementByText(element, SearchOptions.contains),
56+
600
57+
);
58+
return listItem;
59+
}

demo-angular/e2e/tests.e2e.ts

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium";
1+
import { AppiumDriver, createDriver, SearchOptions, Direction} from "nativescript-dev-appium";
22
import { isSauceLab, runType } from "nativescript-dev-appium/lib/parser";
33
import { expect } from "chai";
44
import { ok } from "assert";
5-
import { getDateString, getPickerTime } from "./helper";
5+
import { getPickerTime, clickOkBtn, scrollToElement, getPickerDate} from "./helper";
66
const fs = require('fs');
77
const addContext = require('mochawesome/addContext');
88
const rimraf = require('rimraf');
@@ -54,28 +54,97 @@ describe("DateTimePicker", () => {
5454
it("Should select date and verify value of picker field", async () => {
5555
const selectDateField = await driver.findElementByText("select date", SearchOptions.contains);
5656
await selectDateField.click();
57-
const okBtn = await driver.findElementByText("OK", SearchOptions.exact);
58-
await okBtn.click();
59-
const date = getDateString();
60-
console.log(date);
57+
const date = await getPickerDate(driver);
58+
await clickOkBtn(driver);
6159
const dateSelected = await driver.findElementByText(date);
6260
expect(dateSelected).to.exist;
6361
});
6462

6563
it("Should select time and verify value of picker field", async () => {
6664
const selectTimeField = await driver.findElementByText("select time", SearchOptions.contains);
6765
await selectTimeField.click();
68-
const timeString = await getPickerTime();
69-
70-
const okBtn = await driver.findElementByText("OK", SearchOptions.exact);
71-
await okBtn.click();
66+
const timeString = await getPickerTime(driver, 12);
67+
await clickOkBtn(driver);
7268
const timeSelected = await driver.findElementByText(timeString, SearchOptions.contains);
7369
expect(timeSelected).to.exist;
7470
});
7571

7672
it("Should select date from min/max limited field", async () => {
77-
const minMaxLabel = await driver.findElementByText("min and max date", SearchOptions.contains);
78-
73+
const minMaxDatePicker = await driver.findElementByText("tap to select", SearchOptions.contains);
74+
await minMaxDatePicker.click();
75+
const date = await getPickerDate(driver);
76+
await clickOkBtn(driver);
77+
const dateSelected = await driver.findElementByText(date);
78+
expect(dateSelected).to.exist;
79+
});
80+
81+
it("Should open 12h time format and verify wheelers values", async () => {
82+
const twelveHourFormat = await driver.findElementByText("4:00 PM", SearchOptions.contains);
83+
await twelveHourFormat.click();
84+
const timeString = await getPickerTime(driver, 12);
85+
await clickOkBtn(driver);
86+
expect(timeString).to.equal("4:00 PM");
87+
});
88+
89+
it("Should open 24h format and verify wheeler value", async () => {
90+
const twentyFourFormat = await scrollToElement(driver, "16:00", Direction.down);
91+
await twentyFourFormat.click();
92+
const timeString = await getPickerTime(driver, 24);
93+
await clickOkBtn(driver);
94+
expect(timeString).to.equal("16:00");
95+
});
96+
97+
it("Should verify modified texts field for date picker", async () => {
98+
await scrollToElement(driver, "modified picker texts", Direction.down);
99+
const pickers = await driver.findElementsByText("tap to choose");
100+
const datePicker = pickers[0];
101+
await datePicker.click();
102+
const date = await getPickerDate(driver);
103+
const approveBtn = await driver.findElementByText("Approve", SearchOptions.contains);
104+
const rejectBtn = await driver.findElementByText("Reject", SearchOptions.contains);
105+
const title = await driver.findElementByText("Confirm predefined date selection", SearchOptions.contains);
106+
expect(approveBtn).to.exist;
107+
expect(rejectBtn).to.exist;
108+
expect(title).to.exist;
109+
await approveBtn.click();
110+
const dateString = await driver.findElementByText(date);
111+
expect(dateString).to.exist;
112+
});
113+
114+
it("Should verify modified texts field for time picker", async () => {
115+
const datePicker = await driver.findElementByText("tap to choose");
116+
await datePicker.click();
117+
const time = await getPickerTime(driver, 12);
118+
const approveBtn = await driver.findElementByText("Approve", SearchOptions.contains);
119+
const rejectBtn = await driver.findElementByText("Reject", SearchOptions.contains);
120+
const title = await driver.findElementByText("Confirm predefined time selection", SearchOptions.contains);
121+
expect(approveBtn).to.exist;
122+
expect(rejectBtn).to.exist;
123+
expect(title).to.exist;
124+
await approveBtn.click();
125+
const dateString = await driver.findElementByText(time);
126+
expect(dateString).to.exist;
127+
});
128+
129+
it("Should select date from de_De locale picker and verify format", async () => {
130+
await scrollToElement(driver, "preferred locale: de_DE", Direction.down);
131+
const datePicker = await driver.findElementByText("datum auswählen", SearchOptions.contains);
132+
await datePicker.click();
133+
const date = await getPickerDate(driver);
134+
const acceptBtn = await driver.findElementByText("BestÄtigen", SearchOptions.contains);
135+
const rejectBtn = await driver.findElementByText("Stornieren", SearchOptions.contains);
136+
const title = await driver.findElementByText("Datum auswählen", SearchOptions.contains);
137+
expect(acceptBtn).to.exist;
138+
expect(rejectBtn).to.exist;
139+
expect(title).to.exist;
140+
await acceptBtn.click();
141+
const dateString = new Date(date).toLocaleDateString('de-DE', {
142+
year: 'numeric',
143+
month: '2-digit',
144+
day: 'numeric'
145+
});
146+
const dateField = await driver.findElementByText(dateString);
147+
expect(dateString).to.exist;
79148
});
80149

81150
});
Binary file not shown.

0 commit comments

Comments
 (0)