There is a bank service that provides API to do some operations with bank accounts. To perform a request to all endpoints of this service I, first of all, need to get auth token via grand_type=auth_code; I can easily get the auth code and then access token manually. When browser redirects me to bank auth page I just enter my credentials and then It redirects me to my predefined URL with auth_code.

But I need to write unit tests for my implementation of this API. And how can I perform this process with entering credentials and send request from the page programmatically to get auth code?


You can try to use Selenium WebDriver to automate the flow.

I recently did exactly that - automated integration tests calling bank API protected by OAuth and it took me only few hours to get it to work.

Basically You run a real browser and drive interaction with web page from Java code replicating manual interaction.

| improve this answer | |
  • How do we get the token through browser? I am able to get the authorization code but I couldn't find access token in browser. Will appreciate if you can provide insight. – sohail Jun 22 at 20:48
  • @sohail when you have authorization code you simply send it to the /token endpoint to retrieve the token. You do not need browser for it only a HTTP client that can send post requests. – AGrzes Jun 23 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.