What is Gherkin syntax and how it works

Rahul Shetty
A free video tutorial from Rahul Shetty
Founder of RahulShettyAcademy.com|350k+ QA Udemy Students
4.5 instructor rating • 21 courses • 369,126 students

Learn more from the full course

Cucumber with Java-Build Automation Framework in lesser code

Step by Step Cucumber BDD Approach to design the powerful Testing framework(Selenium,Appium,API) with very MINIMALCODE

10:45:00 of on-demand video • Updated May 2021

  • By end of this course , You will be able to develop Cucumber Test Framework for any Web/Mobile/API Automation testcases
  • Understand how BDD(Behaviour driven development) approach works with the knowledge of gherkin syntax
  • Indepth understanding of real time Automation framework challenges and solutions to fix them
  • Complete knowledge on Datadriven testing, Parameterizations, Resuable components, Cucumber hooks and tags
  •  Additional knowledge on Integrating Cucumber framework with MAVEN, JENKINS, GITHUB
English [Auto] Welcome back. So let's start understanding few terminologies regarding this matter. The first thing is Gerkin so what is Gerkin? So basically it is a language to describe the software behavior. So in testing terms, to speak its own language, to define the testing is OK in general, if you want to develop or if you want to test something, you write a test case in plain English, write like check the credit card payment article, loan payment. So it's all about go and click on the link, verify that information is being sent. Click on submit, take the confirmation page is displayed so you'll write a pretty plain test case if you want to test any software behavior. But so doing this, there are some problems with this design. OK, so Gerkin is replaces and fixes all the disadvantages we are having with existing approach of writing test cases in plain English. OK, now for example, let me write a test case here. OK, this is already written an example. I laid out this. So this is a plain test case. If you want to write like pop up message is displayed when buttons are clicked and errors are gone. OK, so this is the text given by the business analyst, so let's assume that we all know that business analyst is the guy who will give us requirements, business requirements, OK, based upon business requirements given by B.A. Kuai will go and buy test cases based upon that requirement. OK, so in one of that requirement, this is what he has given. So when you write something in plain English that represent the interpretation of that line could be different for a different person. OK, B assumes or interpret this in one way, but when you read this, you might interpret this in another bit, OK, because there is no one singular common syntax to stick to a particular language. So here it's up to the people. So based upon his proficiency in English, people define something now we'll see here. And B, want to write like this pop up message is displayed when buttons are clicked. OK, and then Sargon, this is what he thought of giving a requirement. So one way of interpreting this is the messages displayed. When buttons clicked. And then Eleazar gone, so. Performances and errors are gone on button click on clicking on a button. The message is display and arrows are gone. This is how he interpreted and written, but when queried this, his vision could be different in reading this plain English. Now, you can also write this as. Pompousness, it's. He's displayed. Only when buttons are clicked and errors are gone carefully, observe these two lines not. OK, here, what is start of this line is. Pop-Up Message will only display when I click the button and all the errors are gone. OK, so he has to make sure all the errors are not present in the page and then he clicks the button so that pop up message is displayed, OK? That two conditions has to me to display pop up message. That's what you interpret and never be. He's saying that on button clicked automatically. Alerts are gone and pop up and as it comes up. So which is correct, and if you read this clearly, you are confused, OK, just pass this video and try to understand. So with a plain English language, what generally are traditionally people using the market? There could be wrong in interpreting that. OK, when business analyst give this developer may assume this this style and he developed like this. OK, Kuai may be assuming in this fashion and developed a test case in this way so that of course there will be a mismatch and he would be raising an issue once you see that in the production and thereafter he would be. If developers is wrong and if it's already late and before losing the project, then there is something missing. OK, if at least let's assume that developer made a mistake, if Kuai is correct, then he could correct it and he can play the defect and that is not a big deal. But if Q8 self interpreted in the wrong way and also interpreted in the wrong way, then what happens? It goes into the lane, but when they start an argument and everyone have their own version. So that is why people generally put in meetings as a sign of, OK, whenever they develop test cases, they get sign-off signed off. That is consistent with the business and that's what people traditionally do to overcome this problem. So, however, there are some minor problems are still going on in understanding this the way people are writing. So to overcome this disadvantage, if we all come into a common platform of. Showing or describing software behavior, then there is no point of misleading from actual behavior. OK, so this is where Gerkin comes into the picture. So if B.A. wants to right. Or wants to show a software business requirement, he has to define that in Gerkin syntax so they can define some standards where if he used that standard in describing this test case, then it would be very clear for developer auricular to interpret it, OK? That is where this comes into picture and we it as a building behavior driven development. OK, we explicitly defined the behavioral software requirement using this Gerkin language so it could be also served as a business level and domain specific language. OK, so you will be seeing here how to exactly right at Eskisehir Girkins Index. So here I just want to throw a light on what is Gerkin. And I hope you understand this example of misleading, of interpretation. Right. So that is one main thing, and the key words which you frequently see in cucumber are senario future feature film scenario outline and step definition. OK, these key words you will commonly see when you are working with cucumber automation or if you go to any interview, obviously there will be a question from one of the schema. OK, what is does and how it looks. That's a common thing. So these two will be specifically concentrate when we are working on real automation things. OK, now I want to concentrate on these three parts. So first, what is senario? In cucumber, test cases are presented as scenarios. OK, we generally talk them in terms of scenarios instead of a test case. So in traditional world, we see it as a test case. But when we are dealing that with cucumber, we should see it as a scenario because this is how we use a key word in that framework now. So, as I said, this is a test case and this test case should be presented in jerrycan style, isn't it? So each and every scenario is nothing but a chicken language. So whatever you want to express, you need to express for the jerkily. Now, what does Gerkin takes as an input and how do you define it with the syntax? OK, let's understand these three dimensional. So when you want to write a test case now, for example, I have something here. Let me take that. I'll take this. And I based it here. OK, you can ignore this bullet points not required. Let me put. Given an. Given user fills and then, OK, now, so here the business requirements are there to be a one, two experts is making credit card payment with minimum by selecting a minimum amount option. OK, when you want to make credit card payment, if you really do in your real time, you know this. So if you want to make any credit card payment, you will have an option to pay a minimum due or you will have an option to pay a complete statement balance, or you will also have an option to pay out that amount. And you can mention the amount in it. So any of these three fields you have to use to pay your credit card. So here, let's assume that functionality is to check. If minimum amount, minimum payment floor is working or not, OK, if credit card bill is about five hundred dollars and twenty five dollars, the minimum payment, so there is an option to select a minimum payment and you have to pay that 25. So this is a functionality which you need to verify. So to express this to experts and to define this software behavior, Gerkin uses three key words here given then and then. OK, so given is to test this. What are the pre conditions like before you begin testing this functionality, what you need to know or what do you have to fulfill? OK, in this case, to fulfill this credit card payment, first of all, you should be on pay credit card bills. OK, this is our requirement. So here you are. Business is clearly telling that from which page you can test this functionality, OK, if you're simply simply right. Go and make the credit card payment, the credit card payment, maybe from multiple pages. OK, when you launch or when you navigate to your net banking, same credit card payment could be from the left side and the navigation links all you can access it from credit card tab or there could be any link in the database for the instant. A quick link, references to big rate cut. So first, we need to understand on which type are which module. We are testing this for that he has to provide a given like preconditions are mentioned. So given user is on credit card beach mixed when. So next is once you are on that page with preconditions fulfilled now to make this payment, what action you need to perform. OK, that stands for the when. The purpose of when is to describe you that action to make this payment happen. What are the actions you need to perform when user fills out details? OK, he has to obviously fill that data you are making payment and which from which account and then he should select a minimum amount option. Yes, selected. And for this one, if there are multiple user actions, you can comfortably use and operate. OK, you can use and keyword and you can concatenate all your actions under this one, OK? That's why once all the details are filled and minimum amount option is given and user will go and click on Bellbottom obviously has to do that. This is an action. And then what is the result? OK, so once you fulfill the conditions and what after he makes a payment and then what is the purpose of this flow. The result. Right. That result should be written in then keyword here then stands for purpose of then step is to observe the expected output. Here, credit card confirmation page is displayed. This is our expected output, you'll see that a simple test case making minimum payment, due amount credit card. If they want to express that, he can just write in one single line. But from that, we will have a lot of questions like from which navigation we have to do, what is the flow and what is the outcome expected? So all this if they define in this fashion and how quickly this. To test this is what we say as a behavior driven development. OK, so given when the test case requirement is very, very clear here. So in cucumber, this way of writing a test case is called us senario. OK, so one caution, please remember that don't assume that if business analyst does not give you this in this way, you cannot work with cucumber. OK. Am I giving giving you a simple, plain text on what I have shown here? If you want to automate your test case, you get you will like selenium test if it is a web based. OK, so if you want to use cucumber framework, make sure you convert this test to get into this fashion. You would define it as an automation tester when you have a requirement in a single baseline reading that requirement. And obviously when you want to automate something, you have to start from the page which from where you want to navigate and you have to automate all directions. And at the end you need to validate. Right. By using assertions so fast. First, convert your tester, guess into this model and then you can use cucumber automation to automate your excuses. OK, so just don't think that if you are being or if your manager or whoever gives your test case is not in the standard you cannot use to convert, because most people say that we don't get like this. So continuous cucumber. OK, you can use cucumber for sure. Just convert this test. Whatever you got as a plain English into this, it's a simple step. Right, right. In your own fashion and then you can happily automate it. OK, so let's continue on in our next lecture. Thank you.