Forum Discussion

fgvieira's avatar
fgvieira
Contributor
7 years ago
Solved

Login/logout testcase

Hello,

 

I'm new to soapUI and after reading some documentation and check some tutorials on youtube not being able to do something. I wanna do a login test to a website, what I mean is I wanna check out if with some credentials I can acess the site and then verify if login was succeeded or not. 

 

If that was not clear, please let me know. Really would like some help.

 

Thank you in advance.

  • It sounds like you want to do what a browser would do when a user enters login details on a website.

     

    Doing a login on a webpage form isn't the same thing as invoking a RESTful webservice - but there are a lot of similarities. REST isn't actually a protocol - it's more about ideas for how to design a webservice. The underlying protocol is just HTTP. So since SoapUI uses HTTP for REST test steps, in theory you should be able to test the same actions that a browser takes pretty easily using REST test steps, though it could depend on what technologies the website is using. The sending of passwords is rarely is simple as I'm going to explain here. (This is one reason that people have been asking you for specific information about the website you are trying to log into - you don't need to name it but we need to know how it works).

     

    The other possibility is that you're trying to use a REST service, and not a website. In that case you either need somebody to tell you the parameters to put on your request (and whether they go in the URI, in the body, in the headers etc), or you can load a WADL. If you load a proper WADL, SoapUI should be able to generate some test requests with default parameters that you can just update. (Just because you added a URI to your SoapUI project, that doesn't mean you successfully loaded a WADL).

     

    The super basic approach to logging in to a web page:

     

    First get hold of the login page source markup. You could do this just by pointing your favourite browser at the login page and finding a View Source button. Or you can do it in SoapUI as a REST Request to the same address with the method set to GET.

     

    You'll end up with some HTML. Depending on the site it might not be very human readable, but you'll need to look for a form tag. Here's an example one that I stole from here: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_post

     

    <form action="/action_page.php" target="_blank" method="POST">
      First name:<br>
      <input type="text" name="username">
      <br>
      Last name:<br>
      <input type="text" name="password">
      <br><br>
      <input type="submit" value="Submit">
    </form>

    Based on the above form, the next step would be to create a new REST request with the resource set to /action_page.php and the method set to POST. You would add parameters "username" and "password" and enter your values there. Then enable the option to Post QueryString.

     

    The response you get will be another HTML. You can look it over yourself to see if it indicates the login was successful, and maybe that's enough for you. Or if you'd like SoapUI to give it a pass or fail each time you run it, you can add an assertion (something like Contains: "Welcome, fgvieria"?)

     

32 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Are you test Web Services or rest services?
      • nmrao's avatar
        nmrao
        Champion Level 3
        Do you have wsdl file with you to get started?
  • Hey,

     

    Yes, that's it. I want to be able to check if the login was sucessfull.

    • avidCoder's avatar
      avidCoder
      Super Contributor

      Ok, for this then, you should have proper WADL file.. Like for example, I am giving you the link for the football team details WSDL :- Football WSDL .. If you import this in SOAP UI Pro. You will get the request there.. So, based on the requirement you need pass the data from the SOAP request and you will get the details in response tab.

       

      If you have WADL link.  you can provide here.. I will look into this.

      • fgvieira's avatar
        fgvieira
        Contributor

        Was looking into this file, it doesn't have any authentication, does it?

  • JHunt's avatar
    JHunt
    Community Hero

    It sounds like you want to do what a browser would do when a user enters login details on a website.

     

    Doing a login on a webpage form isn't the same thing as invoking a RESTful webservice - but there are a lot of similarities. REST isn't actually a protocol - it's more about ideas for how to design a webservice. The underlying protocol is just HTTP. So since SoapUI uses HTTP for REST test steps, in theory you should be able to test the same actions that a browser takes pretty easily using REST test steps, though it could depend on what technologies the website is using. The sending of passwords is rarely is simple as I'm going to explain here. (This is one reason that people have been asking you for specific information about the website you are trying to log into - you don't need to name it but we need to know how it works).

     

    The other possibility is that you're trying to use a REST service, and not a website. In that case you either need somebody to tell you the parameters to put on your request (and whether they go in the URI, in the body, in the headers etc), or you can load a WADL. If you load a proper WADL, SoapUI should be able to generate some test requests with default parameters that you can just update. (Just because you added a URI to your SoapUI project, that doesn't mean you successfully loaded a WADL).

     

    The super basic approach to logging in to a web page:

     

    First get hold of the login page source markup. You could do this just by pointing your favourite browser at the login page and finding a View Source button. Or you can do it in SoapUI as a REST Request to the same address with the method set to GET.

     

    You'll end up with some HTML. Depending on the site it might not be very human readable, but you'll need to look for a form tag. Here's an example one that I stole from here: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_post

     

    <form action="/action_page.php" target="_blank" method="POST">
      First name:<br>
      <input type="text" name="username">
      <br>
      Last name:<br>
      <input type="text" name="password">
      <br><br>
      <input type="submit" value="Submit">
    </form>

    Based on the above form, the next step would be to create a new REST request with the resource set to /action_page.php and the method set to POST. You would add parameters "username" and "password" and enter your values there. Then enable the option to Post QueryString.

     

    The response you get will be another HTML. You can look it over yourself to see if it indicates the login was successful, and maybe that's enough for you. Or if you'd like SoapUI to give it a pass or fail each time you run it, you can add an assertion (something like Contains: "Welcome, fgvieria"?)

     

    • fgvieira's avatar
      fgvieira
      Contributor

      Hello,

       

      Thanks for your extensive response, I kinda got it but no being able to get it to work.

       

      That last REST Request I will do, it's got a be a new URI endpoint? My form action gives me a brand new URI.

    • fgvieira's avatar
      fgvieira
      Contributor

      Yeah, meanwhile I got the resource. At this moment, I think it's some trouble with website I'm trying to test. I can get the form action like you said, and put it on the POST method but gaves an error of the website itself. 

       

      Don't you have any website I can test this on? Thanks :) 

  • JHunt's avatar
    JHunt
    Community Hero

    In your SoapUI Tutorials folder (defauilt is in your user directory), there is an Sample REST Project that does exactly this against a mock service.

     

     

    <html>
       <head>
          <meta content="HTML Tidy for Java (vers. 27 Sep 2004), see www.w3.org" name="generator"/>
          <meta charset="utf-8"/>
          <title>Account registration</title>
          <meta content="SoapUI Sample content" name="description"/>
       </head>
       <body>
          <h1>Welcome!</h1>
          <form name="account_registration_form" method="post" action="accountcreation">
             <input placeholder="John Doe" name="username" type="text"/>
             <input name="password" type="password"/>
             <input name="password" type="submit"/>
          </form>
       </body>
    </html>
    POST http://localhost:8080/accountcreation HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 25
    Host: localhost:8080
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
    
    username=abc&password=def
    <html>
    	<head>
    		<meta charset="utf-8"/>
    		<title>Account registration</title>
    		<meta name="description" content="SoapUI Sample content"/>
    	</head>
    
    	<body>
      		<h1>Welcome!</h1>
      		<p>You have successfully registered your account!</p>
    	</body>
    </html>

     

    • fgvieira's avatar
      fgvieira
      Contributor

      Yes, this works out :) I already have seen this, but thanks anyway.

       

      I got to the problem, when I mark 'post as query string' it gives an error saying I should login again before I even put username and password. Any ideas?

  • JHunt's avatar
    JHunt
    Community Hero

    Too many possibilities. Please give some specifics about what you're doing.

    • fgvieira's avatar
      fgvieira
      Contributor

      I did what you. The GET to the URI, got the form action and put it on a resource which has a POST Request to the new resource. Put the username and the password I wanted, and did this as 'post as query string'. So far so good.

       

      When I run it, it gives an error. My website is web application that presents a login page, to put login and password. Then it redirects for another page where I can see a lot of features. 

       

      Maybe when I do the POST I have to give him the redirect URI?

      • fgvieira's avatar
        fgvieira
        Contributor

        I'm editing this message, I already can post the username and the password in the html fields. But it doesn't do anything, statys static with the username and the password done. Any quick resolution? Maybe my URI is wrong? 

  • JHunt's avatar
    JHunt
    Community Hero

    At this point if you're comfortable to do the steps in SoapUI, but you're still getting an error and you can't be more specific about that, it might be best if you contact the developer of the website for help.

    • fgvieira's avatar
      fgvieira
      Contributor

      Yes, I will do that, if I have any more question I'll post it here. Really thankful for your kind help. Thank you mate.

  • Finally got it to work, with some tricks but with the answer I marked as solution did the job. Thank you a lot for your help, if someone needs addition help on login into a web application and I can help I'd be happy to.