AppiumTestDistribution / appium-interceptor-plugin

Appium 2.0 plugin to mock api calls for android apps
27 stars 11 forks source link

Need help to get payload from POST request #39

Open thanggggg1 opened 1 month ago

thanggggg1 commented 1 month ago

I dont know how to get payload from POST request before update it

sudharsan-selvaraj commented 1 month ago

@thanggggg1 Could you please explain the specific use case you're aiming to achieve so that we can provide more precise guidance?

thanggggg1 commented 1 month ago

@sudharsan-selvaraj i used addMock to block the request like this

const blockRequest = async (urlPattern) => { const mockId = await driver.execute('interceptor: addMock', { config: { url: urlPattern, statusCode: 403, // Block by returning 403 Forbidden responseBody: JSON.stringify({ message: 'Request blocked by interceptor', }), }, }); return mockId; };

but i want to get the original requestBody before block, can you show me how. Thank you so much

sudharsan-selvaraj commented 1 month ago

@thanggggg1 You can try below methods to get the API details

  await driver.execute("interceptor: startListening");
  await blockRequest();
  // perform some action
  // ...
  const apiRequests = await driver.execute("interceptor: stopListening");
  console.log(apiRequests) // This will have all the API calls made from the app with the actual response
thanggggg1 commented 1 month ago

Thank you @sudharsan-selvaraj , i will try

thanggggg1 commented 1 month ago

@sudharsan-selvaraj , i can not excecute when set up proxy

const capabilities = {
    platformName: 'Android',
    'appium:automationName': 'UiAutomator2',
    'appium:deviceName': 'emulator-5554',
    'appium:browserName': 'Chrome',
    'appium:intercept': true,
    'goog:chromeOptions': {
        args: [
            `--proxy-server=${proxy_host}`,  // Your public proxy
            '--ignore-certificate-errors'
        ]
    }
};

Do you know how to fix this