Methods

Table of Contents

contains

Returns a boolean representing whether an element or a set of elements contains the specified text.

Parameters

  • selector string CSS selector of the element to check
  • userOptions (optional, default {})
  • options Object Additional options
    • options.scope string Nests provided scope within parent’s scope
    • options.at number Reduce the set of matched elements to the one at the specified index
    • options.resetScope boolean Override parent’s scope
    • options.multiple boolean Check if all elements matched by selector contain the subtext
    • options.testContainer string Context where to search elements in the DOM

Examples

// Lorem <span>ipsum</span>

import { create, contains } from 'ember-cli-page-object';

const page = create({
  spanContains: contains('span')
});

assert.ok(page.spanContains('ipsum'));
// <span>lorem</span>
// <span>ipsum</span>
// <span>dolor</span>

const page = PageObject.create({
  spansContain: PageObject.contains('span', { multiple: true })
});

// not all spans contain 'lorem'
assert.notOk(page.spansContain('lorem'));
// <span>super text</span>
// <span>regular text</span>

import { create, contains } from 'ember-cli-page-object';

const page = create({
  spansContain: contains('span', { multiple: true })
});

// all spans contain 'text'
assert.ok(page.spansContain('text'));
// <div><span>lorem</span></div>
// <div class="scope"><span>ipsum</span></div>
// <div><span>dolor</span></div>

import { create, contains } from 'ember-cli-page-object';

const page = create({
  spanContains: contains('span', { scope: '.scope' })
});

assert.notOk(page.spanContains('lorem'));
assert.ok(page.spanContains('ipsum'));
// <div><span>lorem</span></div>
// <div class="scope"><span>ipsum</span></div>
// <div><span>dolor</span></div>

import { create, contains } from 'ember-cli-page-object';

const page = create({
  scope: '.scope',
  spanContains: contains('span')
});

assert.notOk(page.spanContains('lorem'));
assert.ok(page.spanContains('ipsum'));
  • Throws any Will throw an error if no element matches selector
  • Throws any Will throw an error if multiple elements are matched by selector and multiple option is not set

Returns Descriptor