Granular Keyword Driven Testing
Keyword driven testing is a test automation approach where a tester designs his/her automated test using pre-coded keywords. When I take a quick look at the samples in web, I see that the keywords are supposed to be high level such as login, send email, check account balance etc.
What we are using in our company is what I can call as Granular Keyword Driven Testing. In this approach, keywords are designed to be more granular. So instead of a keyword like login, we use keywords like set test, click button etc.
Moreover, our keywords accept a user control’s visible property or label. For instance, if there is a textbox labeled “User”, our set text keyword accepts its label, such as set text(“User”, “John”).
So instead of implementing a single black-box keyword named “login”, we implement “set text” and “click button” keywords. Then the tester uses these granular keywords to implement his/her white box login method:
Keyword Parameters
----------- ---------------
Set text User, John
Set text Password, MyPasword123
Click button Login
Check text Hi John
The tester then uses this login method in his other keyword driven tests to implement other tests:
Keyword Parameters
----------- ---------------
Login John, MyPassword123
Click button Money Transfer
Set text Amount, 1000
Set text Receiver IBAN, TR032468706
Click button Send
Check text Money sent
These Granular Keywords should be implemented in such a way that they should be able to predict a user control’s XPATH from a given label. So the keyword set text can be implemented as (using a pseudo-code):
Keyword set_text(string label, string text)
{
Var xpath = "https://*[@text='"+label+"']/..//input"; //any input that is under the same parent with the given label object
Var textbox = findElementByXpath(xpath);
Textbox.setText(text);
}
One question can be what to do with objects that have no label or hint. A simple if added to the code above solves this:
Keyword set_text(string label, string text)
{
Var xpath = label; //assuming xpath is specified in the label parameter
if (!xpath.startsWith("https://"))
xpath = "https://*[@text='"+label+"']/..//input"; //any input that is under the same parent with the given label object
Var textbox = findElementByXpath(xpath);
Textbox.setText(text);
}
So the tester will be able to specify the actual xpath if the object has no visible label (or it is actually an image).
This simple approach can be used for granular keywords such as click button, check text etc.
An Alternative to Page Object Model?
Page Object model is used to define objects for elements on a page so that they can be managed from a single point in code. I'm sure it has better meanings and usages but lets keep it simple for now :D
Granular keywords seem to eliminate the need for Page Object approach. Granular keywords can be used on any page that uses the same relation (or hierarchy) between an object and its label. This is generally what happens in most of the applications: The same object hierarchy (a DIV containing both the label and the textbox for instance) is used in most of the pages.
If there is a specific object which does not comply with the general hierarchy, there are 2 options:
- Use its xpath, if this case is rare.
- Write a new keyword, if this case is seen often (a new application or a different section of it).
To summarize, we've been using granular keywords in our company for mobile, web and desktop applications; without writing any page object. And we have hundreds of automation scripts, which are more readable and maintainable (GUI changes in labels are detected and corrected easily by testers).
Please comment to make this post better :)