diff --git a/core/tests/Drupal/Nightwatch/Pages/TestPage.js b/core/tests/Drupal/Nightwatch/Pages/TestPage.js new file mode 100644 index 0000000000000000000000000000000000000000..871940369f7df7a331671f151a5d94fefa30009f --- /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 5e0dc4b86de542c21312fd291a7563be93c9a3b6..04f21954d07d3414851f1ddc23db115dbadbf8a5 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 d27517045a7433dcd7b25bf7ce0055a03a0e0a9c..7f4cb83529b8ef86640294b0b9c246b9562d1a44 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 468ee65cadf51d6e69fe3961ec9ce76ee1db953c..701f81f6681679f7b40e9f010379496eb4ea09bc 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`.