Giter Site home page Giter Site logo

rtatol / giulius-selenium-tests Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timboudreau/giulius-selenium-tests

0.0 2.0 0.0 165 KB

A test harness that allows Selenium tests to be run using JUnit and test fixtures to be created and injected by a WebDriver-aware Guice

Groovy 1.85% Java 98.15%

giulius-selenium-tests's Introduction

giulius-selenium-tests

An easy way to write Selenium tests in Java, have objects representing web page contents be created and injected by Guice + WebDriver, and use any JUnit reporting engine with Selenium

Builds and a Maven repository containing this project can be found on timboudreau.com.

Overview

This library makes it easy to write Selenium tests in Java. These tests are run using JUnit (which makes reporting simple). It can utilize both Google Guice and Selenium's own injection to create test fixtures. It extends Giulius-Tests, a test-harness for writing Guice-aware JUnit tests to make the framework Selenium-aware as well.

This means that test methods can have method parameters, and the framework will pre-create objects that you want to test. You write test code to test what matters, and the framework does the rest.

To see what these tests look like, check out this test which is part of the test-suite for this project.

Here's a test which tests a fake search page. That page contains a form with a text field with the ID searchField, a submit button with the ID searchSubmit and a span with the ID prev which contains the previously submitted form. This test uses a test fixture - a class called MyPageModel which contains fields representing each of those HTML elements.

The nice thing about this is that you never have to write code to create any of the objects in question - the framework creates them for you. So writing tests remains focused on writing code that actually tests something:

@Test
@Fixtures( LoginFixture.class ) // do the login steps ahead of time
public void foo( MyPageModel page, WebDriverWait wait ) {
    page.searchField.sendKeys ( "giulius" );
    page.searchButton.click ();
    assertEquals ( "giulius", page.prev.getText() );
}

MyPageModel is a Selenium model for the content of the page, written just the way you normally do with Selenium tests.

The difference is that the framework sees that this class is an argument to your test method, and it scans its fields and notices that there are Selenium annotations on them. So it uses Selenium's PageFactory to instantiate the object, and then uses Guice to inject any other objects you might have included in it (remember to use @Inject on such fields).

The result is that you never have to write code to instantiate this class ourselves - you just mention it as a test method parameter and the rest is handled for you.

public class MyPageModel {
    @FindBy(how = How.ID, using = "searchField")
    @CacheLookup
    public WebElement searchField;
    @FindBy(how = How.ID, using = "searchSubmit")
    public WebElement searchButton;
    @FindBy(how = How.ID, using = "prev")
    public WebElement prev;
}

You may have noticed the annotation:

@Fixtures (LoginFixture.class)

That annotation is a way of saying "I don't need one of these passed to me, but I need you to make one before my test method runs". The test harness will construct an instance of LoginFixture. As a side-effect of constructing it, it logs into the web page, so that the page is ready to do the things we want to test.

Groovy

The groovy-selenium-guice-demo shows an example of writing Selenium tests injected by Guice in Groovy and run in JUnit, and recording a screen-capture video while doing so (requires ffmpeg).

The test-main project provides a simplified JUnit runner suitable for running tests as a standalone process (Selenium tests are not usually part of a unit test suite).

giulius-selenium-tests's People

Contributors

rtatol avatar timboudreau avatar

Watchers

 avatar  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.