Scenario: Verify if a customer is able to pay his credit card bill.
The Flow as follows:
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:
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.
Token
.def Token = (testRunner.testCase.getPropertyValue("Token")) Token.sendKeys(TOKEN);
assert
command.We need to follow three steps to achieve this:
getText()
; at the end of the locator and pass the value in a variable.assert
command to validate if the value in the variable matches the expected value or not.3.144.114.85