简体   繁体   English

组织3种环境的测试用例

[英]Organizing the test cases for 3 environment

I am new to protractor. 我是量角器的新手。 I have created my test cases for the development environment and it works fine. 我已经为开发环境创建了测试用例,并且工作正常。 Now I have to move my test cases for the production and QA. 现在,我必须移动生产和质量检查的测试用例。

Since the code in 3 environment is same I don't want to create duplicate code for all the 3 environment. 由于3环境中的代码相同,所以我不想为所有3环境创建重复的代码。

In short If I run my code for development I should do 简而言之,如果我运行开发代码,我应该这样做

protractor conf.js -dev

for production 用于生产

protractor conf.js -production.

-dev and -production are the respective url. -dev和-production是各自的URL。 Can anyone tell me a way I can achieve it? 谁能告诉我我可以实现的方法? or should I create 3 conf.js file for the 3 environments? 还是应该为3种环境创建3个conf.js文件?

Best way is, just send the environment type(QA,DEV,PROD) while running protractor from command prompt and before running, you need to add params section on conf.js file as shown below: 最好的方法是,仅在从命令提示符运行量角器时发送环境类型(QA,DEV,PROD),然后再运行,您需要在conf.js文件上添加params部分,如下所示:

1-on conf.js : 1对conf.js

 params: {
         environment:null
  }

2-pass environment value from command prompt 通过命令提示符进行2遍环境值

 protractor --params.environment='QA' conf.js

Based on environment value, you can assign the url to baseUrl parameter inside the: 根据环境值,您可以在以下位置将url分配给baseUrl参数:

onPrepare:function(){
   if(browser.params.environement=QA){
      browser.baseUrl="QA URL"
     }
   else{
      browser.baseUrl="PROD URL"
   }
 };

Pass it in as a command line option. 将其作为命令行选项传递。

protractor --baseUrl='http://www.productionUrl.com' conf.js

Using command line arguments will also override any setting you have in your config file. 使用命令行参数还将覆盖配置文件中的所有设置。 So if your config file had the setting baseUrl='http://www.test.com' , it will take the Url you passed in the command line instead of the config file. 因此,如果您的配置文件具有设置baseUrl='http://www.test.com' ,它将使用您在命令行中传递的Url而不是配置文件。

It's personal preference though, I myself have several config files (different browsers, environments etc). 不过,这是个人喜好,我自己有几个配置文件(不同的浏览器,环境等)。 I use the same config 95% of the time, but every once in awhile it's nice to have the others just for quick access to a specific browser/environment/whatever. 我有95%的时间使用相同的配置,但是偶尔让其他人快速访问特定的浏览器/环境/任何东西,这是很好的。 Plus I don't have to type as much :) 另外,我不必输入太多:)

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

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