Giter Site home page Giter Site logo

juanazam / ember-cli-page-object Goto Github PK

View Code? Open in Web Editor NEW

This project forked from san650/ember-cli-page-object

0.0 1.0 0.0 168 KB

Represent the screens of your web app as a series of objects.

License: MIT License

JavaScript 91.62% HTML 5.96% Handlebars 2.42%

ember-cli-page-object's Introduction

Ember Page Objects

Represent the screens of your web app as a series of objects.

Description

An excerpt from the Selenium Wiki

Within your web app's UI there are areas that your tests interact with. A Page Object simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place. The pattern was first introduced by the Selenium

This ember-cli addon ease the construction of Page Objects on your acceptance tests.

You can find more information about the design pattern here:

Usage

First add the npm package to your ember-cli project

npm install --save-dev ember-cli-page-object

then import the page-object helper

import PO from '../page-object';

The previous example assumes that your test file is one level deep under tests/ folder. i.e. tests/unit/my-unit-test.js.

Then you can start building your page objects as follows:

var login = PO.build({
  visit:        PO.visitable('/login'),
  userName:     PO.fillable('#username'),
  password:     PO.fillable('#password'),
  submit:       PO.clickable('#login'),
  errorMessage: PO.text('.message')
});

test('Invalid log in', function(assert) {
  login
    .visit()
    .userName('[email protected]')
    .password('secret')
    .submit();

  andThen(function() {
    assert.equal(login.errorMessage(), 'Invalid credentials!');
  });
});

Built-in support for defining tables and collections:

<table id="users">
  <tr>
    <td>Jane</td>
    <td>Doe</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
  </tr>
</table>
var page = PO.build({
  visit: PO.visitable('/users'),

  users: PO.collection({
    itemScope: '#users tr',

    item: {
      firstName: PO.text('td:nth-of-type(1)'),
      lastName:  PO.text('td:nth-of-type(2)')
    }
  })
});

test('show all users', function(assert) {
  page.visit();

  andThen(function() {
    assert.equal(login.users().count(), 2);
    assert.equal(login.users(1).firstName(), 'Jane');
    assert.equal(login.users(1).lastName(), 'Doe');
    assert.equal(login.users(2).firstName(), 'John');
    assert.equal(login.users(2).lastName(), 'Doe');
  });
});

You can use ES6 destructuring to declutter even more your page definition:

var { visitable, collection, text } = PO;

var page = PO.build({
  visit: visitable('/users'),

  users: collection({
    itemScope: '#users tr',

    item: {
      firstName: text('td:nth-of-type(1)'),
      lastName:  text('td:nth-of-type(2)')
    }
  })
});

Check the DOCUMENTATION for more information.

Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

License

ember-cli-page-object is licensed under the MIT license.

See LICENSE for the full license text.

ember-cli-page-object's People

Contributors

san650 avatar

Watchers

Juan Manuel Azambuja 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.