What is Keyword Driven Framework
When we talked about different types of frameworks, we talked about Keyword framework. Keywords are blocks of functionality that achieves a certain purpose. The amount of functionality and the scope of what resides inside a keyword is a matter of discretion and domain knowledge. This section falls under the category of selenium framework.
Where is it useful?
Technical Keywords:
For example, we can say click() is a keyword and we handle the logic of checking for existence of element, clicking and expecting the next step inside click. So we can define all operations like click, set, and so on customized to our web application, put them all in one module and keep making calls to these keywords in our step definitions.
As we can see now we have a uniform behavior described for certain functionality and we can repeatedly use it. Any changes in the behavior of click would have to be changed only in the module where we define click and all test scripts automatically get that functionality applied. So makes maintainability easier right.
Business Keywords:
We can also define keywords as representing business workflows, so that readability is addressed. For example, I might say sign_in is a business keyword. So whenever I call a keyword sign_in(username,password) , I should expect that keyword to click sign in button, enter username and password that I supply to it and ensure that I have signed in to the application and on home page or landing page.
What is the recommendation?
It really depends on how clear are you in your requirements. But that said, based on large scale implementations of frameworks, having business keywords makes sense because you want readability not just from your team, but also from others. You would definitely like to keep the extreme technical details abstracted into the keywords and expose only the main business functionality through business keywords.
Think about it, how nice it would be to just call the following in your step definitions
- Sign_in(username,password)
- purchase_item(item_name)
- pay(check)
- confirm_order
What is the other side ?
We all know that if it were so easy, then why all the fuss about automation in the industry? It is easy once you cross the chasm right, but until that point, lets take it step by step. Of course the fact that you are reading this post is that you want to learn if it is possible in first place. And it is ! To what perfection ? is an open question. But definitely we can be better than our current state right.
There is definitely some effort, design and implementation details to build the keywords and they might evolve over time too, however once you have them, the operational aspects of using them in step definitions makes life very easy.
Enough said right ! Lets move to implementation details.