Skip to content

Commit 003b7ea

Browse files
Ci (#5)
* added e2e test
1 parent abc4ec3 commit 003b7ea

3 files changed

Lines changed: 124 additions & 52 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/utils/proxy.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,26 @@ export function addDefaultMocks(proxy: Proxy) {
169169
],
170170
});
171171

172-
proxy.addMock({
173-
// url: '**/api/users*?*',
174-
url: '/api/users?.*',
175-
updateUrl: [
176-
{
177-
regexp: '/page=(\\d)+/g',
178-
value: 'page=2',
179-
},
180-
],
181-
updateResponseBody: [
182-
{
183-
jsonPath: '$.data[?(/michael.*/.test(@.email))].first_name',
184-
value: 'sudharsan',
185-
},
186-
{
187-
jsonPath: '$.data[?(/michael.*/.test(@.email))].last_name',
188-
value: 'selvaraj',
189-
},
190-
],
191-
});
172+
// proxy.addMock({
173+
// // url: '**/api/users*?*',
174+
// // url: '/api/users?.*',
175+
// // updateUrl: [
176+
// // {
177+
// // regexp: '/page=(\\d)+/g',
178+
// // value: 'page=2',
179+
// // },
180+
// // ],
181+
// // updateResponseBody: [
182+
// // {
183+
// // jsonPath: '$.data[?(/michael.*/.test(@.email))].first_name',
184+
// // value: 'sudharsan',
185+
// // },
186+
// // {
187+
// // jsonPath: '$.data[?(/michael.*/.test(@.email))].last_name',
188+
// // value: 'selvaraj',
189+
// // },
190+
// // ],
191+
// });
192192

193193
proxy.addMock({
194194
url: '/appiumproxy.io/g',
@@ -306,6 +306,7 @@ export function sanitizeMockConfig(config: MockConfig) {
306306
].forEach((regexNodePath) => {
307307
const regexElement = jsonpath.query(config, regexNodePath);
308308
return regexElement.forEach((ele) => {
309+
console.log('00000', ele)
309310
const isValidRegExp = typeof ele === 'string' && !(parseRegex(ele) instanceof RegExp);
310311
if (!isValidRegExp) {
311312
throw new Error(`Invalid Regular expression ${ele} for field ${regexNodePath}`);

test/plugin.spec.js

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { remote } from 'webdriverio';
2-
import { API_DEMOS_APK_PATH as apidemosApp } from 'android-apidemos';
32
import { expect } from 'chai';
43

54
const APPIUM_HOST = '127.0.0.1';
@@ -14,7 +13,7 @@ const WDIO_PARAMS = {
1413
const capabilities = {
1514
platformName: 'Android',
1615
'appium:automationName': 'UIAutomator2',
17-
'appium:app': apidemosApp,
16+
'appium:app': './assets/test_app_mitm_proxy.apk',
1817
'appium:intercept': true,
1918
};
2019
let driver;
@@ -23,14 +22,112 @@ describe('Plugin Test', () => {
2322
driver = await remote({ ...WDIO_PARAMS, capabilities });
2423
});
2524

26-
it('Vertical swipe test', async () => {
25+
it('Should be able to mock entire response body', async () => {
2726
const mockId = await driver.execute('interceptor: addMock', {
2827
config: {
29-
url: 'https://jsonplaceholder.typicode.com/todos/1',
28+
url: '/api/users?.*',
29+
responseBody:
30+
JSON.stringify({
31+
page: 1,
32+
per_page: 6,
33+
total: 12,
34+
total_pages: 2,
35+
data: [
36+
{
37+
id: 1,
38+
email: 'saikrishna.bluth@reqres.in',
39+
first_name: 'George',
40+
last_name: 'Bluth',
41+
avatar: 'https://reqres.in/img/faces/1-image.jpg',
42+
},
43+
{
44+
id: 2,
45+
email: 'janet.weaver@reqres.in',
46+
first_name: 'Janet',
47+
last_name: 'Weaver',
48+
avatar: 'https://reqres.in/img/faces/2-image.jpg',
49+
},
50+
{
51+
id: 3,
52+
email: 'emma.wong@reqres.in',
53+
first_name: 'Emma',
54+
last_name: 'Wong',
55+
avatar: 'https://reqres.in/img/faces/3-image.jpg',
56+
},
57+
{
58+
id: 4,
59+
email: 'eve.holt@reqres.in',
60+
first_name: 'Eve',
61+
last_name: 'Holt',
62+
avatar: 'https://reqres.in/img/faces/4-image.jpg',
63+
},
64+
{
65+
id: 5,
66+
email: 'charles.morris@reqres.in',
67+
first_name: 'Charles',
68+
last_name: 'Morris',
69+
avatar: 'https://reqres.in/img/faces/5-image.jpg',
70+
},
71+
{
72+
id: 6,
73+
email: 'tracey.ramos@reqres.in',
74+
first_name: 'Tracey',
75+
last_name: 'Ramos',
76+
avatar: 'https://reqres.in/img/faces/6-image.jpg',
77+
},
78+
],
79+
support: {
80+
url: 'https://reqres.in/#support-heading',
81+
text: 'To keep ReqRes free, contributions towards server costs are appreciated!',
82+
},
83+
}),
3084
},
31-
})
32-
expect(mockId).to.not.be.null
85+
});
86+
expect(mockId).to.not.be.null;
87+
const el1 = await driver.$("xpath://android.widget.TextView[@text=\"Get User List\"]");
88+
await el1.click();
89+
const page = await driver.getPageSource();
90+
expect(page.includes('saikrishna.bluth@reqres.in')).to.be.true;
3391
});
92+
93+
it('Should be able to mock partial response body', async () => {
94+
const mockId = await driver.execute('interceptor: addMock', {
95+
config: {
96+
url: '/api/users?.*',
97+
updateResponseBody: [
98+
{
99+
jsonPath: '$.data[?(/tracey.*/.test(@.email))].first_name',
100+
value: 'sudharsan',
101+
},
102+
{
103+
jsonPath: '$.data[?(/tracey.*/.test(@.email))].last_name',
104+
value: 'selvaraj',
105+
},
106+
],
107+
},
108+
});
109+
expect(mockId).to.not.be.null;
110+
const el1 = await driver.$("xpath://android.widget.TextView[@text=\"Get User List\"]");
111+
await el1.click();
112+
const page = await driver.getPageSource();
113+
expect(page.includes('sudharsan')).to.be.true;
114+
expect(page.includes('selvaraj')).to.be.true;
115+
});
116+
117+
it('Should be able to mock status code', async () => {
118+
const mockId = await driver.execute('interceptor: addMock', {
119+
config: {
120+
url: '/api/users?.*',
121+
statusCode: 400
122+
},
123+
});
124+
expect(mockId).to.not.be.null;
125+
const el1 = await driver.$("xpath://android.widget.TextView[@text=\"Get User List\"]");
126+
await el1.click();
127+
const page = await driver.getPageSource();
128+
expect(page.includes('Error')).to.be.true;
129+
});
130+
34131
afterEach(async () => {
35132
await driver.deleteSession();
36133
});

0 commit comments

Comments
 (0)