GithubHelp home page GithubHelp logo

kochetkov-ma / selenide-pages Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 93 KB

Page Object Model mini Framework for Selenide

License: Apache License 2.0

Java 10.43% Kotlin 89.57%
kotlin java selenium selenide docker pageobject kotest

selenide-pages's Introduction

Maven Central

Selenide pages

selenide pages

Framework based on Selenide provided convenient functional to create and manage your app Page Objects in automation testing.

Description

  • Quickly creating a convenient, extensible PageObject hierarchy based on Selenide.
  • Additional functionality for working with a page and organizing elements structure.
  • Kotlin DSL for Page Object, and fully compatible with Java 11
  • Cucumber steps for using Page Objects

Modules

Main module

Cucumber steps provided selenide-pages-core and Selenide functions in Gherkin features

Example of use on Kotlin and Java

Very interesting! Have a look before using ...

Getting started

Add dependency

Add selenide-pages-core dependency and your favorite testing framework for example junit-jupiter

dependencies {
    testImplementation "org.brewcode:selenide-pages-core:1.0.0"
    testImplementation "org.junit.jupiter:junit-jupiter:5.8.2"
}

The selenide-pages-core brings with transitive dependencies:

  • selenide
  • selenium 4
  • chrome driver (without another drivers sush as firefox or edge)
  • awaitility
  • kotlin
  • kotest assertions
  • slf4j

The dependencies above are necessary for the operation of our library. But you can disable it and override

dependencies {
    testImplementation("org.brewcode:selenide-pages-core:1.0.0") { transitive false }
}

Create first page

/**
 * Define selenide page via @Page annotation. Must extend BasePage class.
 * 
 * value = "Getting Started" - page name for log message
 * path = "/tutorial/" - expected path. Will check on page open verify, and will append when open this page
 * expectedTitle = "Getting Started" - The title text will check on page open verify
 */
@Page(value = "Getting Started", path = "/tutorial/", expectedTitle = "Getting Started")
public class DockerGettingStartedMainPage extends BasePage<DockerGettingStartedMainPage> {

    /**
     * Create element collection.
     * With alias "Paragraphs" to use in log messages.
     * Search by tag name.
     * 
     * "required = true" - This element must be visible on the page after loading. When you open the page, this element must be visible, otherwise an error will occur
     */
    @Element(value = "Paragraphs", tagName = "h2", required = true)
    public ElementsCollection paragraphs;

    public GettingStartedNavigation gettingStartedNavigation;

    /**
     * The page block defined.
     * Must extend Block class.
     * 
     * Be aware - @Element annotation uses on class instead of field. 
     * But you may use field annotation and field annotation has a higher priority.
     */
    @Element(value = "Getting started navigation", css = "nav.md-nav--primary>ul")
    public static class GettingStartedNavigation extends Block {

        /**
         * Collection of page blocks.
         */
        @Element(value = "Пункты навигации", xpath = "./li")
        public Blocks<NavigationItem> navigationItemList;
    }

    public static class NavigationItem extends Block {

        @Element(value = "Navigation item", tagName = "a", required = true)
        public SelenideElement gettingStartedNavigation;
    }
}
  • Use @Page annotation on page class
  • Your page class must inherit the BasePage with parameter as self class
  • Use @Element annotation for SelenideElement, Block and Blocks<T>
  • Your block class must inherit the Block

Create test

public class FunctionalTest {

    @Test
    public void test() {
        final Pages pages = Pages.PagesFactory
            .createWithStaticSelenideDriver("http://localhost"); // Create Page Factory
        final DockerGettingStartedMainPage page = pages
            .page(DockerGettingStartedMainPage.class) // Create page
            .open() // open page with path from @Page annotation
            .verify(); // verify that page opened successfully, url is correct, title is expected, all required elements is displayed
        
        // interact with element collection and check third element text is not empty
        page.paragraphs.get(2).shouldNotBe(empty);

        // get block
        final GettingStartedNavigation block = page.gettingStartedNavigation;
        block.navigationItemList.getSelf().shouldHave(sizeGreaterThan(0)); // check that list is loaded
        block.navigationItemList.get(1).gettingStartedNavigation.should(appear); // get element and check
    }
}

Advanced Usage

in progress ...

Kotlin DSL

Support

Kochetkov Maxim - [email protected]

Roadmap

Cucumber steps module - expected release date 30.01.2022

Contributing

Mail to me [email protected], and I will add you to GitLab Group

Authors and acknowledgment

Kochetkov Maxim - [email protected] Frolov Sergey - tbd

License

Apache License 2.0

Project status

Released on January 2021

ACTIVE DEVELOPING

selenide-pages's People

Contributors

crazymoonkin avatar kochetkov-ma avatar

Stargazers

 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.