Skip to content

Commit

Permalink
fixed issue nightwatchjs#4057, added getAll and findElements aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Musa Ibrahim committed Mar 22, 2024
1 parent 93e4e39 commit 3cf33b6
Show file tree
Hide file tree
Showing 11 changed files with 7,969 additions and 7,512 deletions.
4 changes: 2 additions & 2 deletions examples/tests/duckDuckGo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ describe('duckduckgo example', function() {

this.tags = ['end-to-end'];

it('Search Nightwatch.js and check results', function(browser) {
it('Search Nightwatch.js and check results', async function(browser) {
browser
.navigateTo('https://duckduckgo.com')
.waitForElementVisible('body')
.assert.visible('input[name="q"]')
.sendKeys('input[name="q"]', ['Nightwatch.js'])
.assert.visible('button[type=submit]')
.click('button[type=submit]')
.assert.textContains('.react-results--main', 'Nightwatch.js');
.assert.textContains('.react-results--main', 'Nightwatch');
});
});
4 changes: 2 additions & 2 deletions examples/tests/ecosia.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ describe('Ecosia.org Demo', function() {
.navigateTo('https://www.ecosia.org/');
});

it('Demo test ecosia.org', function(browser) {
it('Demo test ecosia.org', async function(browser) {
browser
.waitForElementVisible('body')
.assert.titleContains('Ecosia')
.assert.visible('input[type=search]')
.setValue('input[type=search]', 'nightwatch')
.assert.visible('button[type=submit]')
.click('button[type=submit]')
.assert.textContains('.layout__content', 'Nightwatch.js');
.assert.textContains('.layout__content', 'Nightwatch');
});

after(browser => browser.end());
Expand Down
9 changes: 9 additions & 0 deletions examples/tests/element/elementapi-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('queries tests', function() {
await element.findAll('section').count().assert.equals(9);
});

it('getAll', async function({element}) {
await element.getAll('section').count().assert.equals(9);
});

it('findElements', async function({element}) {
await element.findElements('section').count().assert.equals(9);
});


it('Button click works', async function(browser) {
const button = await browser.element.findByText('Unique Button Text');

Expand Down
2 changes: 1 addition & 1 deletion lib/api/_loaders/element-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ScopedElementAPILoader {
static get availableElementCommands() {
return [
['findElement', 'find', 'get'],
['findAll'],
['findAll', 'getAll'],
['findByText'],
['findAllByText'],
['findByRole'],
Expand Down
2 changes: 1 addition & 1 deletion lib/api/_loaders/element-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ElementGlobal {
return [
'getId',
['findElement', 'element', 'find', 'get'],
['findElements', 'findAll'],
['findElements', 'findAll', 'getAll'],
'click',
'sendKeys',
['getTagName', 'tagName'],
Expand Down
30 changes: 30 additions & 0 deletions lib/api/web-element/commands/findElements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Search for elements on the page. The located elements will be returned as a special web element object (with added convenience methods).
* The argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
* Elements can be searched by using another element as the starting point.
*
* @example
* export default {
* async demoTest(browser: NightwatchAPI): Promise<void> {
* const buttonsElement = browser.element.findElements('button.submit-form');
*
* // Get an array of found elements.
* const buttons = await buttonsElement;
*
* // Use an object to customise locating behaviour.
* const sections = browser.element
* .findElements({ selector: 'section', locateStrategy: 'css selector' });
* }
* }
*
* @since 3.0.0
* @method findElements
* @memberof ScopedWebElement
* @instance
* @syntax browser.element.findElements(syntax)
* @param {Selector} selector
* @returns {Array.<ScopeWebElement>}
*/
module.exports.command = function(selector) {
return this.createScopedElements(selector, {parentElement: this, commandName: 'findElements'});
};
30 changes: 30 additions & 0 deletions lib/api/web-element/commands/getAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Search for elements on the page. The located elements will be returned as a special web element object (with added convenience methods).
* The argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
* Elements can be searched by using another element as the starting point.
*
* @example
* export default {
* async demoTest(browser: NightwatchAPI): Promise<void> {
* const buttonsElement = browser.element.getAll('button.submit-form');
*
* // Get an array of found elements.
* const buttons = await buttonsElement;
*
* // Use an object to customise locating behaviour.
* const sections = browser.element
* .getAll({ selector: 'section', locateStrategy: 'css selector' });
* }
* }
*
* @since 3.0.0
* @method getAll
* @memberof ScopedWebElement
* @instance
* @syntax browser.element.getAll(syntax)
* @param {Selector} selector
* @returns {Array.<ScopeWebElement>}
*/
module.exports.command = function(selector) {
return this.createScopedElements(selector, {parentElement: this, commandName: 'getAll'});
};
Loading

0 comments on commit 3cf33b6

Please sign in to comment.