generated from AppiumTestDistribution/appium-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathplugin.spec.js
133 lines (128 loc) · 4.02 KB
/
plugin.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
import { remote } from 'webdriverio';
import { expect } from 'chai';
const APPIUM_HOST = '127.0.0.1';
const APPIUM_PORT = 4723;
const WDIO_PARAMS = {
connectionRetryCount: 0,
hostname: APPIUM_HOST,
port: APPIUM_PORT,
path: '/wd/hub/',
logLevel: 'info',
};
const capabilities = {
platformName: 'Android',
'appium:automationName': 'UIAutomator2',
'appium:app': './assets/test_app_mitm_proxy.apk',
'appium:intercept': true,
};
let driver;
describe('Plugin Test', () => {
beforeEach(async () => {
driver = await remote({ ...WDIO_PARAMS, capabilities });
});
it('Should be able to mock entire response body', async () => {
const mockId = await driver.execute('interceptor: addMock', {
config: {
url: '/api/users?.*',
responseBody: JSON.stringify({
page: 1,
per_page: 6,
total: 12,
total_pages: 2,
data: [
{
id: 1,
email: 'saikrishna.bluth@reqres.in',
first_name: 'George',
last_name: 'Bluth',
avatar: 'https://reqres.in/img/faces/1-image.jpg',
},
{
id: 2,
email: 'janet.weaver@reqres.in',
first_name: 'Janet',
last_name: 'Weaver',
avatar: 'https://reqres.in/img/faces/2-image.jpg',
},
{
id: 3,
email: 'emma.wong@reqres.in',
first_name: 'Emma',
last_name: 'Wong',
avatar: 'https://reqres.in/img/faces/3-image.jpg',
},
{
id: 4,
email: 'eve.holt@reqres.in',
first_name: 'Eve',
last_name: 'Holt',
avatar: 'https://reqres.in/img/faces/4-image.jpg',
},
{
id: 5,
email: 'charles.morris@reqres.in',
first_name: 'Charles',
last_name: 'Morris',
avatar: 'https://reqres.in/img/faces/5-image.jpg',
},
{
id: 6,
email: 'tracey.ramos@reqres.in',
first_name: 'Tracey',
last_name: 'Ramos',
avatar: 'https://reqres.in/img/faces/6-image.jpg',
},
],
support: {
url: 'https://reqres.in/#support-heading',
text: 'To keep ReqRes free, contributions towards server costs are appreciated!',
},
}),
},
});
expect(mockId).to.not.be.null;
const el1 = await driver.$('xpath://android.widget.TextView[@text="Get User List"]');
await el1.click();
const page = await driver.getPageSource();
expect(page.includes('saikrishna.bluth@reqres.in')).to.be.true;
});
it('Should be able to mock partial response body', async () => {
const mockId = await driver.execute('interceptor: addMock', {
config: {
url: '/api/users?.*',
updateResponseBody: [
{
jsonPath: '$.data[?(/tracey.*/.test(@.email))].first_name',
value: 'sudharsan',
},
{
jsonPath: '$.data[?(/tracey.*/.test(@.email))].last_name',
value: 'selvaraj',
},
],
},
});
expect(mockId).to.not.be.null;
const el1 = await driver.$('xpath://android.widget.TextView[@text="Get User List"]');
await el1.click();
const page = await driver.getPageSource();
expect(page.includes('sudharsan')).to.be.true;
expect(page.includes('selvaraj')).to.be.true;
});
it('Should be able to mock status code', async () => {
const mockId = await driver.execute('interceptor: addMock', {
config: {
url: '/api/users?.*',
statusCode: 400,
},
});
expect(mockId).to.not.be.null;
const el1 = await driver.$('xpath://android.widget.TextView[@text="Get User List"]');
await el1.click();
const page = await driver.getPageSource();
expect(page.includes('Error')).to.be.true;
});
afterEach(async () => {
await driver.deleteSession();
});
});