Repository: nightwatchjs/nightwatch (js)

Issue:
Add `text` as an alias for `getText` command in the new Element API.
### Description

### Description


The `getText` should have the following alias 
- `text` 


The `getText` can be found in the `lib/api/web-element/commands` directory. 

### Suggested solution

_No response_

### Alternatives / Workarounds

_No response_

### Additional Information

_No response_

Pull request:
Feat: Added `text` as an alias for `getText`
Fixes #4179  

Thanks in advance for your contribution. Please follow the below steps in submitting a pull request, as it will help us with reviewing it quicker.

- [ . ] Before marking your PR for review, please test and verify your changes by making appropriate modifications to any of the Nightwatch example tests (present in `examples/tests` directory of the project) and running them. `ecosia.js` and `duckDuckGo.js` are good examples to work with.
- [ . ] Create a new branch from master (e.g. `features/my-new-feature` or `issue/123-my-bugfix`);
- [ . ] If you're fixing a bug also create an issue if one doesn't exist yet;
- [ ] If it's a new feature explain why do you think it's necessary. Please check with the maintainers beforehand to make sure it is something that we will accept. Usually we only accept new features if we feel that they will benefit the entire community;
- [ ] Please avoid sending PRs which contain drastic or low level changes. If you are certain that the changes are needed, please discuss them beforehand and indicate what the impact will be;
- [ ] If your change is based on existing functionality please consider refactoring first. Pull requests that duplicate code will most likely be ignored;
- [ ] Do not include changes that are not related to the issue at hand;
- [ ] Follow the same coding style with regards to spaces, semicolons, variable naming etc.;
- [ ] Always add unit tests - PRs without tests are most of the times ignored.


Patch:
diff --git a/lib/api/client-commands/debug.js b/lib/api/client-commands/debug.js
index 53a3e868..e5632223 100644
--- a/lib/api/client-commands/debug.js
+++ b/lib/api/client-commands/debug.js
@@ -1,15 +1,16 @@
-const util = require('util');
 const EventEmitter = require('events');
 const NightwatchRepl = require('../../testsuite/repl');
 const Debuggability = require('../../utils/debuggability.js');
 
 /**
  * This command halts the test execution and provides users with a REPL interface where they can type
- * any of the available Nightwatch commands and the command will be executed in the running browser
+ * any of the available Nightwatch commands or assertions and it will be executed in the running browser
  * in real-time.
  *
- * This can be used to debug why a certain command in not working as expected, find the correct
- * locators for your assertions or just play around with the available Nightwatch commands.
+ * This can be used to debug why a certain command in not working as expected or a certain assertion is
+ * failing by trying out the commands and assertions in different ways (trying an assertion with different
+ * locators until the correct one if found), or just play around with the available Nightwatch commands
+ * and assertions.
  *
  * @example
  * // async function is required while using the debug
@@ -26,52 +27,51 @@ const Debuggability = require('../../utils/debuggability.js');
  * };
  *
  * @method debug
- * @param {object} config Config options for the REPL interface.
+ * @param {object} [config] Config options for the REPL interface.
  * @param {function} [callback] Optional callback function to be called when the command finishes.
  * @api protocol.utilities
  */
+class Debug extends EventEmitter {
+  static get avoidPrematureParentNodeResolution() {
+    return true;
+  }
 
-function Debug() {
-  EventEmitter.call(this);
-}
-
-util.inherits(Debug, EventEmitter);
-
-Debug.prototype.command = function(config, cb) {
-  const repl = new NightwatchRepl(config);
+  command(config, callback) {
+    const repl = new NightwatchRepl(config);
 
-  // eslint-disable-next-line
-  console.log(NightwatchRepl.introMessage());
+    // eslint-disable-next-line
+    console.log(NightwatchRepl.introMessage());
 
-  // Create context for vm
-  const context = {
-    browser: this.api,
-    app: this.api
-  };
-  if (config?.selector) {
-    this.api.executeScript('console.log("Element ' + config.selector + ':", document.querySelector("' + config.selector + '"))');
-  }
-  // Before starting REPL server, Set debugMode to true
-  Debuggability.debugMode = true;
-  // Set isES6AsyncTestcase to true in debugmode
-  const isES6AsyncTestcase = this.client.isES6AsyncTestcase;
-  this.client.isES6AsyncTestcase = true;
-  repl.startServer(context);
+    // Create context for vm
+    const context = {
+      browser: this.api,
+      app: this.api
+    };
+    if (config?.selector) {
+      this.api.executeScript('console.log("Element ' + config.selector + ':", document.querySelector("' + config.selector + '"))');
+    }
+    // Before starting REPL server, Set debugMode to true
+    Debuggability.debugMode = true;
+    // Set isES6AsyncTestcase to true in debugmode
+    const isES6AsyncTestcase = this.client.isES6AsyncTestcase;
+    this.client.isES6AsyncTestcase = true;
+    repl.startServer(context);
 
-  repl.onExit(() => {
-    // On exit, Set debugMode to false
-    Debuggability.debugMode = false;
-    this.client.isES6AsyncTestcase = isES6AsyncTestcase;
+    repl.onExit(() => {
+      // On exit, Set debugMode to false
+      Debuggability.debugMode = false;
+      this.client.isES6AsyncTestcase = isES6AsyncTestcase;
 
-    // if we have a callback, call it right before the complete event
-    if (cb) {
-      cb.call(this.client.api);
-    }
+      // if we have a callback, call it right before the complete event
+      if (callback) {
+        callback.call(this.client.api);
+      }
 
-    this.emit('complete');
-  });
+      this.emit('complete');
+    });
 
-  return this;
-};
+    return this;
+  }
+}
 
 module.exports = Debug;
diff --git a/lib/api/client-commands/pause.js b/lib/api/client-commands/pause.js
index 695d8a4a..080025de 100644
--- a/lib/api/client-commands/pause.js
+++ b/lib/api/client-commands/pause.js
@@ -1,7 +1,5 @@
-const util = require('util');
 const EventEmitter = require('events');
 const readline = require('readline');
-const tty = require('tty');
 const Debuggability = require('../../utils/debuggability.js');
 
 /**
@@ -31,65 +29,63 @@ const Debuggability = require('../../utils/debuggability.js');
  * @param {function} [callback] Optional callback function to be called when the command finishes.
  * @api protocol.utilities
  */
+class Pause extends EventEmitter {
 
-function Pause() {
-  EventEmitter.call(this);
-}
-
-util.inherits(Pause, EventEmitter);
-
-Pause.prototype.command = function(ms, cb) {
-  // If we don't pass the milliseconds, the client will
-  // be suspended indefinitely, until the user presses some
-  // key in the terminal to resume it.
-  if (ms === undefined) {
-    // eslint-disable-next-line
-    console.log(`Paused...
-  Press <space> or F10 to step over to the next test command and pause again.
-  Press Ctrl+C to exit.
-  Press any other key to RESUME.`);
-
-    readline.emitKeypressEvents(process.stdin);
-    process.stdin.resume();
-    if (process.stdin.isTTY) {
-      process.stdin.setRawMode(true);
-    }
-    process.stdin.once('keypress', (str, key) => {
-      if (key.ctrl && key.name === 'c') {
-        this.api.end(function() {
-          process.exit(0);
-        });
-      } else if (key.name === 'space' || key.name === 'f10') {
-        Debuggability.stepOverAndPause = true;
-      }
+  command(ms, callback) {
+    // If we don't pass the milliseconds, the client will
+    // be suspended indefinitely, until the user presses some
+    // key in the terminal to resume it.
+    if (ms === undefined) {
+      // eslint-disable-next-line
+      console.log(`Paused...
+    Press <space> or F10 to step over to the next test command and pause again.
+    Press Ctrl+C to exit.
+    Press any other key to RESUME.`);
 
+      readline.emitKeypressEvents(process.stdin);
+      process.stdin.resume();
       if (process.stdin.isTTY) {
-        process.stdin.setRawMode(false);
+        process.stdin.setRawMode(true);
       }
-      process.stdin.pause();
+      process.stdin.once('keypress', (str, key) => {
+        if (key.ctrl && key.name === 'c') {
+          this.api.end(function() {
+            process.exit(0);
+          });
+        } else if (key.name === 'space' || key.name === 'f10') {
+          Debuggability.stepOverAndPause = true;
+        } else if (key.name === 'd') {
+          this.api.debug();
+        }
 
-      // Remove the logged paused... information above
-      readline.moveCursor(process.stdout, 0, -4);
-      readline.clearScreenDown(process.stdout);
+        if (process.stdin.isTTY) {
+          process.stdin.setRawMode(false);
+        }
+        process.stdin.pause();
 
-      if (cb) {
-        cb.call(this.client.api);
-      }
+        // Remove the logged paused... information above
+        readline.moveCursor(process.stdout, 0, -4);
+        readline.clearScreenDown(process.stdout);
 
-      this.emit('complete');
-    });
-  } else {
-    setTimeout(() => {
-      // if we have a callback, call it right before the complete event
-      if (cb) {
-        cb.call(this.client.api);
-      }
+        if (callback) {
+          callback.call(this.client.api);
+        }
 
-      this.emit('complete');
-    }, ms);
-  }
+        this.emit('complete');
+      });
+    } else {
+      setTimeout(() => {
+        // if we have a callback, call it right before the complete event
+        if (callback) {
+          callback.call(this.client.api);
+        }
+
+        this.emit('complete');
+      }, ms);
+    }
 
-  return this;
-};
+    return this;
+  }
+}
 
 module.exports = Pause;
diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js
index 1aaee5f8..c752b45d 100644
--- a/lib/api/web-element/scoped-element.js
+++ b/lib/api/web-element/scoped-element.js
@@ -23,8 +23,10 @@ class ScopedWebElement {
       'findAllByPlaceholderText': ['getAllByPlaceholderText'],
       'findAllByAltText': ['getAllByAltText'],
       'getRect': ['getSize', 'getLocation', 'rect'],
+      'getText': ['text'],
       'getProperty': ['property'],
       'getCssProperty': ['css'],
+      'getAriaRole': ['ariaRole'],
       'isVisible': ['isDisplayed']
     };
   }
diff --git a/types/web-element.d.ts b/types/web-element.d.ts
index d8fc0c71..a1340784 100644
--- a/types/web-element.d.ts
+++ b/types/web-element.d.ts
@@ -148,6 +148,7 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
   getTagName(): ElementValue<string>;
 
   getText(): ElementValue<string>;
+  text(): ElementValue<string>;
 
   click(): Promise<WebElement>;
 
@@ -178,6 +179,7 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
   getAccessibleName(): ElementValue<string>;
 
   getAriaRole(): ElementValue<string>;
+  ariaRole(): ElementValue<string>;
 
   getCssProperty(name: string): ElementValue<string>;
 


Test patch:
diff --git a/test/src/api/commands/web-element/testGetAriaRole.js b/test/src/api/commands/web-element/testGetAriaRole.js
index 53e86b65..7cddaad3 100644
--- a/test/src/api/commands/web-element/testGetAriaRole.js
+++ b/test/src/api/commands/web-element/testGetAriaRole.js
@@ -38,6 +38,30 @@ describe('element().getAriaRole() command', function () {
     assert.strictEqual(resultValue, 'signupSection');
   });
 
+  it('test .element().ariaRole()', async function() {
+    MockServer.addMock({
+      url: '/session/13521-10219-202/element/0/computedrole',
+      method: 'GET',
+      response: JSON.stringify({
+        value: 'signupSection'
+      })
+    }, true);
+
+    const resultPromise = this.client.api.element('#signupSection').ariaRole();
+    assert.strictEqual(resultPromise instanceof Element, false);
+    assert.strictEqual(typeof resultPromise.find, 'undefined');
+
+    assert.strictEqual(resultPromise instanceof Promise, false);
+    assert.strictEqual(typeof resultPromise.then, 'function');
+
+    const result = await resultPromise;
+    assert.strictEqual(result instanceof WebElement, false);
+    assert.strictEqual(result, 'signupSection');
+
+    const resultValue = await resultPromise.value;
+    assert.strictEqual(resultValue, 'signupSection');
+  });
+
   it('test .element().find().getAriaRole()', async function() {
     MockServer.addMock({
       url: '/session/13521-10219-202/element/1/computedrole',
diff --git a/test/src/api/commands/web-element/testGetText.js b/test/src/api/commands/web-element/testGetText.js
index 14162147..056bb49f 100644
--- a/test/src/api/commands/web-element/testGetText.js
+++ b/test/src/api/commands/web-element/testGetText.js
@@ -38,6 +38,30 @@ describe('element().getText() command', function () {
     assert.strictEqual(resultValue, 'Signup');
   });
 
+  it('test .element().text() alias', async function() {
+    MockServer.addMock({
+      url: '/session/13521-10219-202/element/0/text',
+      method: 'GET',
+      response: JSON.stringify({
+        value: 'Signup'
+      })
+    }, true);
+
+    const resultPromise = this.client.api.element('#signupSection').text();
+    assert.strictEqual(resultPromise instanceof Element, false);
+    assert.strictEqual(typeof resultPromise.find, 'undefined');
+
+    assert.strictEqual(resultPromise instanceof Promise, false);
+    assert.strictEqual(typeof resultPromise.then, 'function');
+
+    const result = await resultPromise;
+    assert.strictEqual(result instanceof WebElement, false);
+    assert.strictEqual(result, 'Signup');
+
+    const resultValue = await resultPromise.value;
+    assert.strictEqual(resultValue, 'Signup');
+  });
+
   it('test .element().find().getText()', async function() {
     MockServer.addMock({
       url: '/session/13521-10219-202/element/1/text',
@@ -110,4 +134,5 @@ describe('element().getText() command', function () {
     assert.strictEqual(await resultPromise.assert.not.contains('Signupx'), 'Signup');
     assert.strictEqual(await resultPromise.assert.not.matches(/Si[a-z]{2}upx/), 'Signup');
   });
+
 });
diff --git a/types/tests/webElement.test-d.ts b/types/tests/webElement.test-d.ts
index ed24c4f5..0a36e12e 100644
--- a/types/tests/webElement.test-d.ts
+++ b/types/tests/webElement.test-d.ts
@@ -136,6 +136,7 @@ describe('new element() api', function () {
     expectType<ElementValue<string>>(elem.getId());
     expectType<ElementValue<string>>(elem.getTagName());
     expectType<ElementValue<string>>(elem.getText());
+    expectType<ElementValue<string>>(elem.text());
 
     expectType<ElementValue<string | null>>(elem.getProperty('property-name'));
     expectType<ElementValue<string | null>>(elem.getAttribute('attrib-name'));
@@ -151,6 +152,7 @@ describe('new element() api', function () {
 
     expectType<ElementValue<string>>(elem.getAccessibleName());
     expectType<ElementValue<string>>(elem.getAriaRole());
+    expectType<ElementValue<string>>(elem.ariaRole());
     expectType<ElementValue<string>>(elem.getCssProperty('height'));
     expectType<ElementValue<string>>(elem.takeScreenshot());