Repository: nightwatchjs/nightwatch (js)

Issue:
Add `isDisplayed()` as an alias command for `isVisible()` in new Element API.
### Description of the bug/issue

For the newly added `.isVisible()` command on the new Element API, we should also add `.isDisplayed()` as an alias to it, so that we can use either `browser.element().isVisible()` or `browser.element().isDisplayed()` in our tests. `.isDisplayed()` is the standard command name in Selenium for checking the "visibility" of an element.


### Steps to reproduce

Go to `ecosia.js` test in `examples/tests` directory and add `browser.element('input[name=q]').isDisplayed();` at the top of the first test case (`it` block). You will see an error that `browser.element(...).isDisplayed is not a function`.

But if you replace `isDisplayed()` with `isVisible()` it will work fine.

So, we need to get `isDisplayed()` command working as well, similar to the `isVisible()` command, without the need to add any new file in the codebase.

### TODO

- [ ] Add `isDisplayed` as an alias to `isVisible` command.
- [ ] Add some more test cases to test `isDisplayed` alias to the already present `web-element/testIsVisible.js` test file.
- [ ] Add types and tests for types.

Pull request description:
Added `isDisplayed()` as alias to `isVisible()`
Fixed #4105 
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.

- [x] Create a new branch from master (e.g. `features/my-new-feature` or `issue/123-my-bugfix`);
- [x] If you're fixing a bug also create an issue if one doesn't exist yet;
- [x] 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;
- [x] 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;
- [x] If your change is based on existing functionality please consider refactoring first. Pull requests that duplicate code will most likely be ignored;
- [x] Do not include changes that are not related to the issue at hand;
- [x] Follow the same coding style with regards to spaces, semicolons, variable naming etc.;
- [x] Always add unit tests - PRs without tests are most of the times ignored.


Patch:
diff --git a/lib/api/client-commands/alerts/accept.js b/lib/api/client-commands/alerts/accept.js
index e7f91ab1..e6308135 100644
--- a/lib/api/client-commands/alerts/accept.js
+++ b/lib/api/client-commands/alerts/accept.js
@@ -20,7 +20,6 @@ const ClientCommand = require('../_base-command.js');
  * @syntax .alerts.accept([callback])
  * @method alerts.accept
  * @param {function} [callback] Optional callback function to be called when the command finishes.
- * @exampleLink /api/acceptAlert.js
  * @see alerts.dismiss
  * @see alerts.getText
  * @see alerts.setText
diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js
index 69cd4212..32b1e4f4 100644
--- a/lib/api/web-element/scoped-element.js
+++ b/lib/api/web-element/scoped-element.js
@@ -24,7 +24,8 @@ class ScopedWebElement {
       'findAllByAltText': ['getAllByAltText'],
       'getRect': ['getSize', 'getLocation'],
       'getProperty': ['property'],
-      'getCssProperty': ['css']
+      'getCssProperty': ['css'],
+      'isVisible': ['isDisplayed']
     };
   }
 
diff --git a/types/web-element.d.ts b/types/web-element.d.ts
index dc2f87aa..1547fc7e 100644
--- a/types/web-element.d.ts
+++ b/types/web-element.d.ts
@@ -194,6 +194,7 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
   isEnabled(): ElementValue<boolean>;
 
   isVisible(): ElementValue<boolean>;
+  isDisplayed(): ElementValue<boolean>;
 }
 
 type WaitUntilOptions = {


Test patch:
diff --git a/test/src/api/commands/web-element/testIsVisible.js b/test/src/api/commands/web-element/testIsVisible.js
index c1ba6c97..ed2fddf5 100644
--- a/test/src/api/commands/web-element/testIsVisible.js
+++ b/test/src/api/commands/web-element/testIsVisible.js
@@ -41,6 +41,33 @@ describe('element().isVisible() command', function() {
     assert.strictEqual(elementId, '0');
   });
 
+  it('test .element().isDisplayed() displayed', async function() {
+    let elementId;
+
+    MockServer.addMock({
+      url: '/session/13521-10219-202/execute/sync',
+      method: 'POST',
+      response: JSON.stringify({
+        value: true
+      }),
+      onRequest(_, requestData) {
+        elementId = requestData.args[0]['element-6066-11e4-a52e-4f735466cecf'];
+      }
+    }, true);
+
+    const resultPromise = this.client.api.element('#signupSection').isDisplayed();
+    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, true);
+    assert.strictEqual(elementId, '0');
+  });
+
   it('test .element().isVisible() not displayed', async function() {
     let elementId;
 
@@ -68,6 +95,33 @@ describe('element().isVisible() command', function() {
     assert.strictEqual(elementId, '0');
   });
 
+  it('test .element().isDisplayed() not displayed', async function() {
+    let elementId;
+
+    MockServer.addMock({
+      url: '/session/13521-10219-202/execute/sync',
+      method: 'POST',
+      response: JSON.stringify({
+        value: false
+      }),
+      onRequest(_, requestData) {
+        elementId = requestData.args[0]['element-6066-11e4-a52e-4f735466cecf'];
+      }
+    }, true);
+
+    const resultPromise = this.client.api.element('#signupSection').isDisplayed();
+    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, false);
+    assert.strictEqual(elementId, '0');
+  });
+
   it('test .element().find().isVisible()', async function() {
     let elementId;
 
diff --git a/types/tests/webElement.test-d.ts b/types/tests/webElement.test-d.ts
index 78edaa90..8a3172f9 100644
--- a/types/tests/webElement.test-d.ts
+++ b/types/tests/webElement.test-d.ts
@@ -142,6 +142,7 @@ describe('new element() api', function () {
     expectType<ElementValue<string | null>>(elem.getValue());
     expectType<ElementValue<boolean>>(elem.isEnabled());
     expectType<ElementValue<boolean>>(elem.isVisible());
+    expectType<ElementValue<boolean>>(elem.isDisplayed());
 
     expectType<ElementValue<ScopedElementRect>>(elem.getRect());
     expectType<ElementValue<ScopedElementRect>>(elem.getSize());