We can run precondition and postcondition test methods with the help of @Before and @After hooks in Cucumber.ExampleFeature file.Feature: Transaction Table Scenario: Verify the monthly transactions Given User is on the Payment PageStep Definition has methods with hooks @Before and @After. The test method with hook @Before will be executed as a precondition then the test method (naviagteToPayment() method) will run and finally the test method with hook @After which is the postcondition will execute.Example@Before public void method1(){ System.out.println("The precondition executed successfully"); } @After public void method2(){ System.out.println("The postcondition executed successfully "); } @Given ("^User is on payment ... Read More
We can include and exclude test methods from a set of test cases in Cucumber by tagging scenarios in the feature file.ExampleFeature file.@Tutorialspoint Testing Feature: Login Feature Testing @Smoke Scenario: Home Page Testing Given User is in home page @CodingModule Scenario: Coding Module Testing Given User is in Coding Module PageThe test runner file has tags Smoke to be excluded and CodingModule to be included in the execution.Exampleimport org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import cucumber.api.testng.AbstractTestNGCucumberTests; @RunWith(Cucumber.class) @CucumberOptions( features = “src/test/java/features”, glue = “stepDefiniations” tags = {“~@Smoke”, “@CodingModule”} )Read More
We can skip a particular test method from execution in Cucumber with the help of tagging of scenarios in the feature file.Examplefeature file.@Regression Feature: Invoice Testing @Smoke Scenario: Login Verification Given User is in Home Page @Payment Scenario: Payment Testing Given User is in Payment PageFeature file with scenarios having tags Smoke and Payment.Exampleimport org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import cucumber.api.testng.AbstractTestNGCucumberTests; @RunWith(Cucumber.class) @CucumberOptions( features = “src/test/java/features”, glue = “stepDefiniations” tags = { “~@Payment”} )To skip the scenarios with @Payment , ~ is placed before the @Payment tag in Test Runner file.Read More
We can set the order of execution for test methods in Cucumber with the help of order keyword. Test methods are assigned with order in the step definition file.The test method with lower order executes first followed by the methods with higher orders.ExampleStep definition file.@Before (order = 1) public void login(){ System.out.println("login is successful"); } @Before (order = 2) public void payment(){ System.out.println("payment is successful"); } @Given ("^Land in repayment page$") public void repay(){ System.out.println ("Actual Scenario of repayment"); }The test method with lower order (login() set to 1) will be executed first. Then payment () test ... Read More
We use the Scenario Outline keyword in the feature file in Cucumber. If a particular scenario needs to be executed with more than a set of data in multiple combinations, then we use the Scenario Outline.The multiple data sets are represented in form of a table separated by (||) symbol under Examples keyword. Each row represents a group of data.ExampleFeature file.Feature: Login Verification Feature Scenario Outline: Login Verification Given User lands on the home page When Page title is Tutorialspoint Then User keys in "" and "" Examples: | username | password | | Selenium | t123 ... Read More
The main file components in Cucumber are listed below −Feature file − This file has an extension of .feature. It comprises single or multiple test scenarios in plain text. All the scenarios are written with the keywords like Then, Given, When, And, But, Feature, Background and so on.ExampleFeature file.Feature: Login Test Scenario: Tutorialspoint login validation Given: Launch the “https://www.tutorialspoint.com/index.htm”Step Definition File - This file has an extension of .java. It provides mapping of the test scenarios to the test script logic.ExampleStep Definition file based on the above feature file.@Given (“^Launch the \"([^\"]*)\"$”) public void launch_application(String url){ System.out.println("The url is ... Read More
Some of the advantages of using Cucumber are listed below −Cucumber is an open source tool and does not require licensing.Cucumber can be easily configured with IDEs like Eclipse.Cucumber bridges the understanding and communication gaps among developers, testers, business analysts, customers and product owners.Cucumber enables the participation of business stakeholders who do not have technical knowhow.Cucumber gives plain text representation which enables easy understanding for non-technical members in the team.Cucumber is easy to maintain and is scalable.Cucumber increases the reusability of important steps.Cucumber promotes teamwork since each individual in the team can contribute.Cucumber uses the Gherkin tool which is simple ... Read More
We can combine multiple groups to single Test in TestNG with the help of test group feature.ExampleTestng xml files with groups. To run a group of test cases from the collection of test cases, we have to define in the testng xml file. Here the testNG xml contains multiple groups QuestionAnswer and Jobs to be associated to a single Test.Example@Test(groups={"QuestionAnswer"},{"Jobs"}) public void preparation(){ System.out.println("Preparation module is verified"); }In the Java class file the test methods with group as QuestionAnswer and Jobs are associated with the test method preparation().
TestNG Listeners have the capacity to listen to a specific incident. It is basically an interface that changes the nature of the system. TestNG Listeners are used for logging purposes and creating reports.There are two Listeners in Selenium. They are listed below −TestNG Listeners.WebDriver Listeners.TestNG can be configured with the Listeners which can change the default behavior of the TestNG. TestNG Listeners are known as iTestListener (a TestNG interface). A java class implements the iTestListeners and at the same time overrides its methods. Each of these methods trigger an event.The functions of TestNG listeners are listed below.iSuiteListener − This consists ... Read More
We can achieve parallel execution with the help of TestNG. There is a parallel attribute in TestNG which is used for this implementation. The parallel execution in TestNG is associated with another attribute called thread-count.The parallel attribute can have the values listed below −Methods.Classes.InstancesTestsExampleTestng xml file. The execution will trigger in parallel mode for tests with the thread count of 5.
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP