forked from edgarmsilva/QAEngineeringChallenge2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logPartTab.ts
89 lines (80 loc) · 2.84 KB
/
logPartTab.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
import { element, by, waitFor } from 'detox';
import { selectPickerValue } from '../utils/interactions';
import { PICKER_ELEMENTS } from '../components/picker';
import { elementIsVisible } from '../utils/interactions';
const RUNNING_IOS = device.getPlatform() === 'ios';
export class LOG_PART_TAB {
static readonly TAB_TITLE: Detox.IndexableNativeElement = element(
by.id('LogPartTab')
);
static readonly PART_VALUE_INPUT_ELEMENT_BY_ID: Detox.IndexableNativeElement =
device.getPlatform() === 'ios'
? element(by.id('ComponentEditScreenPartValueInput'))
: element(by.type('android.widget.EditText'));
static readonly SAVE_BUTTON_ELEMENT_BY_TEXT: Detox.IndexableNativeElement =
RUNNING_IOS ? element(by.text('Save')) : element(by.text('SAVE'));
static readonly SAVE_SUCCESSFUL_ELEMENT_BY_ID: Detox.IndexableNativeElement =
element(by.id('ComponentEditScreenInfoSavedText'));
static async navigateTo(): Promise<void> {
if (
!(await elementIsVisible(this.PART_VALUE_INPUT_ELEMENT_BY_ID)) &&
(await elementIsVisible(this.TAB_TITLE))
) {
await this.TAB_TITLE.tap();
await waitFor(this.PART_VALUE_INPUT_ELEMENT_BY_ID).toBeVisible();
}
}
static async setMachineName(machineName: string): Promise<void> {
await waitFor(
element(by.id(PICKER_ELEMENTS.SELECT_PICKER_WRAPPER_ID)).atIndex(0)
).toBeVisible();
await selectPickerValue(
PICKER_ELEMENTS.SELECT_PICKER_WRAPPER_ID,
PICKER_ELEMENTS.SELECT_PICKER_ID,
PICKER_ELEMENTS.SELECT_DONE_ID,
0,
0,
machineName
);
}
static async setPartName(partName: string): Promise<void> {
await waitFor(
element(by.id(PICKER_ELEMENTS.SELECT_PICKER_WRAPPER_ID)).atIndex(1)
).toBeVisible();
await selectPickerValue(
PICKER_ELEMENTS.SELECT_PICKER_WRAPPER_ID,
PICKER_ELEMENTS.SELECT_PICKER_ID,
PICKER_ELEMENTS.SELECT_DONE_ID,
0,
1,
partName
);
}
static async setPartValue(partValue: string): Promise<void> {
await waitFor(this.PART_VALUE_INPUT_ELEMENT_BY_ID).toBeVisible();
await this.PART_VALUE_INPUT_ELEMENT_BY_ID.replaceText(partValue + '\n');
}
static async savePart(): Promise<void> {
await waitFor(this.SAVE_BUTTON_ELEMENT_BY_TEXT).toBeVisible();
await this.SAVE_BUTTON_ELEMENT_BY_TEXT.tap();
await waitFor(this.SAVE_SUCCESSFUL_ELEMENT_BY_ID).toBeVisible();
}
static async logPart(
machineName: string,
partName: string,
partValue: string
): Promise<void> {
await this.setPartValue(partValue);
await this.setMachineName(machineName);
await this.setPartName(partName);
await this.savePart();
}
static async navigateToAndLogPart(
machineName: string,
partName: string,
partValue: string
): Promise<void> {
await this.navigateTo();
await this.logPart(machineName, partName, partValue);
}
}