简体   繁体   English

在Angular-CLI e2e量角器测试中更改baseUrl

[英]Change baseUrl on Angular-CLI e2e protractor test

I would like to run my angular e2e test against a running server. 我想对正在运行的服务器运行我的angular e2e测试。 The default URL is configured in the protractor.conf.js file but it seems like there is no command line argument which allow to override it at runtime. 默认URL在protractor.conf.js文件中配置,但似乎没有允许在运行时覆盖它的命令行参数。 I tried using the option --public-host but it does not work. 我尝试使用--public-host选项,但是它不起作用。 Is there any solution other than override the protractor.conf.js file? 除了覆盖protractor.conf.js文件之外,还有其他解决方案吗?

You can pass command line arguments, I never worked with Angular CLI, but what you can normally do is add this behind the script you are running ng e2e --baseUrl=http://your.other.url.com , it could be that Angular CLI needs a double -- so it becomes ng e2e -- --baseUrl=http://your.other.url.com . 您可以传递命令行参数,但我从未使用过Angular CLI,但是通常可以做的是将其添加到正在运行ng e2e --baseUrl=http://your.other.url.com的脚本后面。 Angular CLI需要加倍--因此它变成ng e2e -- --baseUrl=http://your.other.url.com The double -- could be needed to tell that command line arguments are passed. --可能需要告诉命令行参数传递。 You don't need to do that if you have multiple command line arguments, only add it once, if Angular CLI needs it. 如果您有多个命令行参数,则无需执行此操作,如果Angular CLI需要,则只需添加一次即可。 I normally use it when I have a npm script. 我通常在有npm脚本时使用它。

Good luck 祝好运

It looks like the latest version of @angular/cli released yesterday ( see changelog ) is resolving the issue to override the baseUrl. 看来昨天发布的最新版本的@ angular / cli( 请参阅changelog )正在解决该问题,以覆盖baseUrl。 However, it does not work when combined with the option --serve false . 但是,与选项--serve false组合使用时,它不起作用。

对于角度6,唯一有效的命令是这样

ng e2e --dev-server-target="" --base-url="https://localhost:8080"

Passing --no-serve and --base-href=http://yoururltotest:8080 will not build as well as serve the passed base url in --base-href= from the command. 传递--no-serve--base-href=http://yoururltotest:8080不会像在命令中的--base-href=那样传递传递的基本url,也无法生成和构建。

I tried other combinations of/with options but did not work. 我尝试了其他带有选项的组合,但没有用。

so the command will be 所以命令将是

ng e2e --no-serve --base-href=https://yoururltotest:8888

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM