We can reduce the length of the code by creating a new resource file which includes the commonly used keywords of flight login functionalities.
Let us find the unique element in the flight application and write the test case for the same.
Open the ngendigital page and click on the Demo Application. You can see a login form, right-click on it and inspect the element.
Find the XPath for the email and password.
Xpath for Password
We have found the unique elements for email and password, Open the Ride editor and create a new test case as Flight Application.
Now, write the test case for the flight application
Now, select the test case and Run, once the test case starts executing, the ngendigital page will open and the email and password will be taken automatically and then closes the browser.
The Test Report is as shown below:
The Test case is having three steps that contain the email id, password and sign in, we can enhance these files by creating a new Resource file.
Let us create a new resource file as
And, creating a new use keyword as
Login to Flight application
Create new scalar variables for
commonlyusedkeywords by right-clicking on it and then open the test case and copy the input text lines and the Click element.
Now, paste it into the user keyword, instead of writing an actual username and password we can pass scalar variables as shown below.
We had created a user keyword that will be used in the flight application and hence we can use this user keyword just by importing the resource file in any of the test cases. In this way, we can reduce the length of the code. This process is known as keyword rewind functionality.
Now, add the Selenium library into the Commonlyusedkeywords, right-click on the commonlyusedkeywords and click on the library under import and enter the library name as SeleniumLibrary.
Now, import the Resource file into the Web Automation suite
And also, we need to import this resource file into the demo project
Once you import the resource file into the test case, the resource file will reflect inside the test suite, now open the test case and delete the input text and click element lines and insert a new keyword Login to flight application.
The Enhanced functionality test case is as shown below:
Once you run the test case and you will get the same output as before.