nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.85k stars 1.34k forks source link

Add types for custom commands on page object sections. #4298

Closed garg3133 closed 1 week ago

garg3133 commented 1 week ago

Fixes: #4292

This PR adds the types for the custom commands that are made available directly over the page object sections.

It should be noted NOT all custom commands are made available directly on the section object. All the custom commands are only available on the section.api object while the section object directly contains all the custom commands EXCEPT those having a namespace. This behaviour has been accounted for in the type definition.

For example, let's say the structure of the custom-commands folder is as follows:

custom-commands/
  - command1.js
  - command2.js
  - namespace1/
      - command.js

The above custom commands would be available on the various APIs as follows (assuming a page-object named myPage with a mySection section):

// all commands are available on the `browser` object
browser.command1();
browser.command2();
browser.namespace1.command(); // WORKS

// only non-namespaced custom commands are available on the `mySection` object directly
const mySection = myPage.section.mySection;

mySection.api.command1();
mySection.command2();
mySection.namespace1.command(); // !!!ERROR

// all commands are available on the `mySection.api` object
mySection.api.command1();
mySection.command2();
mySection.namespace1.command();  // WORKS

The above is also true for the page-objects -- only non-namespaced custom commands are made directly available on the page object.

The types for custom commands on page-objects should also be fixed at some later time (after making sure that the newly added type definition is working correctly).