Тёмный

Selenium Cucumber Java BDD Framework 9 - Hooks | Step by Step 

Automation Step by Step
Подписаться 529 тыс.
Просмотров 82 тыс.
50% 1

FREE Tutorials - automationstep...
QUIZ - forms.gle/np9t...
1 - What are Hooks
2 - Why to use Hooks
3 - When to use Hooks
4 - How to create & use Hooks - Step by Step Demo
5 - Conditional Hooks
Useful Tips
What are HOOKS
Blocks of code that runs before OR after each scenario
Hooks in Cucumber are like Listeners in TestNG
Can define hooks by using annotations @Before @After
Scenario Hooks - runs before and after each scenario
Step Hooks - runs before and after each step
Conditional Hooks - hooks associated with tags for conditional execution
Why to use HOOKS
To manage the setup and teardown
To avoid rewriting the common setup or teardown actions
Allow better management of code workflow
When to use HOOKS
Whenever you have some common setup and teardown actions to be executed before each scenario
How to use HOOKS
Step 1 - Create a new or use an existing Feature File
Step 2 - Create the steps for the scenario in the feature file
Step 3 - Create setup and teardown methods and mark with annotation
@Before
@After
@BeforeSteps
@AfterSteps
Step 4 - Create new or use an existing TestRunner class
Step 5 - Run the TestRunner class and check execution
We can use Tags with Hooks - Conditional Hooks
Hooks can be conditionally selected for execution based on the tags of the scenario
To run a particular hook only for certain scenarios, you can associate a Before or After hook with a tag expression
Tags can be used with
@BeforeSteps
@AfterSteps
@After(value="@smoke", order=2)
Single tag
tags = {"@smoke"}
Multiple tags
Tags with AND OR conditions
tags = {"@smoke or @regression"}
tags = {"@smoke and @regression"}
tags = {"@smoke and not @regression"}
Skip or Ignore Tags
tags = {"(@smoke or @regression) and not @important"}
Ordering Hooks
We can use multiple Before and After hooks and also assign order of execution
@Before(order=0)
@Before(order=1)
Background
Whatever happens in hooks is invisible to people who only read the features
Only use hooks for low-level logic such as starting a browser or deleting data from a database.
You should consider using a background as a more explicit alternative, especially if the setup should be readable by non-technical people
Note - we will learn about background in next session
You can keep your function name anything
Hooks will get executed even if the test fails
You need to import the library
import io.cucumber.java.Before;
import io.cucumber.java.After;
You can support by Joining Automation Step By Step channel: www.youtube.co...
Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you
You can support my mission for education by sharing this knowledge and helping as many people as you can
If my work has helped you, consider helping any animal near you, in any way you can.
_______ ONLINE COURSES TO LEARN _______
automationstep...
Never Stop Learning
Raghav

Опубликовано:

 

19 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 186   
@ilyshka9711
@ilyshka9711 Год назад
Hello from junior AutoQA engineer from Russia and thank u very much. Your playlist about cucumber + selenium very useful on my project!
@RaghavPal
@RaghavPal Год назад
You are welcome
@hindsabik4025
@hindsabik4025 Год назад
This is no doubt the most amazing and well explained tutorial you can find about Java selenium cucumber many thanks
@RaghavPal
@RaghavPal Год назад
So nice of you
@automationrockerz8006
@automationrockerz8006 3 года назад
Hello Raghav, Your Videos are really great. Thanks for updating the cucumber series with new topics. I am a great fan of you....
@RaghavPal
@RaghavPal 3 года назад
So nice of you Balagopal, I will do
@ilavarasansriraman4140
@ilavarasansriraman4140 3 года назад
You are like God to me ❤
@RaghavPal
@RaghavPal 3 года назад
Hi Ilavarasan, humbled, pls consider me just as a Teacher
@3aadel
@3aadel 3 года назад
@@RaghavPal and you're a great teacher! thank you bro.
@toobamunir7586
@toobamunir7586 9 месяцев назад
Trust me you are the saviour, thank you for making such clear and concise tutorials!
@RaghavPal
@RaghavPal 9 месяцев назад
Most welcome Tooba
@RajendraNayak-iw1xk
@RajendraNayak-iw1xk 3 месяца назад
Raghav you Explained very very good thankyou raghav you are real person to save maximum number of strugged people
@RaghavPal
@RaghavPal 3 месяца назад
Thanks a lot Rajendra.. humbled
@abhijeetdeshmukh
@abhijeetdeshmukh Год назад
Raghav you are just amazing.you explained everything in very simple language.
@RaghavPal
@RaghavPal Год назад
Most welcome Abhijeet
@jackiema5888
@jackiema5888 3 года назад
This helped me a lot! I can't thank you enough Raghav.
@RaghavPal
@RaghavPal 3 года назад
Most welcome Jackie
@sahilkakkar7550
@sahilkakkar7550 3 года назад
Hi Raghav, Your all videos are so great and easy to understand. Thanks for your videos. and Take care now days
@RaghavPal
@RaghavPal 3 года назад
Thanks a ton Sahil
@ranigaddam1126
@ranigaddam1126 3 года назад
Hi Raghav, Your videos are so great and easy to understand. Thanks for your videos. Could please make one video for how to use Testng with cucumber.
@RaghavPal
@RaghavPal 3 года назад
Noted, I will Rani
@gurubg982
@gurubg982 3 года назад
Yaa sir please make a video testNG with cucumber
@manankumar4850
@manankumar4850 Год назад
Excellent explanation
@RaghavPal
@RaghavPal Год назад
Glad it was helpful Manan
@Knaga-qs3pu
@Knaga-qs3pu Год назад
Your teaching supper sir 💯💯💯💯☑️☑️☑️
@RaghavPal
@RaghavPal Год назад
Thanks and welcome
@ravendhiran4062
@ravendhiran4062 3 года назад
Wonderful session.. Now I'm able to understand about Hooks Concept... Thank you 💓
@RaghavPal
@RaghavPal 3 года назад
You are welcome Ravendhiran
@navindaggula7843
@navindaggula7843 3 года назад
Amazing Raghav!! This really helps!!
@RaghavPal
@RaghavPal 3 года назад
Most welcome Navin
@sweetthirty2
@sweetthirty2 2 года назад
can we extend the class where hooks are defined???
@RaghavPal
@RaghavPal 2 года назад
Can check this Samir stackoverflow.com/questions/34771928/cucumber-class-extending-step-definitions-and-hooks
@3aadel
@3aadel 3 года назад
Excellent ! many thanks Raghav 👍
@RaghavPal
@RaghavPal 3 года назад
Most welcome Adel
@kiransingh8239
@kiransingh8239 2 года назад
Too good explanation,thanks a lot Raghav 🙏🙏
@RaghavPal
@RaghavPal 2 года назад
Most welcome Kiran
@rameshpatole4894
@rameshpatole4894 Год назад
Hello Sir ,All videos are best.Thank you.
@RaghavPal
@RaghavPal Год назад
Most welcome
@teddykiller8421
@teddykiller8421 3 года назад
May god bless you with all the prosperity 🙏. Am fully satisfied with each and every word of your teaching. Thank you so much ragav
@RaghavPal
@RaghavPal 3 года назад
You are most welcome Purushotham
@teddykiller8421
@teddykiller8421 3 года назад
@@RaghavPal a small request, have you posted any video that where to start the beginning of automation and what are the things go first, second and so on... and things make completion of automation. Thanks in advance
@RaghavPal
@RaghavPal 3 года назад
Some of these tips you will get in askRaghav series - ru-vid.com/group/PLhW3qG5bs-L_jt72YpRmQnR5YA8P_R7Y6
@teddykiller8421
@teddykiller8421 3 года назад
@@RaghavPal thank you ragav.
@sbc498
@sbc498 10 месяцев назад
@@teddykiller8421 Did you get the exact video for that problem?
@abhishekthomas7799
@abhishekthomas7799 3 года назад
you can use Webdrivermanager to avoid the constant hassle of changing the chrome driver exe again and again.
@RaghavPal
@RaghavPal 3 года назад
Yes Abhishek, I added that in Selenium Java Framework, will do here too
@krina3111
@krina3111 3 года назад
You really have explained well......
@RaghavPal
@RaghavPal 3 года назад
Thanks Krina
@wahindia3588
@wahindia3588 Месяц назад
So, I have been using testNg annotations in almost all my projects... but with Cucumber I think we can't use testNg recommend is cucumber hooks After/before???
@RaghavPal
@RaghavPal Месяц назад
Let's break down the problem step by step: Problem Statement: You're familiar with using TestNG annotations in your projects, but you're wondering if you can use them with Cucumber, specifically in the `Before` and `After` hooks. Understanding TestNG Annotations: TestNG is a popular testing framework that provides annotations to control the execution of tests. Some common TestNG annotations include: * `@BeforeMethod`: Runs before each test method * `@AfterMethod`: Runs after each test method * `@BeforeClass`: Runs before the first test method in a class * `@AfterClass`: Runs after the last test method in a class Cucumber Hooks: Cucumber is a BDD (Behavior-Driven Development) testing framework that provides its own set of hooks to perform setup and teardown operations. Cucumber hooks are similar to TestNG annotations, but they're specific to Cucumber. The two main Cucumber hooks are: * `Before`: Runs before each scenario * `After`: Runs after each scenario The Question: Can you use TestNG annotations in Cucumber hooks, specifically in the `Before` and `After` hooks? Answer: No, you cannot use TestNG annotations in Cucumber hooks. Cucumber has its own hooks, and they're not compatible with TestNG annotations. Why? Cucumber and TestNG are two separate testing frameworks, each with their own architecture and execution models. While both frameworks provide hooks or annotations for setup and teardown operations, they're not interchangeable. What to Do Instead: If you need to perform setup or teardown operations in your Cucumber tests, you should use Cucumber's built-in hooks (`Before` and `After`). These hooks are specifically designed for Cucumber and will work seamlessly with your Cucumber tests. Example: Here's an example of using Cucumber's `Before` hook: ```java import io.cucumber.java.Before; public class MyHooks { @Before public void setup() { // Perform setup operations here } } ``` Similarly, you can use the `After` hook to perform teardown operations: ```java import io.cucumber.java.After; public class MyHooks { @After public void tearDown() { // Perform teardown operations here } } ``` By using Cucumber's built-in hooks, you can ensure that your setup and teardown operations are executed correctly and efficiently in your Cucumber tests --
@kattakapilkumar
@kattakapilkumar 3 года назад
your tutorials are helpful
@RaghavPal
@RaghavPal 3 года назад
Glad to hear that!
@saiadaikappan
@saiadaikappan 3 года назад
Excellent presentation, thank you for sharing knowledge.
@RaghavPal
@RaghavPal 3 года назад
Glad it was helpful!
@shruthimanjesh5169
@shruthimanjesh5169 Год назад
Very well explained... Thank you
@RaghavPal
@RaghavPal Год назад
Most welcome Shruthi
@priyatayal4541
@priyatayal4541 3 года назад
I have one question raghav, for every scanerio there will be one step definition file right?? Like in one feature file we have 3 scanerios then we have 3 step definition file for each scanerio right??
@navikasspecials3112
@navikasspecials3112 3 года назад
i am also having the same question...
@RaghavPal
@RaghavPal 3 года назад
Hi Priya and Mounika, it can depend on how you need the steps, If you like you can create a single class for step definition and add all the functions from your feature and scenarios or have it separate for every scenario. Basically when running, cucumber will check for matching step definition for the step in the file/location you have specified in Cucumber runner
@SarangHoley
@SarangHoley 3 года назад
Very well explained with slides 👍😊
@RaghavPal
@RaghavPal 3 года назад
Glad it was helpful Sarang
@IshwarMusical
@IshwarMusical 6 месяцев назад
Thanks a lot sir jii
@RaghavPal
@RaghavPal 5 месяцев назад
Most welcome Ishwar
@ameyapatil1139
@ameyapatil1139 2 года назад
Great job man ! Really Thankful !
@RaghavPal
@RaghavPal 2 года назад
Glad it helped Ameya
@SP-Charis
@SP-Charis Год назад
Hi Raghav, Your explanation is very nice.. it is very clear I request you a video on executing failure test cases using hooks and parallel execution 🙏
@RaghavPal
@RaghavPal Год назад
Sure Chandra, thanks for the comment
@SP-Charis
@SP-Charis Год назад
@@RaghavPal Hi Raghava, thank you for your reply Do we prefer Cucumber with Junit or Cucumber with TestNG? which one is mostly used.
@RaghavPal
@RaghavPal Год назад
In General, I have seen for automation testing projects, TestNG is preferred
@SP-Charis
@SP-Charis Год назад
Hi Raghava, here is my question how to automate Captcha, OTP (mobile and mail) and payments methods in selenium.
@RaghavPal
@RaghavPal Год назад
Hi Chandra Captcha is to prevent robots or automated scripts mimic humans. So ideally we should not automate Captcha, However there are ways to handle it. I will say check the following 1. How imp is to automate this scenario 2. Check the time and effort required 3. Check with your dev team if Captcha can be disabled in testing env 4. Check with your team if a static Captcha be provided in QA env
@Imran-M-
@Imran-M- 3 года назад
Hi Raghav, quick questions: 1> Any specific reason your wrote WebDriver driver = null @15:23? Because even if not initialized, the interface reference would still point to null upon declaration. 2> Is the order of execution for @After(order=-1) @After(order=0) @After(order=1) would be 1, 0 then -1 ?
@RaghavPal
@RaghavPal 3 года назад
HI Imran, should be okay if you leave null, Yes, I believe I have shown this in the video
@riz_anime9478
@riz_anime9478 Год назад
your video was great but, why don't you use WDM as jars ,then there is no need of adding chromedriver or any other drivers,
@RaghavPal
@RaghavPal Год назад
It was released later and I added a video on that - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-8vWTgyoG0nc.html
@sravanthik237
@sravanthik237 3 года назад
Hi Raghav, thanks for the beautiful explanation. Can u please specify the examples for @beforesteps and @aftersteps hooks, like what can we run there?
@RaghavPal
@RaghavPal 3 года назад
Hi Sravanthi, I will plan to add more on that
@fitnessdaily7288
@fitnessdaily7288 3 года назад
Excellent bro. Thanks
@RaghavPal
@RaghavPal 3 года назад
Welcome 👍
@tulasiramsunkara
@tulasiramsunkara 2 года назад
@Raghav: Ideally Hooks should not be part of any step definitions. In my knowledge Hooks should be individual class and our browser initialisation and teardown methods should be part of them. If possible can you create a video where setup and teardown methods are part of Hooks class and pass the driver instance to step definitions file.
@RaghavPal
@RaghavPal 2 года назад
Sure Tulasi, I will check on this
@roopaar4726
@roopaar4726 2 года назад
yes can you please share any demo on this above and also I need where beforeHook is executed once and not for each scenario
@NeilDattaS
@NeilDattaS 3 года назад
Could you please help me knowing why am I not seeing any results in console like yours i.e., the scenarios are passed. I am seeing no error and ran successfully
@RaghavPal
@RaghavPal 3 года назад
see if your test classes are named as per convention
@NeilDattaS
@NeilDattaS 3 года назад
@@RaghavPal okay. Your sessions are great! I have one request. Could you please make a video on how to capture the screenshots for all steps and also how to pick the login data from excel
@RaghavPal
@RaghavPal 3 года назад
I will do
@Noor-EJannat-g4v
@Noor-EJannat-g4v Год назад
what is @cucumber options ?
@RaghavPal
@RaghavPal Год назад
The @CucumberOptions can be used to provide additional configuration to the runner. as shown in relevant sessions
@ruz966
@ruz966 3 года назад
Any idea how can we create a jar and run cucumber test with java -jar command
@RaghavPal
@RaghavPal 3 года назад
We can, but may not be the best solution, Try using maven commands
@gantooria
@gantooria Год назад
Hi raghav , can we put all the hooks in a seperate file and use it in all the step defs ?
@RaghavPal
@RaghavPal Год назад
Yes, in Selenium Java Cucumber, you can put all the hooks in a separate file and use it in all the step definitions. This can be achieved by creating a separate class file for hooks and defining the hooks in that file using @Before and @After annotations. Here is an example of how to do it: Create a new class file for the hooks and define the hooks using @Before and @After annotations. import io.cucumber.java.After; import io.cucumber.java.Before; public class Hooks { private WebDriver driver; @Before public void setup() { // Set up code here driver = new ChromeDriver(); driver.manage().window().maximize(); } @After public void teardown() { // Teardown code here driver.quit(); } } In your step definition files, you can import the Hooks class and use the hooks defined in it. For example: import io.cucumber.java.en.Given; import io.cucumber.java.en.When; import io.cucumber.java.en.Then; public class StepDefinitions { private WebDriver driver; @Given("I am on the login page") public void i_am_on_the_login_page() { driver.get("www.example.com/login"); } @When("I enter my username and password") public void i_enter_my_username_and_password() { WebElement usernameField = driver.findElement(By.id("username")); WebElement passwordField = driver.findElement(By.id("password")); usernameField.sendKeys("myusername"); passwordField.sendKeys("mypassword"); } @Then("I should be logged in") public void i_should_be_logged_in() { WebElement welcomeMessage = driver.findElement(By.id("welcome-message")); assertTrue(welcomeMessage.isDisplayed()); } } In your Cucumber runner class, you can specify the location of the hooks file using the glue option: import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features = "src/test/resources/features", glue = {"com.example.hooks", "com.example.stepdefinitions"} ) public class TestRunner { } In the above example, the glue option specifies two packages: com.example.hooks and com.example.stepdefinitions. The hooks defined in the Hooks class in the com.example.hooks package will be used by all the step definitions in the com.example.stepdefinitions package.
@gantooria
@gantooria Год назад
@@RaghavPal thanks raghav , i was wondering how we can use the driver from hook to step def , i found 2 solutions one is by creating thread local instance and one by using pico container , what do you recommend
@RaghavPal
@RaghavPal Год назад
Both solutions you mentioned, using a ThreadLocal instance and using Pico Container, are valid options for sharing the WebDriver instance between the hooks and step definitions in a Selenium Java Cucumber framework. Using a ThreadLocal instance involves creating a static WebDriver instance in the Hooks class and then initializing it in the @Before hook. The WebDriver instance can be retrieved in the step definitions using the static getter method. The advantage of this approach is that it is simple and easy to implement. Using Pico Container involves creating a container object in the Hooks class and registering the WebDriver instance as a dependency. The container object can then be retrieved in the step definitions and used to retrieve the WebDriver instance. The advantage of this approach is that it provides a more robust dependency injection mechanism. Both approaches have their advantages and disadvantages, and the choice between them ultimately depends on your specific requirements and preferences. However, in general, using a dependency injection framework like Pico Container is recommended for larger, more complex projects, while using a ThreadLocal instance may be sufficient for smaller projects.
@gantooria
@gantooria Год назад
@@RaghavPal thanks Raghav thats a great help and knowledge
@VrushaliHajare
@VrushaliHajare Год назад
Hi Raghav, I am getting the error when I run RunnerClass (perticular of lecture 9), but, when I run same with feature file scenarios and steps are passing smoothly. can you tell me what I can do? code is the same as of yours.
@RaghavPal
@RaghavPal Год назад
Hi, what is the error, will need to check the setup and commands
@VrushaliHajare
@VrushaliHajare Год назад
@@RaghavPal io.cucumber.junit.UndefinedStepException: The step 'user is on login page' and 3 other step(s) are undefined. You can implement these steps using the snippet(s) below: @Given("user is on login page") public void user_is_on_login_page() { // Write code here that turns the phrase above into concrete actions throw new io.cucumber.java.PendingException(); } @When("user enters valid username and password") public void user_enters_valid_username_and_password() { // Write code here that turns the phrase above into concrete actions throw new io.cucumber.java.PendingException(); } @When("clicks on login button") public void clicks_on_login_button() { // Write code here that turns the phrase above into concrete actions throw new io.cucumber.java.PendingException(); } @Then("user is navigated to home page") public void user_is_navigated_to_home_page() { // Write code here that turns the phrase above into concrete actions throw new io.cucumber.java.PendingException(); } I am getting this error
@RaghavPal
@RaghavPal Год назад
Yes, this is because you have not created step definitions (glue code) for your scenarios in feature file. Please check all the videos of this series
@VrushaliHajare
@VrushaliHajare Год назад
@@RaghavPal ok..thank you
@sweetthirty2
@sweetthirty2 2 года назад
should we define hooks only in Step definition??
@RaghavPal
@RaghavPal 2 года назад
Yes, can check this too www.axelerant.com/blog/how-work-cucumber-hooks
@aasraful
@aasraful Год назад
Thanks😍🥰
@RaghavPal
@RaghavPal Год назад
You’re welcome 😊
@sagaromer8385
@sagaromer8385 Год назад
whenever i am running step definition filw by right click it doesn't specify junit or anyother method to run.. how we specify the run configuration? please help...
@RaghavPal
@RaghavPal Год назад
Hi Sagar, you can follow these steps: Create a new run configuration by clicking on the "Run" menu in Eclipse and selecting "Run Configurations". Select "JUnit" from the list of run configurations on the left side of the dialog box. Click on the "New launch configuration" icon in the top left corner of the dialog box. Give your new launch configuration a name, and select the project and test class that you want to run. Under the "Arguments" tab, you can specify any command-line arguments that you want to pass to your test. Click on the "Apply" button to save your new launch configuration. Now you can run your test using the new launch configuration by right-clicking on your step definition file and selecting "Run As" -> "JUnit Test". You should now see your test running in the JUnit window, and you can view the results in the "JUnit" tab in the bottom panel of Eclipse.
@priyajain8715
@priyajain8715 3 года назад
Hi raghav, when we apply order what is the priority that is being followed?Is it that sequence is only followed?,like 0 followed by 1,2,3 and so on.i had applied order for beforestep tag and afterstep tag
@RaghavPal
@RaghavPal 3 года назад
Hi Priya, ya the priority is lower no to higher no
@creativestuff3914
@creativestuff3914 3 года назад
Much thanks sir..
@RaghavPal
@RaghavPal 3 года назад
Most welcome
@techmaticsystems1141
@techmaticsystems1141 Год назад
Hello Raghav, Your Videos is was very helped to me.I One doubt have. How I can use if -else loop in Cucumber BDD framework.?
@RaghavPal
@RaghavPal Год назад
Hi, check this stackoverflow.com/questions/30233391/does-if-else-concept-available-in-feature-file-gherkin-language
@techmaticsystems1141
@techmaticsystems1141 Год назад
@@RaghavPal Thanks for you update
@farukhalvi1988
@farukhalvi1988 2 года назад
Hi Raghav please create a tutorial for Behave BDD hooks as well
@RaghavPal
@RaghavPal 2 года назад
Sure Farrukh
@madhusudhanreddy6716
@madhusudhanreddy6716 3 года назад
Hello ragav could you do videos on regular expressions
@RaghavPal
@RaghavPal 3 года назад
Sure will do, I wrote a story on Regex here - automationstepbystep.com/2020/05/05/a-story-of-regex/
@madhusudhanreddy6716
@madhusudhanreddy6716 3 года назад
@@RaghavPal tq sir
@tekinavyadeepthi8944
@tekinavyadeepthi8944 2 года назад
Please upload a video of cucumber with testng test
@shreedeevi2800
@shreedeevi2800 2 года назад
Hi sir, can you tell me, how to write code for initiation of webDriver incase of multiple step definitions are present
@RaghavPal
@RaghavPal 2 года назад
Hi Shree, you can use hooks as shown or use if else within the step definition
@ankitshrivastava1772
@ankitshrivastava1772 Год назад
Hello Rachav, does cucucmbe has the hooks at feature file level ?
@RaghavPal
@RaghavPal Год назад
Ankit No, Cucumber does not have hooks at the feature file level. Hooks are blocks of code that run before or after each scenario or step. They can be used to perform common tasks, such as setting up the environment or cleaning up after the test. In Cucumber, hooks are defined in the step definition files. There are two types of hooks: * **Before hook:** This hook runs before each scenario. * **After hook:** This hook runs after each scenario. You can also define hooks that run before or after each step. These are called step hooks. The following is an example of a before hook: ``` @Before public void setup() { // Set up the environment } ``` The following is an example of an after hook: ``` @After public void teardown() { // Clean up after the test } ``` You can define hooks in any class that is imported by your step definition files. However, it is best to define them in a separate class so that they are not cluttered with your step definitions. I hope this helps
@radhasubbu7476
@radhasubbu7476 2 года назад
Hi @Raghav and @Automation Step by Step, Thanks for this session. In this you have shown @Before and @After hooks for one feature file only which have multiple scenarios. But is that possible for this below scenario? I have multiple feature files with multiple scenarios inside. In this case do I need to add @Before and @After annotations in each feature file or can we use @Before and @After annotations in Runner class or one of the util class ?? Please comment on it or If it's possible upload a video on it Thanks :)
@RaghavPal
@RaghavPal 2 года назад
Hi Radha, I will check and try to do a session on this
@radhasubbu7476
@radhasubbu7476 2 года назад
@@RaghavPal , Thank you Raghav for reply. Yaa if possible let us know :)
@ayzu7670
@ayzu7670 3 года назад
First of all thanks for the wonderful lectures. I had a doubt though. If we want to use pagefactory and hooks concept in same project then is it possible? Because when I try doing it the hooks get executed but control never shifts back to @Given statement of feature file in stepDefinition package.
@RaghavPal
@RaghavPal 3 года назад
I will need to check on this
@mohammedirfan4308
@mohammedirfan4308 Год назад
Sir, i am getting Type mismatch: cannot convert from String[] to String error when i define tags in runner file. please help
@RaghavPal
@RaghavPal Год назад
Hi Irfan, pls check this stackoverflow.com/questions/63742061/cucumber-tags-type-mismatch-cannot-convert-from-string-to-string
@adarshs3334
@adarshs3334 2 года назад
i'm getting this error [io.cucumber.junit.UndefinedStepException: The step 'user is on login page' and 3 other step(s) are undefined. You can implement these steps using the snippet(s) below:] After i executed the Testrunner of hooks
@RaghavPal
@RaghavPal 2 года назад
Hi Adarsh, check if all steps in feature file and implemented in step definition and correct paths are given in runner file
@LouisKKC
@LouisKKC 3 года назад
Hello, Raghav, I am getting stuck in Katalon Cucumber using Java/Groovy when trying to share data in each hook and each steps definition. I had tried using Cucumber with Ruby before. Let say I can create a file called hooks.rb for those before and after hooks. I can share all those variables to other hooks or even steps definitions. The variable updates also reflect to next step definitions or hooks. How can I do that in Katalon Cucumber?
@RaghavPal
@RaghavPal 3 года назад
Hi Louis, I have done BDD Cucumber in Katalon, but yet to check on Hooks, I will need to check on this, Meanwhile pls see if you get online help
@tfttma7403
@tfttma7403 Год назад
Hi all, between @Before (Hooks) and @BeforeClass (TestNG Runner), which item will run first?
@RaghavPal
@RaghavPal Год назад
Hi, In general, the *@BeforeClass* method will be run before the *@Before* hook This is because the @BeforeClass (TestNG) method is executed before any test methods are run, while the @Before (cucumber) hook is executed before each individual scenario For example see this code: /* import cucumber.api.java.Before; import org.testng.annotations.BeforeClass; public class MyTestClass { @BeforeClass public void beforeClass() { System.out.println("Before class method"); } @Before public void before() { System.out.println("Before hook"); } @Test public void test1() { System.out.println("Test 1"); } @Test public void test2() { System.out.println("Test 2"); } } */ When this test class is run, the output will be: /* Before class method Before hook Test 1 Before hook Test 2 */ Let me know if you have any more doubts
@tfttma7403
@tfttma7403 Год назад
@@RaghavPal and I think order execution will be @Before Suite -> @Before Test -> @Before Class -> @Before Method -> @Before (Hook) -> @Test -> @After (Hook) -> @After Method -> @After Class -> @After Test -> @After Suite
@jhonpaul2881
@jhonpaul2881 2 года назад
Thank you Raghav Please let me know how to print cucumber step in java
@RaghavPal
@RaghavPal 2 года назад
Hi Jhon, what exactly are you looking for
@RaghavPal
@RaghavPal 2 года назад
Hi Jyoti, I will need to check on this
@sohaibcool
@sohaibcool 3 года назад
Hi Raghav, very beautiful explanation, had a question I have a java Junit framework with this method can I convert existing Junit project to cucumber or do I need to change something else?
@RaghavPal
@RaghavPal 3 года назад
Hi Sohaib, you will need to add cucumber dependencies and then create feature files. On the other hand why do you want to do this, if you want to implement BDD, it is a process and Cucumber is will only help in automation not the entire BDD process.
@sohaibcool
@sohaibcool 3 года назад
Hi Raghav, thanks for the reply, I would like to convert to the BDD cucumber framework because to create beauty test reports on Jenkins dashboard which believe we can't do it using JUnit framework?
@RaghavPal
@RaghavPal 3 года назад
Okay, you can do that, you will have to add cucumber dependency and then add features and scenarios that will be the wrapper over your code and the code goes into step definitions. Now make sure that your team and management approves this. As I said BDD is not just doing automation using Cucumber and features files, It has to be implemented at organisation level to get its actual benefits.
@sohaibcool
@sohaibcool 3 года назад
@@RaghavPal it was based on team request. Thanks for reply.
@RaghavPal
@RaghavPal 3 года назад
Okay, I will be creating the videos to understand BDD process next week and when and how should BDD start in an Organization, That will be useful
@adventures2880
@adventures2880 2 года назад
👌
@RaghavPal
@RaghavPal 2 года назад
Thanks for watching
@pillulove
@pillulove 3 года назад
if we have multiple step def, then we will be writing hooks in every step def?
@RaghavPal
@RaghavPal 3 года назад
Hi Nidhi, you can use hooks for multiple tests, Check this stackoverflow.com/questions/40720548/how-to-use-hooks-in-cucumber
@pillulove
@pillulove 3 года назад
@@RaghavPal - I didn't quite understand the discussion mentioned in the link. My question was if we have multiple step def, then we will be writing Before and After in every step definition.
@RaghavPal
@RaghavPal 3 года назад
Hi Nidhi, in case you need to have a before and after only once before all step def and after all step def you can do that AND if your need is to do a setup and teardown with every step def, you can do that too, Can check some examples online for this
@aakashamatya3580
@aakashamatya3580 3 года назад
@Before("@smoke", order=1) - - I get compile time error in this line, but in the video it is okay. The error is - "Syntax Error on token "@smoke", Invalid MemberValuePairs". Appreciate any help. Thank you in advance.
@RaghavPal
@RaghavPal 3 года назад
Hi Aakash, mostly this should be related to some syntax, pls check again with the video or use some online examples
@divyadoddagoudar5153
@divyadoddagoudar5153 3 года назад
Raghav could please share how to run scenarios from same feature file/different feature files in parallel mode?
@RaghavPal
@RaghavPal 3 года назад
I will plan Divya
@Arul-pk4xk
@Arul-pk4xk 5 месяцев назад
Hi raghav iam getting error while writing tags in testrunner class inside curly braces
@RaghavPal
@RaghavPal 5 месяцев назад
Arul will need to check the error message and logs
@mohdjaveedali7336
@mohdjaveedali7336 3 года назад
Hi sir, plz make a video on java collection ?
@RaghavPal
@RaghavPal 3 года назад
Will do soon
@ankitgupta-gk6yh
@ankitgupta-gk6yh 3 года назад
Hi Raghav, Please share the GitHub link.
@RaghavPal
@RaghavPal 3 года назад
Hi Ankit, here you are github.com/Raghav-Pal/SeleniumCucumberBDD github.com/Raghav-Pal/CucumberBDDCMD You can see the readme to know for which youtube playlist is this project for
@ankitgupta-gk6yh
@ankitgupta-gk6yh 3 года назад
@@RaghavPal wonderful explanation, your video raise confidence in my mind
@RAHULSHARMA-pv2nt
@RAHULSHARMA-pv2nt 8 месяцев назад
can we use testNG annotations in cucumber?
@RaghavPal
@RaghavPal 8 месяцев назад
Rahul While Cucumber doesn't directly support TestNG annotations within step definitions, here are effective approaches to integrate their functionalities: 1. Leveraging Cucumber Hooks: - Scenario Hooks: - `@Before`: Execute code before each scenario. - `@After`: Execute code after each scenario. - Step Hooks: - `@BeforeStep`: Execute code before each step. - `@AfterStep`: Execute code after each step. 2. Employing QAF (Qmetry Automation Framework): - Integrates Cucumber with TestNG, enabling use of TestNG annotations for: - Listeners - Data providers - Groups - Prioritization 3. Using TestNG Factory: - Configure a TestNG factory for Cucumber execution. - Allows usage of TestNG annotations for listeners and lifecycle methods. Key Considerations: - Cucumber Recommendations: It's generally recommended to use Cucumber's own hooks for setup and teardown to maintain consistency within the framework. - QAF Benefits: QAF offers a seamless integration, treating each Cucumber scenario as a TestNG method, granting access to TestNG features. - Trade-offs: Weigh the advantages of TestNG functionalities against potential complexities and potential conflicts with Cucumber's approach. Choose the approach that best aligns with your project's specific requirements and team preferences.
@RAHULSHARMA-pv2nt
@RAHULSHARMA-pv2nt 8 месяцев назад
thank you so much ,you are doing greatwork @@RaghavPal
@prafullvispute8450
@prafullvispute8450 3 года назад
add video on cypress.io
@RaghavPal
@RaghavPal 3 года назад
Sure I will do Prafull
@vikrantchaudhari7017
@vikrantchaudhari7017 3 года назад
It seems that you are still using J2SE 1.5
@RaghavPal
@RaghavPal 3 года назад
Hi Vikrant, 1.5 and 1.8 both are available
@sumalathadandy5017
@sumalathadandy5017 3 года назад
Hello
@RaghavPal
@RaghavPal 3 года назад
Hi, let me know if you have any questions Sumalatha
@Knaga-qs3pu
@Knaga-qs3pu Год назад
Automation testing jobs any freshers sir please
@RaghavPal
@RaghavPal Год назад
Hi, I am not aware on that
@Knaga-qs3pu
@Knaga-qs3pu Год назад
@@RaghavPal OK thanks so much sir
@sidb2023
@sidb2023 2 года назад
Hi Raghav, same code in runner classes is giving different results w.r.t. report. one runner class is generating report and other is not. working: package StepDefinitions; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions (features="src/test/resources/Features", glue={"StepDefinitions"}, monochrome = false, plugin = {"html:target/report/htmlReport.html"} ) public class TestRunner { } Not Working: package StepDefinitionForHooksPackage; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features = {"src/test/resources/FeaturesWithHooks"}, glue={"StepDefinitionForHooksPackage"}, monochrome=false, plugin = {"html: target/report/report.html"}) public class TestRunnerForHooks { }
@RaghavPal
@RaghavPal 2 года назад
Hi Siddharth, will need to check the setup and execution details. Check again if anything is missed
Далее
ALL React Hooks Explained in 12 Minutes
12:21
Просмотров 128 тыс.