Showing posts with label SoapUI. Show all posts
Showing posts with label SoapUI. Show all posts

Monday, November 3, 2014

Set Authentication WebService and Set Authentication Cookies in SoapUi

After development step, we need to test the Web Services. Using SoapUi, we can give the generated WSDL address and get all the exposed WebMethods.

I developed an application where authentication is needed. So the called method is authenticate which will generate a JSessionId (Cookie) :


@Resource 
private WebServiceContext wsContext;

 
@WebMethod
public User authenticate(@WebParam(name = "userName") String userName, @WebParam(name = "password") String password){
   
 User userToconnect = null;

 HttpServletRequest req = (HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);

 userToconnect = webService.authenticate(userName, password);
  
 req.getSession().setAttribute("User", userToconnect);
    
 return userToconnect;  
}

In next method, we will need to get the user. This one will no more be sent by the authenticated user, but it will be retrieved directly from the WebServiceContext.


public User getUser(WebServiceContext wsContext) throws Exception{

 User user = getUserFromSession(wsContext);
 if(user== null){
  throw new  Exception("User not Authenticated ", UamErrorCode.INVALID_PARAMETER);
 }
 return user.getEnterpriseName();
}


Calling the authenticate method using SoapUi, we will get a Set-Cookie in the header.



Then, in next call, user need to specify the given JsessionId. So the Authentication Cookies should be specified in SoapUi for next requests. This can be done using headers. Clic on add, Copy the JSeesionId generated by the autehnticate (copy all the row, paste, then remove the Set-Cookie). Then create a Header called Cookie, and Set the JSESSIONID.



Thant's all, now your method will work.

Don't forget to share with friends ...

Wednesday, September 17, 2014

Test Automation Tutorial : Test your Software using SoapUi and Create a Test Case

Hello everybody. Today I will show you some tips on using SoapUI to test your software.

I have developed an application based on Web Services, so in order to test that, I use SoapUI which is a nice tool to test the web services by giving the WSDL location or address.

So Lets start.

Step 1 : Open Project

You need to create your project either by giving the WSDL address or the path to your WSDL located locally in your laptop.



Step2 : Create you testSuite.


You can create a test case by cright clic on the project and create test case. 

Or you can clic directly on the desired request and add to TestCase.

Then you create a new one or you add it to an existing one.


 The Request is then added to the TestCase. You can add multiple ones and fill the parameters then run the test. In order to make sure that you are the desired behavior see step3.


Step 3: Add Assertions to your Test Suite


For the first time, running my test Suite, I was happy that everything is all right. Yeeeh I thought that my code is super but I have seen after that it is every time green even if I am waiting an exception. In fact, SoapUI consider that your test is OK when you receive a response independently on the request type.
Hopefully, there is a solution to fix that. It is by adding ASSERTIONS to your requests. Many assertions types are available, but here I use
-  Fault SOAP : I know that my response is NOT OK and I would like that my Test Suite don't stops at that levl.
- NOT Fault Soap: Here, I suppose that the response shouldn't be an error or exception, If so  my test fails and stops at that step.
- Contains: The returned result should contain some characters.

So here how to add ASSERTIONS:

Clic on the Request. The little botton on top (or The is also "Assertion down the request page") is the one to use in order to add assertions.



Many assertions are available and you can choose what fits to your case. For me I need mostly the NOT SOAP Fault, But SLA is also very good to choose a timeout for your resquest.


You can see down the added assertions :


So once you have added a NOT SOAP FAULT ASSERTION to your test case, if you receive an error and hence a soap:fault, your test you fail (RED) and you will know that something is wrong.


Step 4: Add Delay between too Steps


Executing the test Case, sometime we need to have some delay before executing the next step to make sure that the changes are commited in Data Base. So I was searching for how to add Delay before a request in the test Case.
This is possible by adding a special Step which is Delay.

So right clic on the Test Case -> Add Step -> Delay





Once the Delay Step created, change the desired millisecond and put the Delay Step before the request that you need to delay.



Step 5 : Export Test Case and use it in another project.


Deploying my application on a remote server, my logs was not yet working (need to fix it  ;) ). So  I needed to execute the same testSuite on my Local Server. I was able to re-create the same test case, but SoapUI gives us the possibility to export only a testCase and use it in another project.


So clic on the Second project and import that Test Suite:


Hope that you enjoyed the small tutorial :).

Articles les plus consultés