From a0475565694b68f0db86134121da371c09851efe Mon Sep 17 00:00:00 2001
From: Lauri Eskola <lauri.eskola@acquia.com>
Date: Fri, 22 Feb 2019 08:15:03 +0200
Subject: [PATCH] Issue #2981602 by jansete, Lendude, askibinski, alexpott,
 dawehner, slv_, Sam152: Add page objects integration to Nightwatch

---
 core/tests/Drupal/Nightwatch/Pages/TestPage.js    | 11 +++++++++++
 core/tests/Drupal/Nightwatch/Tests/exampleTest.js |  9 +++++++++
 core/tests/Drupal/Nightwatch/nightwatch.conf.js   |  3 ++-
 core/tests/README.md                              |  4 +++-
 4 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 core/tests/Drupal/Nightwatch/Pages/TestPage.js

diff --git a/core/tests/Drupal/Nightwatch/Pages/TestPage.js b/core/tests/Drupal/Nightwatch/Pages/TestPage.js
new file mode 100644
index 000000000000..871940369f7d
--- /dev/null
+++ b/core/tests/Drupal/Nightwatch/Pages/TestPage.js
@@ -0,0 +1,11 @@
+module.exports = {
+  props: {
+    text: 'Test page text',
+    timeout: 1000,
+  },
+  elements: {
+    body: {
+      selector: 'body',
+    },
+  },
+};
diff --git a/core/tests/Drupal/Nightwatch/Tests/exampleTest.js b/core/tests/Drupal/Nightwatch/Tests/exampleTest.js
index 5e0dc4b86de5..04f21954d07d 100644
--- a/core/tests/Drupal/Nightwatch/Tests/exampleTest.js
+++ b/core/tests/Drupal/Nightwatch/Tests/exampleTest.js
@@ -15,4 +15,13 @@ module.exports = {
       .assert.containsText('body', 'Test page text')
       .drupalLogAndEnd({ onlyOnError: false });
   },
+  'Page objects test page': browser => {
+    const testPage = browser.page.TestPage();
+
+    testPage
+      .drupalRelativeURL('/test-page')
+      .waitForElementVisible('@body', testPage.props.timeout)
+      .assert.containsText('@body', testPage.props.text)
+      .drupalLogAndEnd({ onlyOnError: false });
+  },
 };
diff --git a/core/tests/Drupal/Nightwatch/nightwatch.conf.js b/core/tests/Drupal/Nightwatch/nightwatch.conf.js
index d27517045a74..7f4cb83529b8 100644
--- a/core/tests/Drupal/Nightwatch/nightwatch.conf.js
+++ b/core/tests/Drupal/Nightwatch/nightwatch.conf.js
@@ -7,6 +7,7 @@ const collectedFolders = {
   Tests: [],
   Commands: [],
   Assertions: [],
+  Pages: [],
 };
 const searchDirectory = process.env.DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY || '';
 
@@ -45,7 +46,7 @@ module.exports = {
   output_folder: process.env.DRUPAL_NIGHTWATCH_OUTPUT,
   custom_commands_path: collectedFolders.Commands,
   custom_assertions_path: collectedFolders.Assertions,
-  page_objects_path: '',
+  page_objects_path: collectedFolders.Pages,
   globals_path: 'tests/Drupal/Nightwatch/globals.js',
   selenium: {
     start_process: false,
diff --git a/core/tests/README.md b/core/tests/README.md
index 468ee65cadf5..701f81f66816 100644
--- a/core/tests/README.md
+++ b/core/tests/README.md
@@ -123,12 +123,14 @@ sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional-javascri
 - To skip running core tests, run `yarn test:nightwatch --skiptags core`
 - To run a single test, run e.g. `yarn test:nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js`
 
-Nightwatch tests can be placed in any folder with the pattern `**/tests/**/Nightwatch/(Tests|Commands|Assertions)`. For example:
+Nightwatch tests, as well as custom commands, assertions and pages, can be placed in any folder with the pattern `**/tests/**/Nightwatch/(Tests|Commands|Assertions|Pages)`. For example:
 ```
 tests/Nightwatch/Tests
 src/tests/Nightwatch/Tests
 tests/src/Nightwatch/Tests
 tests/Nightwatch/Commands
+tests/src/Nightwatch/Assertions
+tests/src/Nightwatch/Pages
 ```
 
 It's helpful to follow existing patterns for test placement, so for the action module they would go in `core/modules/action/tests/src/Nightwatch`.
-- 
GitLab