Forum Discussion

Fox87's avatar
Fox87
New Contributor
8 years ago

How can I run a test containing oAuth without manual input?

I have a GET request, and I have added some automation code in the Auth window (login with other service - added user, password and clicked on the sign in button), in order to be able to get the token.

If I open the project and click on run I kind of expected to have the automation code executed with the token generated and used in the get request. But for my case it is not working. I have to manually open the Auth tab, go to Automation, run the code and the token will be generated. After that I can run the test suite.

 

How can I remove these steps that I'm doing manually in order to have everything automated?

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Would you mind showing the script which you say automation code?
    • Fox87's avatar
      Fox87
      New Contributor

      Sure Rao,

       

      Just to be clear the steps I used for oAuth are as follows:

      1. For the REST request step I click on the Auth tab (where I have created and added a new authorization)

      2. Click on get token

      3. Set the details for the client identification, authorization  URI, Redirect URI

      4. Click on the Automation tab

      5. Write the code:


      if (document.getElementById("Email")) {
      document.getElementById("Email").value = "xxxx@gmail.com";
      document.getElementById("next").click();

       

      setTimeout(function()
      {

      if (document.getElementById("Passwd")) {
      document.getElementById("Passwd").value = "password";
      document.getElementById("signIn").click();
      }
      }, 1000);
      }

       

      6. Run the code: It works as expected and the login window is opened, the credentials added and clicks on the sign in button

      7. The token is generated and can be used in the request

       

      Now my problem:

      If I send the request now everything works as expected (because I have the token) but if I delete the token and send the request without running the code within the Automation window (to retrieve the token), it fails.

       

      Have you ever had this issue? Were you able to make it work without the need to run the automation code manually before sending the request?

       

      Thanks