TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    JBehave

    Cucumber Java BDD Selenium Framework

    Overview

    Let’s learn the steps involved in creating Cucumber Java BDD Selenium Project using Eclipse IDE in this tutorial.

    Create a Maven Project

    Create a New Project Eclipse

    Configure the Project

    Specify the Group ID, Artifact ID, Version and Packaging format for the project.

     

    Cucumber Java

     

    Cucumber Java BDD Dependencies

    Add the below dependencies to the Maven project file pom.xml.

    <dependencies>
     <dependency>
     <groupId>io.cucumber</groupId>
     <artifactId>cucumber-java</artifactId>
     <version>6.8.1</version>
     </dependency>
     <dependency>
     <groupId>io.cucumber</groupId>
     <artifactId>cucumber-junit</artifactId>
     <version>6.8.1</version>
     <scope>test</scope>
     </dependency>
     <dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.13</version>
     <scope>test</scope>
     </dependency>
     <dependency>
     <groupId>org.seleniumhq.selenium</groupId>
     <artifactId>selenium-java</artifactId>
     <version>3.141.59</version>
     </dependency>
     </dependencies>

     

     

    Eclipse plugin for Cucumber

    Instructions to install Cucumber Eclipse Plugin can be found here:

    https://www.testingdocs.com/questions/how-to-install-cucumber-eclipse-plugin/

    Add Gherkin Steps

    #Sample Demo Feature file
    #www.TestingDocs.com
    
    Feature:
     Browse Google search page, and search for a query,
     The search results should show the results about search query.
    
    Scenario:
     Given that I go to Google search page
     When I add "testingdocs" to the search textbox
     And Click the Search Button
     Then "testingdocs" related results should show up

     

    Add Step Definitions

    Step definitions are methods or code that connect Gherkin steps.

    package Steps;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.ExpectedCondition;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    import io.cucumber.java.After;
    import io.cucumber.java.en.Given;
    import io.cucumber.java.en.Then;
    import io.cucumber.java.en.When;
    
    public class GoogleSearchSteps {
     private final WebDriver driver = new ChromeDriver();
     WebElement element;
     @Given("that I go to Google search page")
     public void that_i_go_to_google_search_page() {
     System.out.println("Google Search page");
     driver.get("https://www.google.com");
     }
    
     @When("I add {string} to the search textbox")
     public void i_add_to_the_search_textbox(String string) {
     System.out.println("Type Search Keyword");
     element = driver.findElement(By.name("q"));
     element.sendKeys(string);
    
     }
    
     @When("Click the Search Button")
     public void click_the_search_button() {
     System.out.println("Click Search Button");
     element.submit();
     }
    
     @Then("{string} related results should show up")
     public void related_results_should_show_up(final String title) {
     System.out.println("Google Search Results Page");
     new WebDriverWait(driver,30L).until(new ExpectedCondition<Boolean>() {
     public Boolean apply(WebDriver d) {
     return d.getTitle().toLowerCase().startsWith(title);
     }
     });
     }
    
     @After()
     public void closeBrowser() {
     driver.quit();
     }
    
    }

     

    Cucumber Test Runner

    Create a Test Runner class. Add the following code. Specify the feature file location to Cucumber.

    package Steps;
    
    import org.junit.runner.RunWith;
    import io.cucumber.junit.Cucumber;
    import io.cucumber.junit.CucumberOptions;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(features="src/test/resources/Features",glue= {"Steps"})
    public class CucumberTestRunner {
    
    }

    Download Browser Driver

    We need to download Browser driver depending on where and how the test is run. For example Download Chrome Driver executable .exe file to Test on Google Chrome browser on Windows operating system.

    Download URL:

    https://sites.google.com/a/chromium.org/chromedriver/

    Copy the driver executable to the project root folder.

    Run the Tests

    Run the tests as JUnit tests.

    Cucumber Selenium Tests

     

    —

    JBehave Tutorials on this website can be found at:
    https://www.testingdocs.com/jbehave-framework-tutorial/

    For more details on Cucumber, visit the official website at:

    https://cucumber.io/

    Related Posts

    JBehave + Serenity Sample Project

    JBehave /

    JBehave + Serenity Sample Project

    Serenity BDD Automation Framework

    JBehave /

    Serenity BDD Automation Framework

    Serenity Maven Artifacts

    JBehave /

    Serenity Maven Artifacts

    Introduction to Serenity BDD

    JBehave /

    Introduction to Serenity BDD

    Jbehave Ubuntu

    JBehave /

    Install JBehave Plugins on Ubuntu

    ‹ JBehave + Serenity Sample Project

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com