Implementing a real world test case using SoapUI and Selenium together

Scenario: Verify if a customer is able to pay his credit card bill.

The Flow as follows:

  1. User logs in.
  2. User enters details on the UI page and clicks Submit; a unique ID is generated and shown on the UI with status: in Progress, and asks for a token to process the payment.
  3. Service A is called and the request of service A needs the unique ID generated to be passed in the request.
  4. Service B is called.
  5. Service C creates the new token.
  6. The user needs the token created by service C to complete the transaction as he needs to enter it in the UI.
  7. The user enters the token and clicks on the Submit button.
  8. The user receives a message payment is done.

So in the previous example we have eight steps, five of the steps are from the UI and three are from the services side. We also see that there is a need to transfer data from the UI to the service request and vice versa.

Now let's assume we need to assert certain UI elements on the screen as well. Now let's map each of the steps.

We would need Selenium invocation and assertion on the UI level, so how do we do that?

We need to find the locator of the element and then assert it.

We have different ways to find a UI element in Selenium, we can use any of the following or whichever suits us the best:

  • Identifier
  • Id
  • Name
  • Link
  • DOM
  • XPath
  • CSS
  • UI-element

Once we get to an element we can always use assert to validate the content on the UI screen.

Now we know how to assert but how do we enter data in the fields?

For that we use the sendKeys command. Below is an example which will help us understand this better. We should also note that XPath will remain the same for all browsers.

WebElement LoginName = driver.findElement(By.xpath("//*[@id='loginname']"));
    LoginName.click();
    LoginName.sendKeys("admin");

  WebElement Password = driver.findElement(By.xpath("//*[@id='passwd']"));
    Password.click();
    Password.sendKeys("admin");

  WebElement Login = driver.findElement(By.xpath("//*[@id='loginBtn']"));
    Login.click();
  WebElement Cardno = driver.findElement(By.xpath("//*[@id='Credit card Number']"));
    Cardno.click();
    Cardno.sendKeys("1098987654");
This way we can enter data in any field on the UI page. Once we have logged into the application and submitted our card details on the screen, we need to click on the Submit button:
WebElement SUBMIT= driver.findElement(By.xpath("//*[@id='SBTBtn']"));
    SUBMIT.click();

As per our scenario, we will receive a unique number in the UI. Let's name it UID.

Now we need to fetch the UID and pass it to the properties file so that we can re-utilize it in the next step which is a test request.

Here is sample code on how to achieve it:

def  UID = driver.findElement(By.xpath("//*[@Name='UniqueID']")).get text();
testRunner.testCase.setPropertyValue("UID",UID.toString());

Now you can use this UID throughout your test case. Once this is done, we can parameterize our test request and run it. This will complete step 3 of our scenario.

  1. We need to run a service request; we can do that easily using SoapUI.
  2. We again need to run the service but we need to save the response in the properties of SoapUI which can be done with Groovy script or property transfer with the help of XPath as we have learnt in the previous chapters. We will save the property name as Token.
  3. Now we will return to the browser and get the property details from the SoapUI properties and enter the details in the token field. See the following sample code:
    def Token = (testRunner.testCase.getPropertyValue("Token"))
       Token.sendKeys(TOKEN);
  4. Now the user will need to click on the Submit button.
  5. Once the Submit button is clicked on, we need to validate whether the flow was successful or not. This can be achieved using the assert command.

We need to follow three steps to achieve this:

  1. Get the Locator to the text where success or failure appears.
  2. Use getText(); at the end of the locator and pass the value in a variable.
  3. Use the assert command to validate if the value in the variable matches the expected value or not.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.114.85