Skip to content

Commit

Permalink
Merge branch 'main' into issue/3571-new
Browse files Browse the repository at this point in the history
  • Loading branch information
swrdfish committed May 15, 2023
2 parents 575fc64 + de19a49 commit 7f72ce2
Show file tree
Hide file tree
Showing 114 changed files with 17,741 additions and 4,205 deletions.
23 changes: 23 additions & 0 deletions examples/tests/bstackdemo/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('Authentication Tests', function () {
beforeEach((browser) => browser.navigateTo('https://www.bstackdemo.com'));

it('Login test', function () {
browser
.click('#signin')
.setValue('#username input', ['demouser', browser.Keys.ENTER])
.setValue('#password input', ['testingisfun99', browser.Keys.ENTER])
.click('#login-btn')
.assert.textEquals('.username', 'demouser', 'demouser had logged in successfuly.');
});

it('Locked account test', function () {
browser
.click('#signin')
.setValue('#username input', ['locked_user', browser.Keys.ENTER])
.setValue('#password input', ['testingisfun99', browser.Keys.ENTER])
.click('#login-btn')
.assert.textContains('.api-error', 'Your account has been locked.');
});

afterEach((browser) => browser.end());
});
33 changes: 33 additions & 0 deletions examples/tests/bstackdemo/checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('Checkout Test', function () {
before((browser) => browser.navigateTo('https://www.bstackdemo.com/'));

it('checkout products on bstackdemo.com', function (browser) {
browser
.waitForElementVisible('body')
.assert.titleContains('StackDemo')
// Filter Google from the avaialble filters
.click('input[value=\'Google\'] + span')
.assert.selected('input[value=\'Google\']')
// Add different phones to cart
.click('[id="17"] .shelf-item__buy-btn')
.click('[id="18"] .shelf-item__buy-btn')
.assert.elementsCount('.float-cart__shelf-container .shelf-item', 2)
// Click checkout
.click('.buy-btn')
// Loging with given credentials
.setValue('#username input', ['demouser', browser.Keys.ENTER])
.setValue('#password input', ['testingisfun99', browser.Keys.ENTER])
.click('#login-btn')
// Fill shipping details
.setValue('#firstNameInput', 'John')
.setValue('#lastNameInput', 'Doe')
.setValue('#addressLine1Input', 'localhost')
.setValue('#provinceInput', 'local')
.setValue('#postCodeInput', '127001')
.click('#checkout-shipping-continue')
// Check order successfully placed
.assert.textEquals('#confirmation-message', 'Your Order has been successfully placed.');
});

after((browser) => browser.end());
});
2 changes: 2 additions & 0 deletions examples/tests/chromeCDP_example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
describe('Chrome DevTools Example', function() {

this.disabled = this.argv.env !== 'chrome';

it ('using CDP DOM Snapshot', async function(browser) {
await browser.navigateTo('https://nightwatchjs.org');

Expand Down
11 changes: 9 additions & 2 deletions examples/tests/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ describe('sample google search', function() {
.pause(1000);
}

let locator;
if (browser.isMobile()) {
locator = 'form[action="/search"] input[type=search]';
} else {
locator = 'form[action="/search"] input[type=text]';
}

await browser
.waitForElementVisible('form[action="/search"] input[type=text]')
.sendKeys('form[action="/search"] input[type=text]', ['Nightwatch.js', browser.Keys.ENTER])
.waitForElementVisible(locator)
.sendKeys(locator, ['Nightwatch.js', browser.Keys.ENTER])
.assert.textContains('#rso>:first-child', 'Nightwatch.js')
.end();
});
Expand Down
6 changes: 6 additions & 0 deletions lib/api/_loaders/element-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class ScopedElementAPILoader {
];
}

static isScopedElementCommand(commandName) {
return ScopedElementAPILoader.availableElementCommands.some(
commands => commands.includes(commandName)
);
}

constructor(nightwatchInstance) {
this.nightwatchInstance = nightwatchInstance;
}
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 @@ -235,7 +235,7 @@ class ElementGlobal {
const isElement = await this.setElement(stackTrace);
if (!isElement) {
return null;
}3;
}

if (commandName === 'findElement' && args.length === 0) {
return this.element;
Expand Down
26 changes: 11 additions & 15 deletions lib/api/assertions/hasAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @api assertions
*/

const {setElementSelectorProps, containsMultiple} = require('../../utils');
const {setElementSelectorProps, isString} = require('../../utils');

exports.assertion = function(definition, expectedAttribute, msg) {
this.options = {
Expand All @@ -32,35 +32,31 @@ exports.assertion = function(definition, expectedAttribute, msg) {


this.formatMessage = function() {
if (!isString(expectedAttribute)) {
throw new Error('Expected attribute must be a string');
}

let message = msg || `Testing if element %s ${this.negate ? 'doesn\'t have attribute %s' : 'has attribute %s'}`;

return {
message,
args: [this.elementSelector, `'${Array.isArray(expectedAttribute) ? expectedAttribute.join(' ') : expectedAttribute}'`]
args: [this.elementSelector, `'${expectedAttribute}'`]
};
};

this.evaluate = function() {
if (!this.attributeList) {
return false;
}

return containsMultiple(this.attributeList, expectedAttribute, ' ');
};
const {result} = this;

this.value = function(result) {
if (!result || !result.value) {
return '';
return false;
}

this.attributeList = result.value.map(attribute => attribute.name);

return this.attributeList;

return true;
};

this.command = function(callback) {
this.api.getAttribute(setElementSelectorProps(definition, {
suppressNotFoundErrors: true
}), 'attributes', callback);
}), expectedAttribute, callback);
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ProtocolAction = require('../_base-action.js');
const ClientCommand = require('../_base-command.js');

/**
* Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog.
Expand Down Expand Up @@ -27,12 +27,14 @@ const ProtocolAction = require('../_base-action.js');
* @link /#accept-alert
* @api protocol.userprompts
*/
module.exports = class Session extends ProtocolAction {
class AcceptAlert extends ClientCommand {
static get isTraceable() {
return true;
}

command(callback) {
return this.transportActions.acceptAlert(callback);
performAction(callback) {
this.transportActions.acceptAlert(callback);
}
};
}

module.exports = AcceptAlert;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ProtocolAction = require('../_base-action.js');
const ClientCommand = require('../_base-command.js');

/**
* Dismisses the currently displayed alert dialog.
Expand Down Expand Up @@ -29,12 +29,14 @@ const ProtocolAction = require('../_base-action.js');
* @link /#dismiss-alert
* @api protocol.userprompts
*/
module.exports = class Session extends ProtocolAction {
class DismissAlert extends ClientCommand {
static get isTraceable() {
return true;
}

command(callback) {
return this.transportActions.dismissAlert(callback);
performAction(callback) {
this.transportActions.dismissAlert(callback);
}
};
}

module.exports = DismissAlert;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ProtocolAction = require('../_base-action.js');
const ClientCommand = require('../_base-command.js');

/**
* Get the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.
Expand Down Expand Up @@ -28,8 +28,10 @@ const ProtocolAction = require('../_base-action.js');
* @link /#get-alert-text
* @api protocol.userprompts
*/
module.exports = class Session extends ProtocolAction {
command(callback) {
return this.transportActions.getAlertText(callback);
class GetAlertText extends ClientCommand {
performAction(callback) {
this.transportActions.getAlertText(callback);
}
};
}

module.exports = GetAlertText;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ProtocolAction = require('../_base-action.js');
const ClientCommand = require('../_base-command.js');

/**
* Send keystrokes to a JavaScript prompt() dialog.
Expand Down Expand Up @@ -27,12 +27,26 @@ const ProtocolAction = require('../_base-action.js');
* @link /#send-alert-text
* @api protocol.userprompts
*/
module.exports = class Session extends ProtocolAction {
class SetAlertText extends ClientCommand {
static get isTraceable() {
return true;
}

performAction(callback) {
const {alertText} = this;

this.transportActions.setAlertText(alertText, callback);
}

command(value, callback) {
return this.transportActions.setAlertText(value, callback);
if (typeof value !== 'string') {
throw new Error('First argument passed to .alerts.setText() must be a string.');
}

this.alertText = value;

return super.command(callback);
}
};
}

module.exports = SetAlertText;
7 changes: 1 addition & 6 deletions lib/api/client-commands/captureBrowserConsoleLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ class StartCapturingLogs extends ClientCommand {
return callback(error);
}

this.transportActions
.startLogsCapture(userCallback, callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.startLogsCapture(userCallback, callback);
}

command(userCallback, callback) {
Expand Down
7 changes: 1 addition & 6 deletions lib/api/client-commands/captureBrowserExceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ class CatchJsExceptions extends ClientCommand {
return callback(error);
}

this.transportActions
.catchJsExceptions(userCallback, callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.catchJsExceptions(userCallback, callback);
}

command(userCallback, callback) {
Expand Down
7 changes: 1 addition & 6 deletions lib/api/client-commands/captureNetworkRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ class CaptureNetworkCalls extends ClientCommand {
return callback(error);
}

this.transportActions
.interceptNetworkCalls(userCallback, callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.interceptNetworkCalls(userCallback, callback);
}

command(userCallback, callback) {
Expand Down
8 changes: 1 addition & 7 deletions lib/api/client-commands/cookies/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ClientCommand = require('../_base-command.js');
const {Logger} = require('../../../utils');

/**
* Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page.
Expand Down Expand Up @@ -36,12 +35,7 @@ class DeleteCookie extends ClientCommand {
performAction(callback) {
const {cookieName} = this;

this.transportActions
.deleteCookie(cookieName, callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.deleteCookie(cookieName, callback);
}

command(cookieName, callback) {
Expand Down
8 changes: 1 addition & 7 deletions lib/api/client-commands/cookies/deleteAll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ClientCommand = require('../_base-command.js');
const {Logger} = require('../../../utils');

/**
* Delete all cookies visible to the current page.
Expand Down Expand Up @@ -33,12 +32,7 @@ class DeleteCookies extends ClientCommand {
}

performAction(callback) {
this.transportActions
.deleteAllCookies(callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.deleteAllCookies(callback);
}
}

Expand Down
8 changes: 1 addition & 7 deletions lib/api/client-commands/cookies/get.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ClientCommand = require('../_base-command.js');
const {Logger} = require('../../../utils');

/**
* Retrieve a single cookie visible to the current page.
Expand Down Expand Up @@ -39,12 +38,7 @@ class GetCookie extends ClientCommand {
performAction(callback) {
const {cookieName} = this;

this.transportActions
.getCookie(cookieName, callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.getCookie(cookieName, callback);
}

command(name, callback) {
Expand Down
8 changes: 1 addition & 7 deletions lib/api/client-commands/cookies/getAll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ClientCommand = require('../_base-command.js');
const {Logger} = require('../../../utils');

/**
* Retrieve all cookies visible to the current page.
Expand Down Expand Up @@ -36,12 +35,7 @@ const {Logger} = require('../../../utils');

class GetCookies extends ClientCommand {
performAction(callback) {
this.transportActions
.getCookies(callback)
.catch(err => {
Logger.error(err);
callback(err);
});
this.transportActions.getCookies(callback);
}
}

Expand Down
Loading

0 comments on commit 7f72ce2

Please sign in to comment.