Repository: nightwatchjs/nightwatch (js)

Issue:
Example with-page-object of Google failed due to some changes in website
### Description of the bug/issue

![image](https://github.com/nightwatchjs/nightwatch/assets/87136581/d257a153-e04b-401b-a13a-fca301d15547)

Example located in `.\nightwatch\examples\with-page-objects\google.js`  failes due to certain change in selector of google.no menu.

`selector: '#hdtb-msb'` not found on the searchResult page.
Also elements in `nightwatch\page-objects\google\searchResults.js` also needed to be changed as `@class` also changed in menuXpath
```javascript
const menuXpath = '//div[contains(@class, "hdtb-mitem")][contains(., "%s")]';
```


### Steps to reproduce

Run following command to reproduce
```
npx nightwatch .\nightwatch\examples\with-page-objects\google.js
```

### Sample test

_No response_

### Command to run

```bash
npx nightwatch .\nightwatch\examples\with-page-objects\google.js
```


### Verbose Output

_No response_

### Nightwatch Configuration

_No response_

### Nightwatch.js Version

3.4.1

### Node Version

_No response_

### Browser

_No response_

### Operating System

_No response_

### Additional Information

This maybe fixed by locating the menu by role="navigation" in xpath.
Fix should be in consideration to replicate the usecase of that particular example 

Pull request description:
Issue/4106 example google page object
fix #4106 
Need review related to `consentPage` or `consentForm` for now i skipped that part `it.skip()`

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.

- [ ] 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/examples/pages/google/search.js b/examples/pages/google/search.js
index 430d8dc1..17ff4013 100644
--- a/examples/pages/google/search.js
+++ b/examples/pages/google/search.js
@@ -30,7 +30,7 @@ module.exports = {
     consentModal,
 
     searchBar: {
-      selector: 'input[name=q]'
+      selector: 'textarea[name=q]'
     },
 
     submitButton: {
diff --git a/examples/pages/google/searchResults.js b/examples/pages/google/searchResults.js
index 35061c08..458e9e61 100644
--- a/examples/pages/google/searchResults.js
+++ b/examples/pages/google/searchResults.js
@@ -1,5 +1,8 @@
 const util = require('util');
-const menuXpath = '//div[contains(@class, "hdtb-mitem")][contains(., "%s")]';
+
+// starting xpath with './/' tells browser to begin search from the current element,
+// while starting with '//' tells browser to begin search from the start of html document.
+const menuXpath = './/span[contains(text(), "%s")]';
 
 const menuCommands = {
   productIsSelected: function (product, callback) {
@@ -18,15 +21,15 @@ module.exports = {
   },
   sections: {
     menu: {
-      selector: '#hdtb-msb',
+      selector: 'div[role="navigation"] div[data-st-cnt="mode"]',
       commands: [menuCommands],
       elements: {
-        all: {
-          selector: util.format(menuXpath, 'All'),
+        maps: {
+          selector: util.format(menuXpath, 'Maps'),
           locateStrategy: 'xpath',
           index: 0
         },
-        video: {
+        videos: {
           selector: util.format(menuXpath, 'Videos'),
           locateStrategy: 'xpath',
           index: 0
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/commands/takeScreenshot.js b/lib/api/web-element/commands/takeScreenshot.js
index 9f4ab1b2..0818ebd0 100644
--- a/lib/api/web-element/commands/takeScreenshot.js
+++ b/lib/api/web-element/commands/takeScreenshot.js
@@ -6,13 +6,13 @@
  *   demoTest(browser: NightwatchAPI): void {
  *     const screenshot = browser.element('#main').takeScreenshot();
  *     screenshot.then((screenshotData) => {
- *       require('fs').writeFile('out.png', screenshotData, 'base64');
+ *       require('fs/promises').writeFile('out.png', screenshotData, 'base64');
  *     });
  *   },
  *
  *   async demoTestAsync(browser: NightwatchAPI): Promise<void> {
  *     const screenshotData = await browser.element('#main').takeScreenshot();
- *     require('fs').writeFile('out.png', screenshotData, 'base64');
+ *     require('fs/promises').writeFile('out.png', screenshotData, 'base64');
  *   }
  * }
  *
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/lib/runner/cli/cli.js b/lib/runner/cli/cli.js
index 5d14ef2c..5b4e7d5d 100644
--- a/lib/runner/cli/cli.js
+++ b/lib/runner/cli/cli.js
@@ -293,7 +293,7 @@ class CliRunner {
 
       if (plugins.length > 0) {
         plugins.forEach((plugin) => {
-          if (plugin.globals && Utils.isFunction(plugin.globals.registerEventHandlers)){
+          if (plugin.globals && Utils.isFunction(plugin.globals.registerEventHandlers)) {
             plugin.globals.registerEventHandlers(NightwatchEventHub);
           }
         });
@@ -450,7 +450,11 @@ class CliRunner {
   }
 
   isTestWorkersEnabled() {
-    const testWorkers =  this.test_settings.testWorkersEnabled && !singleSourceFile(this.argv);
+    if (this.testRunner.supportsParallelTestSuiteRun === false) {
+      return false;
+    }
+
+    const testWorkers = this.test_settings.testWorkersEnabled && !singleSourceFile(this.argv);
     if (!testWorkers) {
 
       if (this.argv.debug) {
@@ -466,7 +470,7 @@ class CliRunner {
 
       if (isMobile(desiredCapabilities) && !this.usingServer(this.testEnvSettings[env])) {
 
-        if  (Concurrency.isWorker()) {
+        if (Concurrency.isWorker()) {
           Logger.info('Disabling parallelism while running tests on mobile platform');
         }
 
diff --git a/package-lock.json b/package-lock.json
index cab803a9..da13123a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "nightwatch",
-  "version": "3.4.1",
+  "version": "3.5.0",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "nightwatch",
-      "version": "3.4.1",
+      "version": "3.5.0",
       "license": "MIT",
       "dependencies": {
         "@nightwatch/chai": "5.0.3",
diff --git a/package.json b/package.json
index 44b8556f..db55b8c8 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "nightwatch",
   "description": "Easy to use Node.js based end-to-end testing solution for web applications using the W3C WebDriver API.",
-  "version": "3.4.1",
+  "version": "3.5.0",
   "author": "Andrei Rusu",
   "homepage": "https://nightwatchjs.org",
   "main": "./lib/index.js",
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/examples/tests/googlePageObject.js b/examples/tests/googlePageObject.js
index 49be3b26..1823599a 100644
--- a/examples/tests/googlePageObject.js
+++ b/examples/tests/googlePageObject.js
@@ -1,30 +1,10 @@
 describe('google search with consent form - page objects', function() {
-
-  this.disabled = this.argv.env !== 'chrome';
-
   const homePage = browser.page.google.search();
-  const consentPage = browser.page.google.consent();
 
   before(async () => homePage.navigate());
 
   after(async (browser) => browser.quit());
 
-  it.only('should complete the consent form', async function (browser) {
-
-    // const consentForm = consentPage.section.consentForm;
-    // const submitButton = consentForm.element('@submitButton');
-
-    const oldElement = await browser.element('css selector', 'body');
-    const consentPresent = await homePage.isPresent('@consentModal');
-
-    if (consentPresent) {
-      await homePage.expect.section('@consentModal').to.be.visible;
-
-      const {consentModal} = homePage.section;
-      await consentModal.click('@rejectAllButton');
-    }
-  });
-
   it('should find nightwatch.js in results', function (browser) {
     homePage.setValue('@searchBar', 'Nightwatch.js');
     homePage.submit();
@@ -37,6 +17,6 @@ describe('google search with consent form - page objects', function() {
     resultsPage.expect.section('@menu').to.be.visible;
 
     const menuSection = resultsPage.section.menu;
-    menuSection.expect.element('@all').to.be.visible;
+    menuSection.expect.element('@videos').to.be.visible;
   });
 });
diff --git a/lib/runner/test-runners/cucumber.js b/lib/runner/test-runners/cucumber.js
index 6a505a03..bb270a63 100644
--- a/lib/runner/test-runners/cucumber.js
+++ b/lib/runner/test-runners/cucumber.js
@@ -246,6 +246,10 @@ class CucumberSuite extends TestSuite {
 
 class CucumberRunnner extends Runner {
   get supportsConcurrency() {
+    return true;
+  }
+
+  get supportsParallelTestSuiteRun() {
     return false;
   }
 
diff --git a/test/cucumber-integration-tests/testCucumberTestsInParallel.js b/test/cucumber-integration-tests/testCucumberTestsInParallel.js
index ca6a7ae3..f34c9702 100644
--- a/test/cucumber-integration-tests/testCucumberTestsInParallel.js
+++ b/test/cucumber-integration-tests/testCucumberTestsInParallel.js
@@ -5,17 +5,17 @@ const commandMocks = require('../lib/command-mocks.js');
 const common = require('../common.js');
 const MockServer = require('../lib/mockserver.js');
 
-describe('Cucumber integration - parallel running single formatter', function() {
-  beforeEach(function(done) {
+describe('Cucumber integration - parallel running single formatter', function () {
+  beforeEach(function (done) {
     this.server = MockServer.init(null, {port: 10190});
     this.server.on('listening', () => done());
   });
 
-  afterEach(function(done) {
+  afterEach(function (done) {
     Globals.afterEach.call(this, done);
   });
 
-  it('testCucumberSampleTests in parallel with single formatter', function() {
+  it('testCucumberSampleTests in parallel with single formatter', function () {
     const source = [
       path.join(__dirname, './sample_cucumber_tests/parallel/testSample.js')
     ];
@@ -41,7 +41,7 @@ describe('Cucumber integration - parallel running single formatter', function()
       });
   });
 
-  it('testCucumberSampleTests in parallel with multiple step definition files', function() {
+  it('testCucumberSampleTests in parallel with multiple step definition files', function () {
 
     commandMocks.elementText('5cc459b8-36a8-3042-8b4a-258883ea642b', 'xx');
 
@@ -56,6 +56,7 @@ describe('Cucumber integration - parallel running single formatter', function()
       parallel: true,
       verbose: true,
       timeout: 10,
+      env: 'chrome',
       silent: false,
       tags: ['not @fail'],
       format: 'progress',
@@ -71,4 +72,36 @@ describe('Cucumber integration - parallel running single formatter', function()
         assert.strictEqual(errorOrFailed, false);
       });
   });
-});
\ No newline at end of file
+
+  it('testCucumberSampleTests in parallel environments with multiple step definition files', function () {
+
+    commandMocks.elementText('5cc459b8-36a8-3042-8b4a-258883ea642b', 'xx');
+
+    const source = [
+      path.join(__dirname, './sample_cucumber_tests/parallelWithMultipleDefinition')
+    ];
+
+    const {runTests} = common.require('index.js');
+
+    return runTests({
+      source,
+      parallel: true,
+      verbose: true,
+      timeout: 10,
+      env: 'chrome,firefox',
+      silent: false,
+      tags: ['not @fail'],
+      format: 'progress',
+      config: path.join(__dirname, '../extra/cucumber-config-parallel.js'),
+      'format-options': '',
+      ['retry-interval']: 5,
+      ['persist-globals']: true,
+      ['webdriver-host']: 'localhost',
+      ['start-process']: false,
+      ['webdriver-port']: 10190
+    }, {})
+      .then(errorOrFailed => {
+        assert.strictEqual(errorOrFailed, false);
+      });
+  });
+});
diff --git a/test/extra/cucumber-config-parallel.js b/test/extra/cucumber-config-parallel.js
index 302ea421..16badba9 100644
--- a/test/extra/cucumber-config-parallel.js
+++ b/test/extra/cucumber-config-parallel.js
@@ -26,6 +26,19 @@ module.exports = {
       feature_path: path.join(__dirname, '../cucumber-integration-tests/sample_cucumber_tests/parallel/sample.feature')
     }
   },
+
+  test_settings: {
+    chrome: {
+      desiredCapabilities: {
+        browserName: 'chrome'
+      }
+    },
+    firefox: {
+      desiredCapabilities: {
+        browserName: 'firefox'
+      }
+    }
+  },
   output: false,
   silent: false
-}
\ No newline at end of file
+};
\ No newline at end of file
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());