Queries
Methods
attribute
addon/queries/attribute.js:67-82
Returns the value of an attribute from the matched element, or an array of values from multiple matched elements.
Parameters
attributeNamestring Name of the attribute to getselectorstring CSS selector of the element to checkoptionsObject Additional optionsoptions.scopestring Nests provided scope within parent’s scopeoptions.resetScopeboolean Override parent’s scopeoptions.atnumber Reduce the set of matched elements to the one at the specified indexoptions.multipleboolean If set, the function will return an array of valuesoptions.testContainerString Context where to search elements in the DOM
Examples
// <input placeholder="a value">
const page = PageObject.create({
inputPlaceholder: PageObject.attribute('placeholder', 'input')
});
assert.equal(page.inputPlaceholder, 'a value');
// <input placeholder="a value">
// <input placeholder="other value">
const page = PageObject.create({
inputPlaceholders: PageObject.attribute('placeholder', ':input', { multiple: true })
});
assert.deepEqual(page.inputPlaceholders, ['a value', 'other value']);
// <div><input></div>
// <div class="scope"><input placeholder="a value"></div>
// <div><input></div>
const page = PageObject.create({
inputPlaceholder: PageObject.attribute('placeholder', ':input', { scope: '.scope' })
});
assert.equal(page.inputPlaceholder, 'a value');
// <div><input></div>
// <div class="scope"><input placeholder="a value"></div>
// <div><input></div>
const page = PageObject.create({
scope: 'scope',
inputPlaceholder: PageObject.attribute('placeholder', ':input')
});
assert.equal(page.inputPlaceholder, 'a value');
Returns Descriptor
count
Returns the number of elements matched by a selector.
Parameters
selectorstring CSS selector of the element or elements to checkoptionsObject Additional optionsoptions.scopestring Add scopeoptions.resetScopeboolean Ignore parent scopeoptions.testContainerString Context where to search elements in the DOM
Examples
// <span>1</span>
// <span>2</span>
const page = PageObject.create({
spanCount: PageObject.count('span')
});
assert.equal(page.spanCount, 2);
// <div>Text</div>
const page = PageObject.create({
spanCount: PageObject.count('span')
});
assert.equal(page.spanCount, 0);
// <div><span></span></div>
// <div class="scope"><span></span><span></span></div>
const page = PageObject.create({
spanCount: PageObject.count('span', { scope: '.scope' })
});
assert.equal(page.spanCount, 2)
// <div><span></span></div>
// <div class="scope"><span></span><span></span></div>
const page = PageObject.create({
scope: '.scope',
spanCount: PageObject.count('span')
});
assert.equal(page.spanCount, 2)
// <div><span></span></div>
// <div class="scope"><span></span><span></span></div>
const page = PageObject.create({
scope: '.scope',
spanCount: PageObject.count('span', { resetScope: true })
});
assert.equal(page.spanCount, 1);
Returns Descriptor
is
Validates if an element (or elements) matches a given selector.
Useful for checking if an element (or elements) matches a selector like
:disabled or :checked, which can be the result of either an attribute
(disabled="disabled", disabled=true) or a property (disabled).
Parameters
testSelectorstring CSS selector to testtargetSelectorstring CSS selector of the element to checkoptionsObject Additional optionsoptions.scopestring Nests provided scope within parent’s scopeoptions.resetScopeboolean Override parent’s scopeoptions.atnumber Reduce the set of matched elements to the one at the specified indexoptions.multipleboolean If set, the function will return an array of valuesoptions.testContainerString Context where to search elements in the DOM
Examples
// <input type="checkbox" checked="checked">
// <input type="checkbox" checked>
const page = PageObject.create({
areInputsChecked: is(':checked', 'input', { multiple: true })
});
assert.equal(page.areInputsChecked, true, 'Inputs are checked');
// <button class="toggle-button active" disabled>Toggle something</button>
const page = PageObject.create({
isToggleButtonActive: is('.active:disabled', '.toggle-button')
});
assert.equal(page.isToggleButtonActive, true, 'Button is active');
Returns Descriptor
property
addon/queries/property.js:53-68
Returns the value of a property from the matched element, or an array of values from multiple matched elements.
Parameters
propertyNamestring Name of the property to getselectorstring CSS selector of the element to checkoptionsObject Additional optionsoptions.scopestring Nests provided scope within parent’s scopeoptions.resetScopeboolean Override parent’s scopeoptions.atnumber Reduce the set of matched elements to the one at the specified indexoptions.multipleboolean If set, the function will return an array of values
Examples
// <input type="checkbox" checked="checked">
const page = PageObject.create({
isChecked: PageObject.property('checked', 'input')
});
assert.ok(page.isChecked);
// <input type="checkbox" checked="checked">
// <input type="checkbox" checked="">
const page = PageObject.create({
inputsChecked: PageObject.property('checked', 'input', { multiple: true })
});
assert.deepEqual(page.inputsChecked, [true, false]);
// <div><input></div>
// <div class="scope"><input type="checkbox" checked="checked"></div>
// <div><input></div>
const page = PageObject.create({
isChecked: PageObject.property('checked', 'input', { scope: '.scope' })
});
assert.ok(page.isChecked);
Returns Descriptor
text
Returns text of the element or Array of texts of all matched elements by selector.
Parameters
selectorstring CSS selector of the element to checkoptionsObject Additional optionsoptions.scopestring Nests provided scope within parent’s scopeoptions.atnumber Reduce the set of matched elements to the one at the specified indexoptions.resetScopeboolean Override parent’s scopeoptions.multipleboolean Return an array of valuesoptions.normalizeboolean Set tofalseto avoid text normalizationoptions.testContainerString Context where to search elements in the DOM
Examples
// Hello <span>world!</span>
const page = PageObject.create({
text: PageObject.text('span')
});
assert.equal(page.text, 'world!');
// <span>lorem</span>
// <span> ipsum </span>
// <span>dolor</span>
const page = PageObject.create({
texts: PageObject.text('span', { multiple: true })
});
assert.deepEqual(page.texts, ['lorem', 'ipsum', 'dolor']);
// <div><span>lorem</span></div>
// <div class="scope"><span>ipsum</span></div>
// <div><span>dolor</span></div>
const page = PageObject.create({
text: PageObject.text('span', { scope: '.scope' })
});
assert.equal(page.text, 'ipsum');
// <div><span>lorem</span></div>
// <div class="scope"><span>ipsum</span></div>
// <div><span>dolor</span></div>
const page = PageObject.create({
scope: '.scope',
text: PageObject.text('span')
});
// returns 'ipsum'
assert.equal(page.text, 'ipsum');
// <div><span>lorem</span></div>
// <div class="scope">
// ipsum
// </div>
// <div><span>dolor</span></div>
const page = PageObject.create({
scope: '.scope',
text: PageObject.text('span', { normalize: false })
});
// returns 'ipsum'
assert.equal(page.text, '\n ipsum\n');
Returns Descriptor
value
Returns the value of a matched element, or an array of values of all matched elements.
Parameters
selectorstring CSS selector of the element to checkoptionsObject Additional optionsoptions.scopestring Nests provided scope within parent’s scopeoptions.resetScopeboolean Override parent’s scopeoptions.atnumber Reduce the set of matched elements to the one at the specified indexoptions.multipleboolean If set, the function will return an array of valuesoptions.testContainerString Context where to search elements in the DOM
Examples
// <input value="Lorem ipsum">
const page = PageObject.create({
value: PageObject.value('input')
});
assert.equal(page.value, 'Lorem ipsum');
// <input value="lorem">
// <input value="ipsum">
const page = PageObject.create({
value: PageObject.value('input', { multiple: true })
});
assert.deepEqual(page.value, ['lorem', 'ipsum']);
// <div><input value="lorem"></div>
// <div class="scope"><input value="ipsum"></div>
const page = PageObject.create({
value: PageObject.value('input', { scope: '.scope' })
});
assert.equal(page.value, 'ipsum');
// <div><input value="lorem"></div>
// <div class="scope"><input value="ipsum"></div>
const page = PageObject.create({
scope: '.scope',
value: PageObject.value('input')
});
assert.equal(page.value, 'ipsum');
Returns Descriptor