Skip to content

Commit

Permalink
Merge branch 'main' into features/add-waitUnitl-present-command
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityvi committed Sep 5, 2023
2 parents 23638e2 + 863d2c9 commit ebfc436
Show file tree
Hide file tree
Showing 174 changed files with 741 additions and 685 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Expand Up @@ -4,7 +4,7 @@
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 2020,
"ecmaVersion": 13,
"sourceType": "module",
"ecmaFeatures": {
"jsx": false
Expand Down
4 changes: 2 additions & 2 deletions api/index.js
Expand Up @@ -16,7 +16,7 @@ const exportedCommands = [
const basePath = '../dist/api';
const Commands = {};
const props = exportedCommands.reduce((prev, fileName) => {
const commandName = fileName.substring(fileName.lastIndexOf('/')+1).replace('.js', '');
const commandName = fileName.substring(fileName.lastIndexOf('/') + 1).replace('.js', '');
prev[commandName] = {
configurable: true,
get: function() {
Expand All @@ -29,4 +29,4 @@ const props = exportedCommands.reduce((prev, fileName) => {

Object.defineProperties(Commands, props);

module.exports = Commands;
module.exports = Commands;
Expand Up @@ -30,4 +30,4 @@ Then(/^the title is "([^"]*)"$/, function(title) {

Then(/^Body contains "([^"]*)"$/, function(contains) {
return browser.assert.textContains('.search-results', contains);
});
});
2 changes: 1 addition & 1 deletion examples/custom-commands/strictClick.js
Expand Up @@ -3,4 +3,4 @@ module.exports = {
return this.waitForElementVisible(selector)
.click(selector);
}
};
};
2 changes: 1 addition & 1 deletion examples/pages/google/search.js
Expand Up @@ -2,7 +2,7 @@ const searchCommands = {
submit() {
this.waitForElementVisible('@submitButton', 1000)
.click('@submitButton');

this.pause(1000);

return this; // Return page object for chaining
Expand Down
4 changes: 2 additions & 2 deletions examples/pages/google/searchResults.js
Expand Up @@ -6,7 +6,7 @@ const menuCommands = {
var self = this;

return this.getAttribute(product, 'class', function (result) {
let isSelected = result.value.indexOf('hdtb-msel') > -1;
const isSelected = result.value.indexOf('hdtb-msel') > -1;
callback.call(self, isSelected);
});
}
Expand Down Expand Up @@ -44,4 +44,4 @@ module.exports = {
}
}
}
};
};
4 changes: 2 additions & 2 deletions examples/tests/chromeCDP_example.js
@@ -1,7 +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 All @@ -11,4 +11,4 @@ describe('Chrome DevTools Example', function() {

browser.assert.deepStrictEqual(Object.keys(dom), ['documents', 'strings']);
});
});
});
2 changes: 1 addition & 1 deletion examples/tests/duckDuckGo.js
Expand Up @@ -11,5 +11,5 @@ describe('duckduckgo example', function() {
.assert.visible('button[type=submit]')
.click('button[type=submit]')
.assert.textContains('.react-results--main', 'Nightwatch.js');
});
});
});
2 changes: 1 addition & 1 deletion examples/tests/element/elementapi-tests.js
Expand Up @@ -79,4 +79,4 @@ describe('queries tests', function() {
});


});
});
2 changes: 1 addition & 1 deletion examples/tests/sample-with-relative-locators.js
Expand Up @@ -22,4 +22,4 @@ describe('sample with relative locators', function () {
});

after(browser => browser.end());
});
});
2 changes: 1 addition & 1 deletion examples/tests/selectElement.js
Expand Up @@ -13,4 +13,4 @@ module.exports = {
})
.assert.selected(await selectElement.findElement('option[value=four]'), 'Forth option is selected');
}
};
};
2 changes: 1 addition & 1 deletion examples/tests/shadowRootExample.js
Expand Up @@ -50,4 +50,4 @@ describe('Shadow Root example test', function() {
// await expect.element(firstElement).to.be.an('img');

});
});
});
2 changes: 1 addition & 1 deletion examples/unittests/testUtils.js
Expand Up @@ -19,4 +19,4 @@ module.exports = {
assert.strictEqual(Utils.getTestSuiteName('test.case.one'), 'Test Case One');
assert.strictEqual(Utils.getTestSuiteName('testCaseOne'), 'Test Case One');
}
};
};
2 changes: 1 addition & 1 deletion examples/unittests/testUtilsWithChai.js
Expand Up @@ -16,4 +16,4 @@ module.exports = {
var resultMs = Utils.formatElapsedTime(999);
expect(resultMs).to.equal('999ms');
}
};
};
10 changes: 5 additions & 5 deletions lib/api/_loaders/_base-loader.js
Expand Up @@ -399,20 +399,20 @@ class BaseLoader extends EventEmitter {
const options = this.getCommandOptions();


if (args && args.length > 0 && Utils.isFunction(args[args.length-1])) {
if (args && args.length > 0 && Utils.isFunction(args[args.length - 1])) {
const callback = args.pop();

const userCallbackWrapper = (function(context) {

const proxyFn = new Proxy(callback, {
apply: function(target, thisArg, argumentsList) {
context.addedInsideCallback = true;

return target.apply(thisArg, argumentsList);
}
});
proxyFn.originalTarget = callback;

return proxyFn;
})(this);

Expand Down
14 changes: 7 additions & 7 deletions lib/api/_loaders/command.js
Expand Up @@ -42,7 +42,7 @@ class CommandLoader extends BaseCommandLoader {
return function(...args) {
let callback;
let method;
const isLastArgFunction = isFunction(args[args.length-1]);
const isLastArgFunction = isFunction(args[args.length - 1]);

if (isLastArgFunction) {
callback = args.pop();
Expand Down Expand Up @@ -74,8 +74,8 @@ class CommandLoader extends BaseCommandLoader {
reportProtocolErrors(result) {
if (opts.isUserDefined) {
return true;
}
}

return super.reportProtocolErrors(result);
}

Expand All @@ -85,11 +85,11 @@ class CommandLoader extends BaseCommandLoader {

get reuseBrowser() {
return nightwatchInstance.argv['reuse-browser'] || (nightwatchInstance.settings.globals && nightwatchInstance.settings.globals.reuseBrowserSession);
}
}

get isES6AsyncCommand() {
return isES6AsyncFn(
CommandLoader.isDeprecatedCommandStyle(CommandModule) ? CommandModule.command: this.command
CommandLoader.isDeprecatedCommandStyle(CommandModule) ? CommandModule.command : this.command
);
}

Expand Down Expand Up @@ -210,7 +210,7 @@ class CommandLoader extends BaseCommandLoader {
if (result.stack) {
err.stack = result.stack;
}

if (result.error instanceof Error) {
result.error.registered = true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/_loaders/element-global.js
Expand Up @@ -161,7 +161,7 @@ class ElementGlobal {
value = {
value: locator,
using: this.client.locateStrategy
};
};
} else {
value = locator;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ class ElementGlobal {
});
}

const lastArg = args[args.length-1];
const lastArg = args[args.length - 1];
if (isFunction(lastArg)) {
if (error) {
return lastArg.call(this.api, {
Expand Down
2 changes: 1 addition & 1 deletion lib/api/_loaders/expect.js
Expand Up @@ -115,7 +115,7 @@ class ExpectLoader extends BaseCommandLoader {
deferred.reject(err);
});
}

return expectCommand.instance;
}.bind(this));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/_loaders/static.js
Expand Up @@ -182,7 +182,7 @@ module.exports = class StaticAssert {

Object.assign(node.deferred.promise, apiToReturn || this.api);

//prevent unhandled rejection
//prevent unhandled rejection
node.deferred.promise.catch(err => {
return StaticAssert.lastDeferred.reject(err);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/api/assertions/_assertionInstance.js
Expand Up @@ -21,7 +21,7 @@ class AssertionInstance {
}

static init({nightwatchInstance, args, fileName, options}) {
if (Utils.isFunction(args[args.length-1])) {
if (Utils.isFunction(args[args.length - 1])) {
this.__doneCallback = args.pop();
} else {
this.__doneCallback = function(result) {
Expand Down
10 changes: 5 additions & 5 deletions lib/api/assertions/domPropertyMatches.js
@@ -1,12 +1,12 @@
/**
* Check if specified DOM property value of a given element matches a regex. For all the available DOM element properties, consult the [Element doc at MDN](https://developer.mozilla.org/en-US/docs/Web/API/element).
*
*
*
*
* @example
* this.demoTest = function (browser) {
* browser.assert.domPropertyMatches('#main', 'tagName', /^frame/);
* }
*
*
* @method assert.domPropertyMatches
* @param {string|object} definition The selector (CSS/Xpath) used to locate the element. Can either be a string or an object which specifies [element properties](https://nightwatchjs.org/guide#element-properties).
* @param {string} domProperty The DOM property name.
Expand Down Expand Up @@ -41,10 +41,10 @@ exports.assertion = function (definition, domProperty, regexExpression, msg) {

if (!Array.isArray(value)) {
return regex.test(value);
}
}

return false;
};
};

this.value = function(result = {}) {
return result.value || '';
Expand Down
2 changes: 1 addition & 1 deletion lib/api/assertions/elementsCount.js
Expand Up @@ -50,7 +50,7 @@ exports.assertion = function (definition, count, msg) {


this.command = async function(callback) {

await this.api.findElements(definition, callback);
};
};
4 changes: 2 additions & 2 deletions lib/api/assertions/enabled.js
Expand Up @@ -21,7 +21,7 @@ exports.assertion = function(definition, msg) {

this.formatMessage = function() {
const message = msg || `Testing if element %s ${this.negate ? 'is not enabled' : 'is enabled'}`;

return {
message,
args: [this.elementSelector]
Expand All @@ -43,5 +43,5 @@ exports.assertion = function(definition, msg) {
this.command = function(callback) {
this.api.isEnabled(definition, callback);
};

};
12 changes: 6 additions & 6 deletions lib/api/assertions/hasAttribute.js
Expand Up @@ -3,12 +3,12 @@
* Checks if the given element contains the specified DOM attribute.
*
* Equivalent of: https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
*
*
* @example
* this.demoTest = function (browser) {
* browser.assert.hasAttribute('#main', 'data-track');
* };
*
*
* @method assert.hasAttribute
* @param {string|object} definition The selector (CSS/Xpath) used to locate the element. Can either be a string or an object which specifies [element properties](https://nightwatchjs.org/guide#element-properties).
* @param {string} expectedAttribute The DOM attribute to look for.
Expand All @@ -26,15 +26,15 @@ exports.assertion = function(definition, expectedAttribute, msg) {
this.expected = function() {
return this.negate ? `has not ${expectedAttribute}` : `has ${expectedAttribute}`;
};


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'}`;
const message = msg || `Testing if element %s ${this.negate ? 'doesn\'t have attribute %s' : 'has attribute %s'}`;

return {
message,
args: [this.elementSelector, `'${expectedAttribute}'`]
Expand All @@ -47,7 +47,7 @@ exports.assertion = function(definition, expectedAttribute, msg) {
if (!result || !result.value) {
return false;
}

return true;
};

Expand Down

0 comments on commit ebfc436

Please sign in to comment.