Reminder:
Currently we have our main test file containing the actual test.
What if we want to create another test using the same locator? What if we want to use the same test but search for something else?
These can all be done in robot, so let's begin:
Assuming you have followed the previous blog post, we should have 2 unused text files - one for keywords and the other is a repository. If you don't have them, create them now (use the directory as your main tests just for simplicity)
Our main code looks something like this
What if we want to create another test using the same locator? What if we want to use the same test but search for something else?
These can all be done in robot, so let's begin:
Assuming you have followed the previous blog post, we should have 2 unused text files - one for keywords and the other is a repository. If you don't have them, create them now (use the directory as your main tests just for simplicity)
Our main code looks something like this
*** Test Cases ***
Performing a basic google search
Open browser http://www.google.com browser=chrome
Input Text "wikipedia" id=gbqfq
Click Button id=gbqfba
Page Should Contain id=resultStats
Performing a basic google search
Open browser http://www.google.com browser=chrome
Input Text "wikipedia" id=gbqfq
Click Button id=gbqfba
Page Should Contain id=resultStats
Improving what we have.
Taking it line by line:
With this information we can begin enhancing, let's start with search:
Within the repository file we want to store our variables here, it should look like this
- We are always opening chrome to Google, there is no need to change this
- We want to vary the text going into the search field
- We always want to click the search button after the field is filled
- We don't really need to change how we validate the page but we could.
With this information we can begin enhancing, let's start with search:
- Store the id=gbqfq as a variable
- create a keyword that takes a string and performs the search
Within the repository file we want to store our variables here, it should look like this
*** Variables ***
${search_field} id=gbqfq
${search_button} id=gbqfba
${search_field} id=gbqfq
${search_button} id=gbqfba
Within your Keywords file you will need to write the search part
*** Keywords *** Perform Search [Arguments] ${search_text} Input Text ${search_text} ${search_field} Click Button ${search_button} | This is the name of the keyword being created You require to pass in different strings into this keyword the search text is used when the keyword is called we put the click button here as it occurs every test |
With this we can now edit the main test file to include our new keyword
*** Test Cases *** Performing a basic google search Open browser http://www.google.com browser=chrome Perform Search "thing we want to search" Page Should Contain id=resultStats | Pass in 1 string as argument to the keyword we created |
We can still improve this further by moving the Page Should Contain within our keyword, and then use the same variable passed in to perform a search to validate our page!
Understanding what we did.
The whole idea to automation is removing the 'manual data input' aspect of testing - we all hate it, it's pointless but very necessary. Imagine a form you have to fill with contact details - a keyword driven test can easily be converted into a data driven test very easily. By passing in different variables, you are able to use the same line of code but increase your coverage dramatically.
Things to do.
I cannot emphasise how important it is to keep on writing tests. You will discover clever things with RIDE and you will find the line of manual/automation combined. (spoiler: one will never replace the other)
In my next and probably last blog post of this beginner series: I will data drive the above test to perform various searches and provide screenshots.
In my next and probably last blog post of this beginner series: I will data drive the above test to perform various searches and provide screenshots.