Udemy

Developing Keyword Driven Framework

A free video tutorial from Rahul Singh Rathore
Software Developer Engg in Test
Rating: 4.3 out of 5Instructor rating
10 courses
39,598 students
Developing Keyword Driven Framework

Learn more from the full course

BDD with Selenium Webdriver and Specflow using C#

Learn Behaviour Driven Development using the two most powerful tool, Webdriver and Specflow with C# as language binding!

26:41:58 of on-demand video • Updated October 2021

By the end of this course you will give have great understanding Selenium Webdriver using C#
How to use Selenium Webdriver to test web based application and what are the advantages of Selenium Webdriver over Selenium RC
This tutorial will give you great understanding of Selenium Webdriver, and after completing this tutorial, you will be at intermediate level of expertise from where you can take yourself to higher level of expertise. Also you will have great understanding of C#
English [Auto]
Hello, everyone. Welcome again. Well, in this video we are going to develop keyword driven framework. So the most important part of keyword driven framework are keywords. So first of all. We need to figure out the unique keyword for our framework. So keywords. So in order to do that, first I will list down what are the common web component. Component. We usually deal on the UI and based on that I will derive the keywords. So the component are button link. Navigation. Text box. Radio button. CheckBox. Drop down. And. Wait. So also we require the waiting logic. So wait is also a component. Now what are the common actions we can perform on this component? For this, we can perform the click action. For the link. Also, the action is click navigation. We can navigate to any web page text box. We can supply text. So send keys, read your button again. Click checkbox again. Click. Dropdown select and wait. We can perform the wait logic. So all this common action I can map to the unique keyword. So the keyword you can derive from here can be. First is for the click, which will map to the click action. The second one is the navigate which will perform the navigate to the specific URL. After that select which will select the value from the dropdown and send keys which will supply the text inside the text box. So these are the keywords and for the wait, wait for element. So based on the common action, what you can perform on the web component, I have derived the keyword and. In the similar manner I have added inside the Excel sheet. So click to perform the click action. Send keys to provide the input, select and so on. So the logic behind building the keyword driven framework is that. Based on the locator type and locator value, I will create the locator for that web component and based on the keyword, I will perform the corresponding action. So here inside our project, I will add one more directory. Called keyword Inside this, I will add a class called Data Engine. I'm going to make this class as public. And inside this first I will create certain private variable which will have the index value for your keyword column locator type column locator value and parameter. So private read only and. Keyword column. Similarly locator type. Locator value. And parameter. So this variable will have the index value for the corresponding column. And also I will create a constructor where I'm going to initialize this variable. So the parameter to this constructor will be int keyword. Column comma, int. Locator. Column locator type. Column. And locator value column. INT parameter. Column. And here I will use this to point to the variable. And initialized with the value supplied. So similarly for the other. And the reason why I'm doing this is because for me, this is the format. But when you are running your script, you might have a new column over here. So by supplying the value, you can read the specific column. Locator value column, and this will be parameter. Okay. Now, once this is done, first of all, we need to write a logic which is going to combine both of this and give us a web element locator. So here I will use private. And the return type is bi because BI is the way is the class which helps us to create the locator. So get element locator. And this will take two arguments. First is the locator type. So string. Locator type and comma string locator value. And here I'm going to create a switch case. So based on your locator type, I will construct the locator by including the locator value. So switch. This will be locator type and case. So the first one is the. Class name. And here I'm going to return by dot class name and the locator value. Okay. And in the similar manner I'm going to create for the other locator. So the next one is CSS selector. And this will be CSS selector. The next one is I'd. So this will be by.id. Link text. So instead of using link text, I will rely on partial link text. But if you want to have linked text, you can add a separate case for that. Then after that name. So name. And this will be by name. And the X path. So XPath. By X path. And tag name. And in the end, I'm going to put a default. A case where if I am not specifying any specific locator type, then based on the ID, it will return us the locator. So during the parsing, I'm going to call this method, which is going to read the data from this to column. And based on that, it is going to give us the locator for the element. And after that I'm going to make a method which is going to perform the action based on the keyword. So again, here. I'm going to copy the same code. And this will be. Perform action. So this method will accept three arguments. That is string. Keyword, comma locator type and locator value. And based on the keyword, I will use my switch case. The return type will be void. So here the first keyword is click. Click. And the action will be. Button. Helper dot. Click button. And here I'm going to call this method that is get element locator, which is going to return us the locator. And the argument to this method will be locator type and locator value. And after that, I will call the break. Okay, so this is our framework method. So during the runtime I will call the perform action method, which will contain the keyword locator type and locator value, which is internally going to call the get element locator method, which will return us the locator of the web element. And let me make it public. Similarly for the other keywords. Send keys. So this will be text box helper dot type in text box. Get element locator locator type comma locator value. And also insert in some cases you might need to supply the argument like this. Okay. So here and also the parameter can be single double or you can have any number of parameter. So in that case, along with this information, I'm going to create a variable with variable argument. So when I specify like this, that means it does not have any fixed length. In the same method, you can supply the single value for this particular parameter or more than one value for the same parameter. This represents that parameter with variable length. Okay. And I'm going to use arcs. Index zero. So it will be in the form of array. So here I'm accessing its zeroth value. So during the runtime, it will become more clear why we use this particular variable here. And after that, I will call the break. So the next keyword is select. So here I will use. Combo box Helper dot. Select by value. Get element locator, locator type, comma locator value and the parameter. After that again I will call Break. Wait for element. So here I will call generic helper dot. Wait for element. Get element. Locator type comma locator value. Comma time span from second, let's say 50s. After that break. And the last keyword that is navigate. So here I need to call navigation helper. Navigation helper dot navigate to url and the URL will be argument of index zero. NASA. And the default, I'm going to throw an exception. Default. So inside the exception. Custom exception. I'm going to add one more class called No. Keyword found exception. So here again, I'm creating a custom exception which will extend from exception class so that if user has specified any other keyword other than. This selected keyword, our script or data engine will throw the no such no keyword found exception. Instead, let me make it. No such keyword. So here I will create the constructor public. Here, I will ask the user to supply the message for the exception. And I'm going to call the base keyword to supply this message to the superclass. And here I will use throw. New. No such. Keyword exception and the message, let's say keyword not found. Stuart. Okay. So now during the runtime, the actual flow will be first, we need to create the object of this class and where we need to initialize the value for the respective columns. That means keyword, column locator type, column locator, value, column and so on. After that, we need to call a for loop, which is going to iterate. To this entire row. And one by one it is going to read the keyword column. After reading the keyword column, it will call the method perform action where we will supply the keyword locator. Type locator value and also any parameter. Based on the keyword, it is going to switch the case and it is going to call the get element locator method, which will return us the locator type, or you can say web element locator based on the locator type and the value for the corresponding argument. And after that it is going to perform the action. So this will be the flow of the keyword. So in our next video, I will show you how to run this script using this keyword driven framework. So that's all for this video. And thanks for watching.