Git Product home page Git Product logo

sellotape's Introduction

Sellotape

Thin wrapper for selenium which automatically resolves timing errors and "Element not found in DOM" exceptions.

To compile

Build the library using ./gradlew. Jar is output in build/libs. Let me know if you're interested in having this packaged up for maven, gradle, etc.

To use

Extend the class SeleniumTest, which automatically starts a webdriver available as driver. Add your tests, which must start with the prefix 'test'.

SeleniumTest takes a screenshot of every test on success and failure. The screenshots are written to the directory specified by property screenshot.dir (default /tmp/sellotape-screenshots).

The following methods are available in SeleniumTest:

void takeScreenshot(name)

Takes extra screenshot named screenshot-{name}.png

WebElement waitForId(String id, int seconds = 10)

Waits {10 seconds} for visible element with html id of {id}.

Returns an element which can be acted on with click(), clear(), sendKeys(), or any other WebElement method.

WebElement waitForXpath(String xpath, int seconds = 10)

Waits {10 seconds} for visible element with xpath of {xpath}.

Returns an element which can be acted on with click(), clear(), sendKeys(), or any other WebElement method.

WebElement waitForSelector(String css, int seconds = 10)

Waits {10 seconds} for visible element with CSS selector of {css}.

Returns an element which can be acted on with click(), clear(), sendKeys(), or any other WebElement method.

WebElement waitForText(String text, int seconds = 10)

Waits {10 seconds} for visible element containing text {text}.

Returns an element which can be acted on with click(), clear(), sendKeys(), or any other WebElement method.

WebElement hoverOver(WebElement element)

Hover over the given element.

Returns the input element for chaining actions such as click().

void pageShouldNotContain(String text)

Assert that {text} is not visible on the page.

def Wait(int seconds = 10)

Wait {10 seconds} for the chained closure to become true.

Example: Wait().until(buildCondition {el.getAttribute("value") == '150.00'})

static def buildCondition(Closure code)

Wraps a closure ready for use by Wait().

Example: Wait().until(buildCondition {el.getAttribute("value") == '150.00'})

Configurable properties

  • selenium.driver Currently allows firefox (default) or phantomjs.
  • screenshot.dir Directory for output screenshots (default /tmp/sellotape-screenshots).

Example

package net.ulfheim.sellotape.examples

import net.ulfheim.sellotape.SeleniumTest
import org.openqa.selenium.Keys


class GoogleTest extends SeleniumTest {
    void testSearch() {
        // go to site
        driver.get('http://www.google.com')

        // type search into input
        waitForSelector('input[type="text"]').sendKeys('xyz' + Keys.ENTER)

        // wait only 1 second for element to exist (default wait is 10 seconds)
        waitForText('results', 1)

        // clear the search at top of page
        waitForXpath('//input[@type="text"]').clear()

        pageShouldNotContain('results')
    }
}

sellotape's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

morristech

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.