Developing Keyword Driven Framework

Rahul Singh Rathore
A free video tutorial from Rahul Singh Rathore
Software Developer Engg in Test
4.2 instructor rating • 10 courses • 22,702 students

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 keyword. So first of all. We need to figure out the unique work for our framework. So key word. So in order to do that, first, I will list on what are the common pompon component, we usually deal on the way and based on that, I will divide the keyboard. So the components are button a link. Navigation. Text box. Radio Watan Check box. Drop down. And, uh. Wait, so also we require the waiting logic, so it is also in component. Now, what are the common actions we can perform on this component for this? We can perform the action while dealing. Also, the action is click navigation. We can navigate to any Web page, text, Xbox. We can supply text, so send keys, the audio button again, click. Check box, again, click. DropDown, select and wait, we can perform debate logic, so all this common action, I can map to the unique keyword so they give what you can derive from here can be first is for the click, which will map to the click action. The second one is the Navigator, which will perform the navigator to the specific gural after that select which will select the value from the top down and send keys which will supply the text inside the text. So these are the key words 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 key word and in the same manner I have added inside the Excel sheet. So click to perform the Click Action Center to provide the input select and so on. So the logic behind building the keyword and 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. He walked inside this, I will add a class called Data Engine. I'm going to make these classes public and inside this first, I will create certain private variable which will have the index value for your keyword column locator type column loquitur value and parameter. So private Read-Only and. Keyword column. Similarly, look at our type. Look at our value. And parameter. So this very well, we 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 in the word column, comma int. Locator collar locator type column. And. Look at the value column. And barometer. Call them. And here I will use this to point to the variable and initialize with the values applied. 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. Look at the value column and this will be parameter. OK, 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 of that element look at. So here I will use private. And the return type is by because, by the way, is a class which help us to create the locator, so get element located. And this will take the argument for us to look at a tape, so a 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 look at that tape and case. So the first one is the. Last name. And here I'm going to return. By class name, and they look at their value. OK. And in the similar manner I'm going to create for the other. So the next one is. CSO selected. And this will be CSI Selecter. The next one is idee. So this will be by Heidi. Link, text. So instead of using linked text, I will rely on parcelling 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 the name. And the XPath. So XPath. Text expert. And fact name. And in the end, I'm going to put a default. Case where if I am not specifying any specific look at the type, then based on the ID, it will return as they look at the. So during the passing, I'm going to call this method, which is going to read the data from this two column, and based on that, it is going to give us the location 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. Platform action. So this matter will accept your argument that a string. He would come and look at that tape and look at our value, and based on the key word, I will use my suitcase. The return type will be void. So here, the first keyword is click. Click. And the action will be. But. Helper, dot. Click button, and here I'm going to call this method that is get element located, which is going to tell us the look at that. And the argument to this method will be look at that type and look at our value. And after that, I will call the break. OK, so this is our framework method, so that during the runtime I will call the perform action method, which will contain the key word at type, and look at Ravello, which is internally going to call the cat element locator method, which will return as the locator of development. And let me make it public similarly for the other keywords. Send Kees. So this will be. Textbooks help our daughter type in textbooks. Get element locator locator type command locator. And also, in short, in some cases, you might need to supply the argument like this. OK, so here and also the parameter can be single double or you can have any number of araminta. 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 represent that parameter with very blunt. OK, and I'm going to use ARC's index zero, so it will be in the form of error. So here I am accessing it. Zeroth value. So during the daytime, 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 selected by value. That element locator locator type locator value and the parameter. After that, again, I will call break. Wait for element. So here I will call General Helper Dot. We had four element. That element. Locator type, come on, look at value. Time span from second, let's say, 50 seconds. After that break. And the last key word that is never get. So here I need to call navigation helper navigation, help our daughter navigate to United and the world would be argument of index zero. That break. 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 for my exception clause so that if a user has specified any other keyword at that, then. This selected keyword hours, or in general, through no such Noki word for the exception. Instead, let me make it no such Keywood. So here I will correct deconstructed public. Here, I will ask the user to supply the message for the exception. And I'm going to call the keyword to supply this message for the superclass. And here I will use through. New. No such. The exception and the message, let's the key word not found. David. So now, during the time the actual flow will be for us, we need to create the object of this class and where we need to initialize the value for the respective columns, that Maisky column, looking at type column, look at the value column and so on. After that, we need to call off our love, which is going to iterate. To this end, Tirol. 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 daguerreotype, look at our value and also any parameter. Based on the keyword, it is going to switch the case and it is going to call the cat element locator method, which will return as the locator type, or you can say where Bellemont locator based on the locator type and the will 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 the script using this key word and framework. So that's all for this video. And thanks for watching.