mycargus/nightwatch-docker-grid

Error: EACCES: permission denied, mkdir '/usr/src/app/tests_output'

Closed this issue · 17 comments

First off, thank you for such an awesome tool!

I do have a question regarding permissions on the docker machine. The reports/screenshots are supposed to be stored in "tests_output" folder, but I'm running into an error when running the tests with
npm start/ npm test. The assertion is passing btw.

I updated docker to latest version.
Running tests on macOS Sierra, V. 10.12.6

 Output folder doesn't exist and cannot be created.
 firefox   Error: EACCES: permission denied, mkdir '/usr/src/app/tests_output'

If I update volumes to:

    volumes:
      - .:/usr/src/app
      - .:/usr/src/app/tests_output
      - .:/usr/src/app/screenshots

the error would be:

 Warning: Failed to save report file to folder: tests_output
 firefox   Error: EACCES: permission denied, open 'tests_output/FIREFOX_51.0.1_LINUX_example_test.xml'

Test(default one with a few updates)

module.exports = {
  "Nightwatch.js Test": function(browser) {
    console.log("Nightwatch test started");

    browser.url("my url");
    browser.waitForElementVisible("elem", 50000);
    browser.saveScreenshot("/usr/src/app/screenshots/test.png")  // err: Could not save screenshot
    browser.element("css selector", "elem", function(result) {
      if (result.value.length > 0) {
        console.log("The ticket is visible in Docker");
      } else {
        console.log("The ticket is not visible in Docker");
      }
    });
    browser.end();

    console.log("Nightwatch test finished");
    console.log("¸¸♬·¯·♩¸¸♪·¯·♫¸¸Happy Dance¸¸♬·¯·♩¸¸♪·¯·♫¸¸");
  }
};

Hello! Thanks so much for reporting the issue. I'll take a look this week.

Hey there. Here are some questions and suggestions

  1. Are you sure you used npm start/ npm test or did you mean npm start && npm test or npm start ; npm test?
    Please provide actual commands and steps you used.
  2. Don't try to use host mounted volume, it generates permission errors and it's useless.
  3. Try doing mkdir tests_output before testing.
  4. If I'm not wrong, you can't have the output copied if you use npm locally, you need to use execute ./bin/test for that feature.

Finally, about the problem resolution, isn't a && mkdir -p tests_output just before line 9 in bin/test would get rid of this bug?

EDIT: @aamorozov please try ./bin/start && ./bin/test and tell me if it works.

@rmNyro For the npm start/test, those are just scripts specified in the package.json as following:

"start": "bin/start",    
"stop": "bin/stop",
"test": "bin/test"

So changing them to ./bin/start && ./bin/test didn't change the outcome.

However, after pulling the latest from master(the updates there included your fixes actually), it doesn't give me the original error.

But, even if adding && mkdir -p tests_output in bin/test it still doesn't save the screenshot, nor generates a report file.

On another note, if you fail the test on purpose, the error that being thrown is the following. Is it expected to be an npm error? I'll have some time to look into everything more on a weekend, will do a pr if able to improve some of those things.

firefox   FAILED:  1 assertions failed and 1 passed (5.864s)
 firefox
 firefox    _________________________________________________
 firefox   TEST FAILURE:  1 assertions failed, 1 passed. (6.085s)
 firefox    ✖ example_test
 firefox   - Nightwatch.js Test (5.864s)
 firefox      Expected element <test> to be visible - element was not found  - expected "visible" but got: "not found"
 firefox          at Object.Nightwatch.js Test (/home/docker/app/tests/example_test.js:12:20)
       at _combinedTickCallback (internal/process/next_tick.js:73:7)
 firefox

npm ERR! Linux 4.4.86-boot2docker
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "nightwatch"
npm ERR! node v7.10.1
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! docker-grid-nightwatch@1.0.0 nightwatch: `nightwatch -e chrome,firefox`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the docker-grid-nightwatch@1.0.0 nightwatch script 'nightwatch -e chrome,firefox'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the docker-grid-nightwatch package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nightwatch -e chrome,firefox
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs docker-grid-nightwatch
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls docker-grid-nightwatch
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/.npm/_logs/2017-09-20T14_16_20_417Z-debug.log

I worked on it last night and this morning. There are a handful of issues. I'm making progress on them, will have a commit up in the next day or so. Thank you both for the helpful input!

@aamorozov pull master now and try again. Let me know if it works.

I left the npm start and npm test scripts in place for the reason @aamorozov pointed out---they only call the bin/ scripts.

I see the npm errors too when a test fails. I haven't investigated this yet. Functionally the npm error doesn't seem to affect the outcome, but it's definitely ugly and confusing. I filed issue #12 for it.

@mycargus yes I forgot how that works and I must say I don't find it very intuitive. I'm more of a "simple script user". I like to be able to make something work by brainlessly using commands like ./deploy.sh. Maybe a gulp script with help option and usage would limit the confusion.

@mycargus Yep, it worked, thank you for quick update!! One question related to screenshots, is there a way to pull them from docker to your machine for analyzing? Like screenshot comparison, or further upload to aws bucket for example. Or you have to do all that via docker? Currently, upon failure it takes the screenshot with Test failure! View screenshots in tests_output/screenshots., but I cannot really get to them, unless I miss something completely obvious.

@rmNyro I hear you, I prefer good ol' scripts too 😄 . The project has npm commands just as a nicety for node users who are often accustomed to npm start and npm test commands. If they're causing problems or throwing errors, however, then I'm all in favor of removing them given we have the bin/ scripts.

@aamorozov Not sure I understand. Sounds like the project no longer explodes when an assertion fails, but your host file system doesn't have a tests_output/screenshots directory after the failed test run; is that correct?

The scripts should copy the screenshots to your computer's nightwatch-docker-grid/tests_output/screenshots/ directory after a test fails.

@mycargus
Correct, that what I assumed it would do but currently there is no output into tests_output/screenshots/

Roger that. I just tried it with both the bin scripts and the npm scripts and the screenshots got copied to my host filesystem as expected. ¯_(ツ)_/¯

Try running these commands in the nightwatch-docker-grid repo, please:

  1. git checkout . && git pull && docker-compose kill && docker-compose rm -fv && rm -rf tests_output
  2. open tests/example_test.js and uncomment line 15
  3. bin/build && bin/start && bin/test and observe the tests fail
  4. Verify whether the screenshots are on your computer

If I may, the error was:

 Output folder doesn't exist and cannot be created.
 firefox   Error: EACCES: permission denied, mkdir '/usr/src/app/tests_output'

So it's an error inside the container. Even if I tested the same commands as you @mycargus, like rm -rf tests_output, I think it's totally not related.

Maybe creating tests_output folder after copying local content would fix the bug. Btw, I don't quite understand the changes you made in Dockerfile like:

USER root
ADD . $APP_DIR

# switch back to the docker user
USER $USER

Isn't switching back to root to copy files may generates a permission error like the one encountered @aamorozov? Also doing an npm install before copying files may generates an error if user did an npm install locally because host install would rewrite the container install.
@mycargus I think I can rework the Dockerfile and try to fix this (I also have a mac so maybe I can reproduce the error).

@mycargus @rmNyro

Tried latest suggestion from mycargus but it didn't work for me. Also, if I create tests_output/screenshots/ prior to running the tests it gives me the old error back. I'll need to look into this on the weekend, i feel like I'm missing some simple step here. Steps how I'm doing it from the clean install:

  1. From the root of the nightwatch-docker-grid project npm install;
  2. docker machine start // starts default docker;
  3. eval $(docker-machine env default);
  4. ./bin/build && ./bin/start && ./bin/test // installs everything correctly, runs the tests if I intentionally don't fail them. If i fail them:
  • Without tests_output/screenshots folder - it'll run the tests and output that the screenshot is saved to tests_output/screenshots, but it doesn't exist anywhere;

  • With tests_output/screenshots folder - it'll run the tests but will give me a permission error that it is not able to access:

firefox   Warning: Failed to save report file to folder: tests_output
 firefox   Error: EACCES: permission denied, open 'tests_output/FIREFOX_51.0.1_LINUX_example_test.xml'

But at the end of the output:

Test failure! View screenshots in tests_output/screenshots.

@aamorozov Thank you for providing steps to reproduce the error. There is no need to npm install prior to using the project. The install happens in bin/build. I suggest rm -rf node_modules, then ./bin/build && ./bin/start && ./bin/test.

I'm sorry I haven't addressed this fully yet. It's working for me with dinghy. I'll try it without dinghy this week.

@mycargus
Sorry for late response, tried updating it and tweaking last weekend but wasn't able to make it work. I'll actually try with dinghy and see if it works

I just performed the following steps and the failure screenshots were copied successfully to my host machine ¯_(ツ)_/¯

From the root of this project:

  1. rm -rf node_modules tests_output
  2. uncomment tests/example_test.js:15 to intentionally fail the test
  3. docker-machine start default
  4. eval $(docker-machine env default)
  5. docker-clean # brew install docker-clean if necessary
  6. bin/build && bin/start && bin/test

@aamorozov I've made some changes to the project, including updating Nightwatch to a 1.x version.

The "permission denied" error doesn't surface for me, and the bin/test script successfully copies screenshots to my host filesystem at tests_output/screenshots/example_test/*.png.

I'm going to close this issue but please let me know if you still see it on the latest master branch. Cheers!