Ember CLI Page Object

2.3.2 · active · verified Wed Apr 22

Ember CLI Page Object is an Ember CLI addon that streamlines the creation and maintenance of page objects for acceptance and integration tests within Ember applications. Following the Page Object design pattern, it abstracts UI interactions and assertions into reusable objects, significantly reducing code duplication and making tests more resilient to UI changes. The current stable version is 2.3.2, released as part of a continuous development cycle with frequent bug fixes and enhancements. Recent efforts have focused on progressively removing jQuery dependencies to modernize the codebase while maintaining backward compatibility. It differentiates itself by providing a dedicated, mature testing pattern specifically tailored for the Ember ecosystem, offering a structured approach to testing complex UIs compared to raw `@ember/test-helpers` usage.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining a page object for a user listing page and using it in an acceptance test.

import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { create, visitable, text, collection } from 'ember-cli-page-object';

const UsersPage = create({
  visit: visitable('/users'),
  title: text('h1'),
  users: collection({
    itemScope: '.user-item',
    item: {
      name: text('.user-name'),
      email: text('.user-email'),
    },
  }),
});

module('Acceptance | users', function(hooks) {
  setupApplicationTest(hooks);

  test('visiting /users', async function(assert) {
    // Simulate some data or ensure it's available for the route
    // In a real app, this might involve mocking services or Mirage JS
    await visit('/users');

    assert.equal(currentURL(), '/users');
    assert.equal(UsersPage.title, 'Users List');
    assert.equal(UsersPage.users.length, 0, 'No users initially'); // Assuming data needs to be loaded

    // Example of interacting with a populated list
    // (requires data to be present in the tested application)
    // await UsersPage.users[0].name.click(); 
  });
});

view raw JSON →