Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build with ng e2e and run config file via protractor-flake? #100

Open
idanilovqa opened this issue Nov 1, 2018 · 7 comments
Open

Comments

@idanilovqa
Copy link

Hi there!
We are trying to make protractor-flake work with building our code before running the tests.
Right now all I got working is a command like this "protractor-flake --parser standard --max-attempts=3 -- protractor.conf.js" which is good to run protractor-flake tests on an already built enviroment.

However, every time I try something like "protractor-flake --parser standard --max-attempts=3 -- ng e2e" or similar, I get different errors and nothing works.

What I tried:

  1. Adding flake configuration without protractorConfig to angular.json, and then running npm run flake ("protractor-flake --parser standard --max-attempts=3 -- ng flake./protractor.conf.js") results in three idle and instant re-tries with the message "Error: Error: more than one config file specified"

  2. Executing "protractor-flake --parser standard --max-attempts=3 -- ng e2e" with ./protractor.conf.js defined in e2e/protractorConfig property in angular.json results in the same message and behavior.

  3. Adding the whole "protractor-flake --parser standard --max-attempts=3 -- ./protractor.conf.js" line to e2e/protractorConfig in angular.json and running it via "npm run e2e" command results in code actually being built, but after build is done it all fail with the message:

"[11:03:12] E/configParser - Error code: 105
[11:03:13] E/configParser - Error message: failed loading configuration file C:\Users\ilia.danilov\WebStormProjects\dashboard_frontend\protractor-flake --parser standard --max-attempts=3 -- .\protractor.conf.js
[11:03:13] E/configParser - Error: Cannot find module 'C:\Users\ilia.danilov\WebStormProjects\dashboard_frontend\protractor-flake --parser standard --max-attempts=3 -- .\protractor.conf.js'"

Please, advise what can be done. I searched all internet and never found a single example of using protractor-flake with abgular-cli.

"protractor-flake": "version": "3.3.0",
"protractor": "version": "5.4.1",
"@types/node": "^6.0.117",
"@angular/cli": "^6.2.3".

@sivaram-vu
Copy link

I have the same issue. Could you please suggest.

@NickTomlin
Copy link
Owner

Could I get either of you to create a small repository that reproduces the issue? I personally don't use angular-cli so that would make the problem/use case easier to understand.

Thanks!

@sivaram-vu
Copy link

Hi Nick,

To run the e2e tests as part of the build, We need to configure it in angular.json file.

Below is a sample build configuration to launch protractor.

"testapp-e2e": { "root": "e2e/testapp", "sourceRoot": "e2e/testapp", "projectType": "application", "architect": { "e2e": { "builder": "**@angular-devkit/build-angular:protractor**", "options": { "protractorConfig": "**./protractor.conf.js**", "devServerTarget": "testapp:serve" } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "e2e/tsconfig.e2e.json" ], "exclude": [ "**/node_modules/**" ] } } } },

As per the above code, There is a builder for protractor which takes protractor conf file as input.
Could you please create a custom builder to launch protractor-flake as part of the build process.

Thanks

@NickTomlin
Copy link
Owner

Unfortunately I still don't understand the use case and I don't have time right now to create a custom builder. I'd welcome a pull request for one though since it sounds like it would be helpful for others in the community. Thanks!

@rglynn-dev
Copy link

@sivaram-vu

"[11:03:12] E/configParser - Error code: 105
[11:03:13] E/configParser - Error message: failed loading configuration file C:\Users\ilia.danilov\WebStormProjects\dashboard_frontend\protractor-flake --parser standard --max-attempts=3 -- .\protractor.conf.js
[11:03:13] E/configParser - Error: Cannot find module 'C:\Users\ilia.danilov\WebStormProjects\dashboard_frontend\protractor-flake --parser standard --max-attempts=3 -- .\protractor.conf.js'"

Is your protractor.conf.js really in dashboard_frontend\protractor.conf.js? By default it should be in dashboard_frontend\e2e\protractor.conf.js. If that is the case you want:
protractor-flake --parser standard --max-attempts=3 -- e2e\protractor.conf.js
Just a small thought on that.

As far as getting the build configuration to work with Angular, I too have been searching of a way to achieve this. Having found nothing online about this I have opted to bypass Angular since this is mainly protractor's domain anyway.

Note: this is something of a workaround, I am surprised that Angular/Protractor do not provide some simple way of doing this.

My solution is to run an npm script that uses protractor-flake to run the e2e test suite. Because of the way I have my deployment pipeline setup I cannot simply run protractor-flake, I must first use ng serve (or similar e.g. build -> http-server), because I want to test on localhost. The issue is ng serve && protractor-flake <args> will not work because ng serve does not complete and will block the second command. To get around this I can daemonise (run in the background) ng serve. I used foreverjs to do this (other packages could be used).

My current working script (in package.json "scripts") is as follows:
"e2e-retry": "forever start node_modules/@angular/cli/bin/ng serve && webdriver-manager update && protractor-flake --parser standard --max-attempts=3 -- e2e/protractor.conf.js && forever stopall"
This can be run using npm run e2e-retry.

You may run into a scenario where your tests fail because ng serve takes a while to build, this can be solved by using the onPrepare() method in protractor.conf.js, similarly to how you might deal with a login page (see protractor docs)

@Helen109
Copy link

Helen109 commented Nov 6, 2019

@sivaram-vu

"[11:03:12] E/configParser - Error code: 105
[11:03:13] E/configParser - Error message: failed loading configuration file C:\Users\ilia.danilov\WebStormProjects\dashboard_frontend\protractor-flake --parser standard --max-attempts=3 -- .\protractor.conf.js
[11:03:13] E/configParser - Error: Cannot find module 'C:\Users\ilia.danilov\WebStormProjects\dashboard_frontend\protractor-flake --parser standard --max-attempts=3 -- .\protractor.conf.js'"

Is your protractor.conf.js really in dashboard_frontend\protractor.conf.js? By default it should be in dashboard_frontend\e2e\protractor.conf.js. If that is the case you want:
protractor-flake --parser standard --max-attempts=3 -- e2e\protractor.conf.js
Just a small thought on that.

As far as getting the build configuration to work with Angular, I too have been searching of a way to achieve this. Having found nothing online about this I have opted to bypass Angular since this is mainly protractor's domain anyway.

Note: this is something of a workaround, I am surprised that Angular/Protractor do not provide some simple way of doing this.

My solution is to run an npm script that uses protractor-flake to run the e2e test suite. Because of the way I have my deployment pipeline setup I cannot simply run protractor-flake, I must first use ng serve (or similar e.g. build -> http-server), because I want to test on localhost. The issue is ng serve && protractor-flake <args> will not work because ng serve does not complete and will block the second command. To get around this I can daemonise (run in the background) ng serve. I used foreverjs to do this (other packages could be used).

My current working script (in package.json "scripts") is as follows:
"e2e-retry": "forever start node_modules/@angular/cli/bin/ng serve && webdriver-manager update && protractor-flake --parser standard --max-attempts=3 -- e2e/protractor.conf.js && forever stopall"
This can be run using npm run e2e-retry.

You may run into a scenario where your tests fail because ng serve takes a while to build, this can be solved by using the onPrepare() method in protractor.conf.js, similarly to how you might deal with a login page (see protractor docs)

I use your command "forever start node_modules/@angular/cli/bin/ng serve && webdriver-manager update && protractor-flake --parser standard --max-attempts=3 -- e2e/protractor.conf.js && forever stopall" ro run test.But always hit error "This site can't be reached"when open localhost. Do you have any suggestion?

@rglynn-dev
Copy link

@Helen109

I can't say I have had this problem myself. Would be good to see your console output when this is happening, is everything working successfully? It may be that ng serve is failing but because it is being run by forever you can't see the error being thrown. You might want to check that you can just get your app to be served from a forever process before also attempting to test. i.e. just check that forever start node_modules/@angular/cli/bin/ng serve works and you can access localhost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants