nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Trying to build a simple watch mode for the new nightwatch@alpha version #2918

Closed glomotion closed 2 years ago

glomotion commented 2 years ago

Describe the bug

So we're trying to work out how to write a simple watch function for nightwatch, to speed up test development... It looks like some methods have been removed / changed, since v2 alpha... :(

simple watch.js

/* eslint-disable no-console */
const { watch } = require('fs');
const Nightwatch = require('nightwatch');

async function run(filename) {
  const runner = Nightwatch.CliRunner({
    config: './nightwatch.conf.js',
    env: 'default',
    _source: `/src/${filename}`,
  });

  runner.setup();
  await runner.startWebDriver();

  try {
    await runner.runTests();
  } catch (err) {
    console.error('An error occurred:', err);
  }

  await runner.stopWebDriver();
}

watch('src', { recursive: true }, (eventType, filename) => {
  if (filename) {
    run(filename);
  } else {
    console.log('filename not provided');
  }
});

Screen Shot 2021-10-15 at 3 55 13 pm

Run with command

node watch.js

Verbose output

_________________________________________________

TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (2ms)

  TypeError: runner.startWebDriver is not a function
   - writing an ES6 async test case? - keep in mind that commands return a Promise; 
   - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.
       at run (/Users/timpaul/Desktop/GIT-Repos/imx-e2e/watch.js:13:16)
       at FSWatcher.<anonymous> (/Users/timpaul/Desktop/GIT-Repos/imx-e2e/watch.js:26:5)
       at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:186:12)

_________________________________________________

TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (0ms)

  TypeError: runner.startWebDriver is not a function
   - writing an ES6 async test case? - keep in mind that commands return a Promise; 
   - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.
       at run (/Users/timpaul/Desktop/GIT-Repos/imx-e2e/watch.js:13:16)
       at FSWatcher.<anonymous> (/Users/timpaul/Desktop/GIT-Repos/imx-e2e/watch.js:26:5)
       at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:186:12)
<!-- Include the verbose output, if possible (run nightwatch with `--verbose` argument) -->

Configuration

nightwatch.json

```js const path = require('path'); const firefox = require('selenium-webdriver/firefox'); const capabilities = new firefox.Options(); capabilities.addExtensions(path.resolve(__dirname, 'metamask-10.2.2-an+fx.xpi')); module.exports = { src_folders: ['src/tests'], page_objects_path: ['src/pages'], custom_commands_path: ['src/custom-commands'], test_settings: { default: { capabilities, webdriver: { start_process: true, server_path: require('geckodriver').path, // cli_args: ['--verbose'], }, }, }, }; ```

Your Environment

Executable

nightwatch --version

  Nightwatch:
    version: 2.0.0-dev.1
    changelog: https://github.com/nightwatchjs/nightwatch/releases/tag/v2.0.0-dev.1

npm --version

7.20.5

node --version

v14.17.4

Browser drivers

"geckodriver": "^2.0.4",
"nightwatch": "^2.0.0-alpha.3",
"selenium-webdriver": "^4.0.0"

OS

macOS BigSur

11.6 (20G165)
beatfactor commented 2 years ago

Yeah, that's because we don't have to start/stop the webdriver server anymore, it's done automatically by selenium-webdriver. For your purpose, you should use the new programmatic API that was added in v2 alpha-3 and updated in alpha-4.

But this is a pretty cool feature, if you manage to get it working properly, we can add it as an enhancement, if other people will use it.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.