Screen Pill - skinnyjames/screen-pill GitHub Wiki
What are Page Objects?
Page Objects are ways of encapsulating / abstracting the functionality involved with interacting with a Web Page.
Page Objects are useful in functional test suites where complex interactions with web pages may be pushed down into the Page Object container, making clear and concise tests.
screen-pill
is a library for creating page objects, extending numerous accessors with easy to use functionality.
For an example of a test suite written with cucumber-js, selenium, and screen pills, check out the test
folder in this repository
basic usage
//foo-page.js
const ScreenPill = require('screen-pill')
// function needs to take a driver as a parameter
function Foo(driver) {
// setting the driver is required
this.setDriver(driver)
// optional url
this.directUrl('http://www.mycoolapp.com')
// use screen-pill methods to generate acessors
this.textField('useranme', { id: 'username' })
this.passwordField('password', { name: 'password'})
this.submit('submit', { index: 0 })
// you can use the accessors on the instance
this.login = async function(username, password) {
await this.visit() //goto the direct url
await this.username.waitUntilPresent({ timeout: 5000, message: 'username element not present'})
await this.username.set(username)
await this.password.set(password)
return this.submit.click()
}
}
module.exports = ScreenPill(Foo)
and in your tests
// test.js
const chai = require('chai')
chai.use(require('chai-as-promised'))
const expect = chai.expect
const FooPage = require('foo-page')
const webdriver = require('selenium-webdriver')
const driver = new webdriver.Builder().forBrowser('chrome').build()
var page = new FooPage(driver)
page.login('skinnyjames', 'ssshhhhhh')
.then(_ => {
expect(page.text()).to.eventually.match(/Welcome/)
})