-
Notifications
You must be signed in to change notification settings - Fork 12k
Setting baseUrl in protractor.conf is not working #11089
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
Comments
I have the same problem here. Is there any information about when this is fixed? Or is there a certain workaround? |
It seems to have to do with using the "serve" target for that configuration, which for some reason overwrites the baseUrl from the protractor.conf. We managed to work around it by either modifying the default "production" e2e config to not use the "serve" as "devServerTarget", or creating a separate configuration in the e2e project part of the angular.json for accessing a different webserver, like this:
The first "local" config is used for e2e testing against a locally running "ng served" web server, and the "remote" config is used to run the test suite against a remote web server, which is configured using the baseUrl in the different protractor.conf.remote.js. Maybe this will help other people with the same problem. Update: Just to clarify, you don't need a separate protractor.conf in case you only want to overwrite the baseUrl. You can simply do that using the "baseUrl" property of the configuration, or the "base-url" command line parameter:
|
You can pass --public-host arg to your ng e2e call (i.e: ng e2e --public-host="https://hostname.com") |
@Schmaga - Leaving the "options" block empty like that causes the following error: I have a local build that needs to point to a dedicated selenium server (not localhost) and while I was hopeful this would work, isn't acting as expected even when I add distinct 'baseURL' arguments to both "remote" and "local" blocks within "configurations" |
Here's my angular.json block for 'e2e':
|
@mtaylor769 Sorry I should have explained that the options block was omitted for brevity |
@Schmaga understood, but I'm still seeing the issue of it redirecting to localhost:4200 in the 'beforeEach' in the spec unless I prepend some sort of 'baseURL' that's hardcoded in a config somewhere. My understanding was that the variables declared and set in the beforeEach were then in scope for the subsequent tests. One note, however, I am using Page Object Models and it's the browser.get() calls in those that I am seeing this behavior in. (https://github.com/angular/protractor/blob/master/docs/page-objects.md) |
@mtaylor769 Are you sure you are not still using the "serve" target? That always seems to overwrite the baseUrl. |
Anyone facing this issue, please an answer here. |
I'm setting up a Selenium grid and after getting it to work, wanted to share a composition of what you need to do. Basically the workaround is to remove the angular.json snippet:
protractor.conf.js:
commands to run in parallel:
ng e2e will instruct the external Selenium server to run tests against the server accessible via baseUrl |
Unless I'm missing something here, this behaviour is very much intended. When So if you don't actually want to use the devServer, you should create a configuration that sets |
One problem I have is that the value needs to be dynamic as we don't know where the server is going to be accessible from ahead of time. We're using Jenkins pipelines to run the e2e tests. That Jenkins executor is bought up dynamically within a Kubernetes cluster and will have a randomised IP. Our Selenium grid deploys pods in Kubernetes and needs to be able to access the package.json scripts: "scripts": {
"e2e": "ng e2e",
"e2e:ci": "CI=true npm run e2e",
"serve": "ng serve --host=0.0.0.0 --disable-host-check"
} Jenkinsfile pipeline for starting the e2e tests: POD_POST = sh (
script: 'ip r show dev "$(ip r|awk \'$1=="default"{print$NF}\')"|awk \'$1!="default"{print$NF}\'',
returnStdout: true
).trim()
withEnv(['POD_HOST=' + POD_POST]) {
sh 'docker-compose up --abort-on-container-exit ngserve e2e'
} docker-compose.yml: services:
ngserve:
image: app
build: .
command: npm run serve
ports:
- "4200:4200"
e2e:
image: app
command: npm run e2e:ci
depends_on:
- ngserve
environment:
POD_HOST: Inside the protractor.config.js file: baseUrl: process.env.CI ? `http://${process.env.POD_HOST}:4200` : 'http://localhost:4200/',
directConnect: process.env.CI ? false : true,
seleniumAddress: 'https://zalenium.k8s.ourserver.io/wd/hub', When you deploy within a K8S cluster the host/port are totally randomised and I don't see how this can be accomplished within Everything I used to use was ripped away from CLI and placed into static configuration files and it just gets more and more difficult to accomplish :) |
@intellix no, there isn't a good way to call call That's an interest use case. I'm not sure how it can be addressed without fully exposing all transitive dependencies. Perhaps by allowing the config file to pull values from the environment or commands. |
I'm faced with a similar issue, except I'm using Travis CI. During my builds, I need to get the Docker Host IP in Travis CI, and I'm not certain if that IP will be random. It is the last piece I need to ensure my angular e2e tests pass on Travis CI. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Versions
Repro steps
Observed behavior
Desired behavior
I think it should go to what the baseurl is set to.
Mention any other details that might be useful (optional)
I add browser.sleep(900000) in the first test after navigateTo so I have time to see what is going on.
The text was updated successfully, but these errors were encountered: