问题
Some Background
I've been reading up about Protractor Tests running on a Jenkins Server. I'm still a little confused as to how you can start the selenium server on a Jenkins Build. Since you need to first run the following 2 commands
webdriver-manager update
webdriver-manager start
and then you need to run the appropriate protractor command
protractor conf.js
The Problem
Once you've run the first 2 commands, you essentially need to leave that command window open for the server to continue to run, in such a case how are you able to call the protractor command? since you need the original command line to keep running
I was hoping someone has found a clean way of doing this. Maybe a pre-requisite script that runs? or somehow being able to kick off multiple command lines on the server?
I was also looking for a way you could also quit the command Selenium Server Command Prompt when the tests are finished executing, this would make the whole process a lot more cleaner aswell.
回答1:
If you remove the seleniumAddress
from your protractor conf.js
, protractor will start the selenium automatically. Example:
With the seleniumAddress
on the conf.js
:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [ 'spec.js' ]
};
Removing the seleniumAddress
on the conf.js
:
exports.config = {
specs: [ 'spec.js' ]
};
Now, using the protractor conf.js
, protractor will start the selenium server automatically as you need.
回答2:
You can archive your goal with npm packages: concurrently and delay-cli.
Add them as dependencies.
// package.json
"scripts": [
"wstart": "webdriver-manager update && webdriver-manager start",
"test": "concurrently --kill-others \"npm run wstart\" \"delay 10 && protractor conf.js\""
]
execute npm run test
来源:https://stackoverflow.com/questions/52074166/protractor-how-do-i-start-the-selenium-server-on-a-jenkins-build