问题
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.
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. Can anyone tell me a way I can achieve it? or should I create 3 conf.js file for the 3 environments?
回答1:
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.
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. Plus I don't have to type as much :)
回答2:
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:
1-on conf.js:
params: {
environment:null
}
2-pass environment value from command prompt
protractor --params.environment='QA' conf.js
Based on environment value, you can assign the url to baseUrl parameter inside the:
onPrepare:function(){
if(browser.params.environement=QA){
browser.baseUrl="QA URL"
}
else{
browser.baseUrl="PROD URL"
}
};
来源:https://stackoverflow.com/questions/39368149/organizing-the-test-cases-for-3-environment