11import { remote } from 'webdriverio' ;
2- import { API_DEMOS_APK_PATH as apidemosApp } from 'android-apidemos' ;
32import { expect } from 'chai' ;
43
54const APPIUM_HOST = '127.0.0.1' ;
@@ -14,7 +13,7 @@ const WDIO_PARAMS = {
1413const 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} ;
2019let 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