yahoo / protractor-retry

Use protractor features to automatically re-run failed tests with a specific configurable number of attempts.
MIT License
28 stars 32 forks source link

retry fails when protractor is spawned with non-executable node script #55

Open JSMike opened 5 years ago

JSMike commented 5 years ago

For context, this error is happening when using protractor-retry with the Angular-CLI, which starts up a webpack dev server and then launches protractor.

The retry script assumes that argv.$0 will be an executable and in this case tries to spawn a non-executable node script.

This is the result when debugging is turned on and a test fails:

Re-running tests , attempt :  1
Re-running the following test files : /project-path/e2e/retry-test.e2e-spec.ts,/project-path/e2e/scenario/successful-search/successful-search.e2e-spec.ts
Fri, 15 Feb 2019 20:28:07 GMT ProtractorRetry Command node_modules/@angular-devkit/build-angular/src/utils/run-module-worker.js [ [],
  '--specs',
  '/project-path/e2e/retry-test.e2e-spec.ts,/project-path/e2e/scenario/successful-search/successful-search.e2e-spec.ts',
  '--retry',
  1,
  '--disableChecks' ]
[20:28:07] E/launcher - Error: { Error: spawn EACCES
 at _errnoException (util.js:1024:11)
 at ChildProcess.spawn (internal/child_process.js:323:11)
 at Object.exports.spawn (child_process.js:502:9)
 at /project-path/node_modules/protractor-retry/lib/retry.js:151:38
 at Function.promise (/project-path/node_modules/q/q.js:682:9)
 at /project-path/node_modules/protractor-retry/lib/retry.js:150:18
 at Promise.apply (/project-path/node_modules/q/q.js:1165:26)
 at Promise.promise.promiseDispatch (/project-path/node_modules/q/q.js:788:41)
 at /project-path/node_modules/q/q.js:1391:14
 at runSingle (/project-path/node_modules/q/q.js:137:13)
 at flush (/project-path/node_modules/q/q.js:125:13)
 at _combinedTickCallback (internal/process/next_tick.js:131:7)
 at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }
[20:28:07] E/launcher - Process exited with error code 1
An unexpected error occurred: undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1

You can see ProtractorRetry Command node_modules/@angular-devkit/build-angular/src/utils/run-module-worker.js

run-module-worker.js isn't executable, causing the error. I'm assuming that this script in the Angular CLI is waiting for a message that the webpack dev server has started before launching protractor.

This could probably be fixed by adding config to the retry.afterLaunch() function to override the protractor binary path.

JSMike commented 5 years ago

Did some research on this. It's because the angular-cli uses process.fork on a helper module and then runs the protractor launcher inside of a forked process, so it won't work with process.spawn.

dreuxl commented 5 years ago

ok.

We never used the angular-cli for our needs, hence never face that issue. I should at the minimum add that in the caveat list of the README.

I think we got a similar request/issue here : https://github.com/yahoo/protractor-retry/pull/52 I did not have a chance to try myself yet :(

JSMike commented 5 years ago

Ok, I'll keep hacking away at it, if I can get it to work then that pattern should work for everyone using the Angular-CLI, so maybe just adding a flag to the afterLaunch function can toggle default behavior and Angular-CLI.

Oikio commented 5 years ago

@JSMike I've run into the same issue, have you managed to find a workaround?

JSMike commented 5 years ago

@Oikio Sorry, I haven't looked at this in a while, and it looks like I've blown away local changes that I made.

The important things are: https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/protractor/index.ts#L31 https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/utils/run-module-worker.js https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/utils/run-module-as-observable-fork.ts https://github.com/yahoo/protractor-retry/blob/master/lib/retry.js#L94

What's needed is some sort of conditional to check if the retry.js#L94 argv.$0 is executable, then use existing logic to spawn, otherwise spawn node script.

Oikio commented 5 years ago

@JSMike thanks for the update, looks like it can be fixed. So if I won't solve my issue otherwise, I will take a close look at this.

zahnrodolfo commented 5 years ago

@dreuxl @JSMike After a few attempts, I could make it work this way:

Line 94: return Q.fcall(spawn('./node_modules/.bin/protractor', ['path/to/protractor/conf', '--specs', fixedSpecList, '--retry', retryCount, '--disableChecks']));

What I did was change the executable the retry uses to spawn and also I re use the configuration file because without sending the protractor conf file the webdriver-manage update was failing.

Do you guys think that maybe this executable file should be a parameter so we can just choose ours ?

zahnrodolfo commented 5 years ago

This other issue #63 is also caused by the problem mentioned here. So I think you guys can consider it as replicate.

vinodboruah commented 4 years ago

I am experiencing similar failure - I tried executing my protractor test in centos node by command ng e2e and when it tries to execute the failed spec it throws below error Re-running tests , attempt : 1 Re-running the following test files : /home/vinod/zdp/core/zdp-ui/e2e/src/prepare/workflow/Workflow-Category/listcategory.e2e-spec.ts

[17:08:50] E/launcher - spawn node_modules/@angular-devkit/build-angular/src/utils/run-module-worker.js EACCES [17:08:50] E/launcher - Error: spawn node_modules/@angular-devkit/build-angular/src/utils/run-module-worker.js EACCES at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:84:21)

Any suggestion . Thanks in Advance

smcgatheyMT commented 3 years ago

I am getting the same issue as @vinodboruah.