Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make namespaces available as named exports #3646

Merged
merged 32 commits into from
Mar 30, 2023

Conversation

garg3133
Copy link
Member

@garg3133 garg3133 commented Mar 15, 2023

This PR makes the namespaces specified in the namespaced-api.js file available as named exports.

To test this PR, copy/move the navigateTo.js and getTitle.js (or any other command files) to the client sub-directory. Doing so will make those commands available on the client namespace.

In your test, use it as:

const {client, assert} = require('../../lib/index'); // path to `lib/index.js` file

describe('demo', function() {
  it('demo test', function() {
    console.log(client.navigateTo('https://ecosia.org').getTitle((result) => console.log(result)));
    console.log(await assert.titleContains('Ecosia').titleEquals('Ecosia - the search engine that plants trees'));
  });
});

In above test, the commands will return the namespace only instead of the whole browser object. While the commands executed using browser.client.commandName will still return the whole browser object.

@garg3133 garg3133 marked this pull request as ready for review March 16, 2023 14:37
Comment on lines 284 to 296
isRestrictedNamespace(parent, namespace) {
if (!parent) {
return false;
}

// do not load these namespaces on parent (page objects and within-context).
const namespacesRestrictedForParent = ['client'];

const isRestrictedNamespace = namespace
&& namespacesRestrictedForParent.some((ns) => namespace.toString().startsWith(ns));

return isRestrictedNamespace;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change here is for the discussion we had that we don't need to load all the namespaces directly onto the page objects but only a few like cookies and a11y. So, with this, we can restrict the namespaces we do not want to load on page-objects.

This was actually added here because page objects already had a client property (set to NightwatchClient) and so we could not add the client namespace commands directly onto page-objects, but it also serves the purpose mentioned above. And since we are no longer loading the commands onto client namespace, we can safely remove this as well if we do not want this feature at this point.

lib/index.js Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
lib/core/client.js Outdated Show resolved Hide resolved
lib/api/_loaders/static.js Outdated Show resolved Hide resolved
lib/api/_loaders/static.js Outdated Show resolved Hide resolved
lib/api/_loaders/_base-loader.js Outdated Show resolved Hide resolved
lib/api/_loaders/_base-loader.js Outdated Show resolved Hide resolved
lib/api/_loaders/_base-loader.js Show resolved Hide resolved
lib/namespaced-api.js Outdated Show resolved Hide resolved
lib/api/_loaders/_base-loader.js Show resolved Hide resolved
lib/api/index.js Show resolved Hide resolved
lib/api/_loaders/_base-loader.js Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
Copy link
Member

@vaibhavsingh97 vaibhavsingh97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this pull request! LGTY!!

Windows build failing, and I suspect increasing timeout will fix the issue.

@garg3133
Copy link
Member Author

Windows build failing, and I suspect increasing timeout will fix the issue.

Maybe, but in the last 4 build failures, 5 tests failed cumulatively, and all are different. So, not sure which test to increase the timeout for if a different test fails every time.

@swrdfish
Copy link
Member

@garg3133 maybe try increasing the default timeout?

@garg3133 garg3133 force-pushed the named-exports branch 3 times, most recently from ce24453 to 1fde06c Compare March 28, 2023 16:57
@beatfactor beatfactor added the v3 label Mar 29, 2023
@beatfactor beatfactor changed the base branch from main to v3 March 30, 2023 07:58
@beatfactor beatfactor merged commit ed503e1 into nightwatchjs:v3 Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants