-
Notifications
You must be signed in to change notification settings - Fork 95
/
exercises.spec.js
162 lines (144 loc) · 5.48 KB
/
exercises.spec.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
//
// ==================================================================
// We are using accessibilityId's here so easily select elements for
// Android and iOS in a cross-platform way
// This project is not using a PageObject model because it's not part
// if the scope of this exercise
// ==================================================================
//
describe('Appium Gestures Exercises', () => {
// This will be executed for every test, log in and verify that the
// correct screen is loaded
beforeEach(async () => {
// Wait for the App to be opened
await $('~test-Login').waitForDisplayed();
// Login in and wait for the items screen is visible
await $('~test-Username').addValue('standard_user');
await $('~test-Password').addValue('secret_sauce');
await $('~test-LOGIN').click();
await $('~test-PRODUCTS').waitForDisplayed();
});
// This will be executed after each test
afterEach(async () => {
// Restart the app after each test
await driver.reset();
});
it('should be able to do a scroll with TouchPerform', async () => {
// 1. Get the screen / element size (element size is explained in the touch actions)
/**
* CODE THIS STEP
*/
// 2. Determine the x/y from/to position
const from = {
// Get the center of the horizontal axis
x: '{DETERMINE-VALUE}',
// Always start a few pixels above the bottom of the screen
// otherwise you might open a system menu
y: '{DETERMINE-VALUE}',
};
const to = {
// Get the center of the horizontal axis
x: '{DETERMINE-VALUE}',
// Stop at the top of the screen, or maybe a little bit below
// the top
y: '{DETERMINE-VALUE}',
};
/**
* CODE THIS STEP
*/
// 3. Execute the touch perform
// 3a. The press which is the start position of your finger
// 3b. The wait for the speed of the move to
// 3c. The move which will be the end position of your finger
// 3d. Now release it
// For demo purpose
await driver.pause(5000);
});
it('should be able to do a swipe with TouchActions', async () => {
// Prepare test by adding the first product to the cart and go to the cart
await (await $$('~test-ADD TO CART'))[0].click();
// Open the cart
await $('~test-Cart').click();
await $('~test-Cart Content').waitForDisplayed();
/**
* CODE THIS STEP
*/
// 1. Get the size of the element
const firstItem = (await $$('~test-Item'))[0];
/**
* CODE THIS STEP
*/
// 2. Determine X and Y position
// We move our finger on the horizontal axis, this means we need to
// have a starting X position and the Y position will stay the same.
// We need to determine the startX and centerY position
const startX = '{DETERMINE-VALUE}';
const centerY = '{DETERMINE-VALUE}';
/**
* CODE THIS STEP
*/
// 3. Execute the touch action
// We swipe over the horizontal axis which means the Y position
// will always stay the same, but you can change it to create
// different gestures for swiping
// See https://github.com/jlipps/simple-wd-spec#perform-actions
// for a clear explanation of all properties
// 3a. Create the event
// 3b. Move finger into start position
// 3c. Finger comes down into contact with screen
// 3d. Pause for a little bit
// 3e. Finger moves to end position
// We move our finger from the center of the element to the
// starting position of the element
// 3f. Finger lets up, off the screen
// For demo purpose
await driver.pause(5000);
});
it('should be able to scroll the easy way', async () => {
// 2. Android and iOS have their own implementation of executing a "simple"
// scroll, so we ask the driver here if we are an Android or iOS device
// Be aware that you need to have Appium 1.19.0 on your machine!
if (driver.isAndroid) {
// 2a. See http://appium.io/docs/en/writing-running-appium/android/android-mobile-gestures/#mobile-scrollGesture
// for more information
/**
* CODE THIS STEP
*/
} else {
// 2b. See http://appium.io/docs/en/writing-running-appium/ios/ios-xctest-mobile-gestures/index.html#mobile-scroll
// for more information
/**
* CODE THIS STEP
*/
}
// For demo purpose
await driver.pause(5000);
});
it('should be able to swipe the easy way', async () => {
// Prepare test by adding the first product to the cart and go to the cart
await (await $$('~test-ADD TO CART'))[0].click();
// Open the cart
await $('~test-Cart').click();
await $('~test-Cart Content').waitForDisplayed();
// 1. Get the swag item we want to swipe
const firstItemId = (await $$('~test-Item'))[0].elementId;
// 2. Android and iOS have their own implementation of executing a "simple"
// swipe, so we ask the driver here if we are an Android or iOS device
// Be aware that you need to have Appium 1.19.0 on your machine!
if (driver.isAndroid) {
// 2a. See http://appium.io/docs/en/writing-running-appium/android/android-mobile-gestures/#mobile-swipegesture
// for more information
/**
* CODE THIS STEP
*/
} else {
// 2b. See http://appium.io/docs/en/writing-running-appium/ios/ios-xctest-mobile-gestures/#mobile-swipe
// for more information
/**
* CODE THIS STEP
*/
}
// For demo purpose
await driver.pause(5000);
});
});