Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timboudreau/giulius-selenium-tests
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
https://github.com/timboudreau/giulius-selenium-tests
fixtures guice junit selenium
Last synced: 2 months ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/timboudreau/giulius-selenium-tests
- Owner: timboudreau
- Created: 2013-04-07T22:42:31.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T08:37:09.000Z (over 1 year ago)
- Last Synced: 2023-12-04T15:27:20.221Z (about 1 year ago)
- Topics: fixtures, guice, junit, selenium
- Language: Java
- Size: 181 KB
- Stars: 12
- Watchers: 7
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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](http://code.google.com/p/google-guice/)
and Selenium's own injection to create test fixtures. It extends
[Giulius-Tests](https://github.com/timboudreau/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](https://github.com/timboudreau/giulius-selenium-tests/blob/master/selenium/src/test/java/com/mastfrog/selenium/TestSeleniumTest.java) 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](http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html?org/openqa/selenium/support/PageFactory.html) 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).