-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
app.swipe.spec.ts
100 lines (88 loc) · 4.87 KB
/
app.swipe.spec.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
import TabBar from '../screenobjects/components/TabBar.js';
import SwipeScreen from '../screenobjects/SwipeScreen.js';
import Carousel from '../screenobjects/components/Carousel.js';
import Gestures, { DIRECTIONS } from '../helpers/Gestures.js';
describe('WebdriverIO and Appium, when using swiping', () => {
beforeEach(async () => {
await TabBar.waitForTabBarShown();
await TabBar.openSwipe();
await SwipeScreen.waitForIsShown(true);
});
it('should be able to swipe horizontal by swiping the carousel from left to right', async () => {
/**
* To understand what happens in `isCardActive()` please check the method
*/
await expect(await Carousel.isCardActive(await Carousel.openSourceCard)).toBeTruthy();
/**
* To understand what happens in `swipeLeft()` please check the method
*/
await Carousel.swipeLeft();
await expect(await Carousel.isCardActive(await Carousel.communityCard)).toBeTruthy();
await Carousel.swipeLeft();
await expect(await Carousel.isCardActive(await Carousel.jsFoundationCard)).toBeTruthy();
await Carousel.swipeLeft();
await expect(await Carousel.isCardActive(await Carousel.supportVideosCard)).toBeTruthy();
await Carousel.swipeLeft();
await Carousel.swipeLeft();
await expect(await Carousel.isCardActive(await Carousel.compatibleCard)).toBeTruthy();
/**
* To understand what happens in `swipeRight()` please check the method
*/
await Carousel.swipeRight();
await expect(await Carousel.isCardActive(await Carousel.extendableCard)).toBeTruthy();
await Carousel.swipeRight();
await Carousel.swipeRight();
await Carousel.swipeRight();
await Carousel.swipeRight();
await expect(await Carousel.isCardActive(await Carousel.openSourceCard)).toBeTruthy();
});
it('should be able to swipe vertical by finding the surprise', async ()=>{
// Swipe vertical and try to find the element. You can only swipe a max of 5 times
await Gestures.checkIfDisplayedWithSwipe({
scrollContainer: await SwipeScreen.screen,
searchableElement: await SwipeScreen.logo,
maxScrolls: 5,
direction: DIRECTIONS.UP,
percentage: 0.99,
});
await expect(SwipeScreen.logo).toBeDisplayed();
});
// You will find native a native swipe example below, but it is commented out because even though it looks "simple",
// there are more details you need to know about:
// - the device/OS
// - what is the difference between the native swipe on iOS and Android
// Our advice is to use the methods as described above, but if you want to use the native swipe, please check the official driver docs
//
// it('should be able to swipe the native way', async () => {
// /**
// * To understand what happens in `isCardActive()` please check the method
// */
// await expect(await Carousel.isCardActive(await Carousel.openSourceCard)).toBeTruthy();
// if (driver.isAndroid){
// // Src: https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/android-mobile-gestures.md#mobile-swipegesture
// await driver.execute('mobile: swipeGesture', {
// direction: DIRECTIONS.LEFT,
// // The elementId is not mandatory, you can also swipe based on top, right, bottom, left coordinates.
// // Using coordinates will make it a little bit more complex because you need to calculate the coordinates of the element
// // you want to use to swipe withing.
// // On the other hand, using the elementId will make it easier to swipe, but you need to make sure that the device
// // you are using does not have left or right actions on for example the edge of the screen which would trigger those actions.
// elementId: (await Carousel.carousel).elementId,
// percent: 0.5,
// // Speeds it optional, but if you want to use it, you need to multiply the speed with the displayDensity of the device.
// // speed: {number} * displayDensity
// });
// } else {
// // Src: https://appium.github.io/appium-xcuitest-driver/5.12/execute-methods/#mobile-swipe
// await driver.execute('mobile: swipe', {
// direction: DIRECTIONS.LEFT,
// elementId: (await Carousel.carousel).elementId,
// // The velocity is not mandatory, it is measured in pixels per second and same values could behave differently
// // on different devices depending on their display density.
// velocity: 250,
// });
// }
// // For demo purposes
// await driver.pause(3000);
// });
});