AppiumTestDistribution / appium-interceptor-plugin

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

Error(Android): Invalid agrument: Did not receive an appropriate execute method parameters object. It needs to be deserializable as a plain JS object #30

Closed ygarg465 closed 5 months ago

ygarg465 commented 5 months ago

Describe the issue Mocking request using below code

await driver.execute("interceptor: addMock", [
      {
        config: {
          url: "https://domain/sms/sendOTP",
          method: "POST",
          responseBody: JSON.stringify({
            success: true,
            message: "OTP sent successfully",
          }),
        },
      },
    ]);

results in this error on Appium server logs invalid argument: Did not receive an appropriate execute method parameters object. It needs to be deserializable as a plain JS object

This also happens if we pass an empty object or the example code in the commands sections

 const authorizationMock = await driver.execute("interceptor: addMock", [{
    config: {
        url: "**/reqres.in/**",
        headers: {
            "Authorization" : "Bearer bearertoken"
        }
    }
 }]);

Device Information OS: Android Version: API 34 (Android 14) Device: Pixel 7 Pro

ygarg465 commented 5 months ago

Hey @sudharsan-selvaraj, did you look at this issue? Because it's a blocker for me to move forward.

sudharsan-selvaraj commented 5 months ago

@ygarg465 Are you using webdriver.io on the client side?

ygarg465 commented 5 months ago

@sudharsan-selvaraj Actually yes

sudharsan-selvaraj commented 5 months ago

@ygarg465 Could you please try with the below syntax?

await driver.execute("interceptor: addMock",  {
        config: {
          url: "https://domain/sms/sendOTP",
          method: "POST",
          responseBody: JSON.stringify({
            success: true,
            message: "OTP sent successfully",
          }),
        },
      });
ygarg465 commented 5 months ago

@sudharsan-selvaraj Yes this syntax resolves the above issue. Was this due to WebDriver ? If Yes we can update the docs to add this usecase as well.

However now I am getting this error in logcat when the request is sent from the app.

 [ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -202

  Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
ygarg465 commented 5 months ago

@sudharsan-selvaraj Addtional context It's a hybrid application developed using CapacitorJS

ygarg465 commented 5 months ago

I should create a separate issue for that.