Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set response body and apply it to UI, selenium driver #8

Closed
mdpl2426 opened this issue May 11, 2020 · 7 comments
Closed

Unable to set response body and apply it to UI, selenium driver #8

mdpl2426 opened this issue May 11, 2020 · 7 comments

Comments

@mdpl2426
Copy link

Hi, I am using selenium framework for web application, completed mitm setup, able to get calls and trying to edit the response body using setBody() but not getting the correct response message on the web application after changed the body(getting a common issue screen for all error JSON bodies). Able to edit the response code using setStatusCode(). Can anyone please help me to edit the response body so that it should show correct message on the UI, or if can we add setHeaders also to achieve this then how to use setHeaders()

@mdpl2426
Copy link
Author

@Jonahss It will be very helpful if you suggest anything and can we print the response body in JSON format?

@Jonahss
Copy link
Member

Jonahss commented May 12, 2020

I think the body of the response is just a byte array. So if you want to have that as JSON, find a library to convert a byte array to JSON.

It sounds like you're getting an error screen because the body you are setting is not valid JSON?
Make sure you are setting the body to a JSON string, like {"foo": "bar"}.

I suggest using your browser developer tools to inspect the body of the response you are getting back. Make sure it is valid JSON.

sure you can add setHeaders(). I think you can just do that by adding the right annotation to this file: https://github.com/appium/mitmproxy-java/blob/master/src/main/java/io/appium/mitmproxy/InterceptedMessage.java#L37

@mdpl2426
Copy link
Author

mdpl2426 commented May 13, 2020

@Jonahss : Thank you for your reply!, yes I converted byte array to JSON and printed, it is the correct JSON.
Manually I am able to see correct UI screen by changing response code and response body through Charlesproxy. The same way I am trying in mitmproxy-java, using setStatusCode and setBody. After setBody validated the JSON, it is correct. But not getting the expected message on the UI.

@Jonahss
Copy link
Member

Jonahss commented May 13, 2020

So what is the difference between the packets returned by charlesproxy and the packet returned by mitmproxy-java?

@mdpl2426
Copy link
Author

@Jonahss I figured out the issue, Actually I was mocking OPTIONS call instead of GET call. Now its working fine and able to see expected screen on UI. Thank you for your support!
Now is there any way to integrate enterprise jenkins with mitm for bulk run and reporting?

@Jonahss
Copy link
Member

Jonahss commented May 27, 2020

Great! Glad you were able to figure it out. Debugging this sort of thing is very difficult.

I'm not sure about enterprise jenkins, but there should be a way. You might have to create a custom plugin or something.

@Jonahss Jonahss closed this as completed May 27, 2020
@jorgemoma
Copy link

Hi @mdpl2426,

I'm having the same issue intercepting and rewriting the responseBody but not seeing the change in the UI. Currently using Appium & Selenium

How did you changed mocking OPTIONS call instead of GET call ?

@Jonahss this is also related to this open issue : #17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants