Giter VIP home page Giter VIP logo

bazylmn / cucumber-java-webdriver-manager Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 4.0 14 KB

Cucumber-java-webdriver-manager template with Cucumber-java8, Cucumber Spring, Selenide library and webdriver manager (Selenium WebDriver)

Java 89.80% Gherkin 10.20%
cucumber cucumber-java cucumber-spring selenide selenium-webdriver selenium-page-factory lambda-expressions java8-lambda-expression

cucumber-java-webdriver-manager's Introduction

Cucumber-java-webdriver-manager template

with Cucumber-java, Cucumber Spring, custom annotation @PageObject, lambda expression ready, Selenide library and webdriver manager (Selenium WebDriver) for:

  • chrome
  • firefox
  • chrome headless
  • iexplorer

Prerequisites

  • gradle
  • Cucumber for Java plugin for IntelliJ
  • Gherkin for IntelliJ
  • chromedriver.exe (put it into project root)- chrome is set as default browser
  • geckodriver.exe (put it into project root)- is needed for newer FF versions
  • IEDriverServer.exe (put it into project root)

Initial

  • clone repository
  • open build.gradle file in IDE (IntelliJ)
  • import dependencies with gradle

Customise Cucumber tests

  • add your .feature files with scenarios
  • create custom steps class / steps classes with @Autowired annotations for page objects class / classes
  • generate steps- in .feature file press 'alt+enter' shortcut and choose 'Create step definition' option, choose created steps class / steps classes to paste steps
  • create custom page objects classes with methods and with @Component and @Autowired annotations for webdriver manager
  • create assertions classes with methods and @Component annotation
  • delete example .feature files, steps classes, page objects classes and assertion classes

Custom annotation @PageObject

Add @PageObject in page object classes instead of Spring @Component annotation

Lambda expression ready

Steps classes implements En interface and are prepared to use code by 'lambda-way'. Example of lambda expression is used in SignUpFormPageObjects class:

    private void sendKeysForInputWithAttrubuteName(String partValueName, String keyToSend){
        webDriverManager.getDriver().findElements(By.cssSelector(USER_INPUT))
                .stream()
                .filter(elem->elem.getAttribute(USER_INPUT_ATTRIBUTE_NAME).contains(partValueName))
                .findFirst()
                .get()
                .sendKeys(keyToSend);
    }

How to use Selenide

If there is a need to use Selenide as a driver provider to find elements or take an action, simply add one line in a page object method:

WebDriverRunner.setWebDriver(your initialized driver);

A method in template, which is using Selenide to find element might look like below (there is used 'setWebDriver(driver)' method):

    @Autowired
    private WebDriverManager webDriverManager;

    private static final String JAM_MENU = ".Header-nav-item[href*=jam]";

    public void clickJamMenu(){
        WebDriverRunner.setWebDriver(webDriverManager.getDriver());
        $(JAM_MENU).click();
    }

Or paste the method 'setWebDriver(driver)' in the WebDriverManager class like below and use Selenide as a driver provider across the project, mixing it with Selenium WebDriver (you can use both in methods):

            (...)
            default:
                System.getProperty("browser", "chrome");
                System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
                webDriver = new ChromeDriver();
                break;
        }
        WebDriverRunner.setWebDriver(webDriver);
        return webDriver;
    }

The method 'getWebDriver()' in WebDriverManager class is already configured to use Selenide library. You can choose which way Selenide is going to be used in project (only partially in particular method or globally with WebDriverManager class)

How to run tests:

With gradle command:

To run Cucumber tests with custom runTests task and with default browser, type:
 runTests
To run Cucumber tests with custom runTests task and with chosen browser, type:
-Dbrowser=chrome runTests
-Dbrowser=firefox runTests
-Dbrowser=chromeHeadless runTests
-Dbrowser=iexplorer runTests
To run Cucumber tests with default browser, type:
clean test
To run Cucumber tests with chosen browser, type:
clean -Dbrowser=chrome test
clean -Dbrowser=firefox test
clean -Dbrowser=chromeHeadless test
clean -Dbrowser=iexplorer test

With IDE (JUnit):

run CucumberRunner class
or run .feature file / directory with .feature files / scenario in .feature file

Reports and screenshots

Reports are placed in 'target' directory, including screenshots of failed scenarios. To run report in browser, open 'target\html\index.html' file and choose browser.

Gradle custom tasks

  • runTests
  • deleteCucumberReports

cucumber-java-webdriver-manager's People

Contributors

bazylmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.