问题
I am new to Cloud9 and I am trying to use Protractor for e2e testing. I am running the angular-phonecat examples.
The error is the folowing:
Using ChromeDriver directly...
/home/ubuntu/workspace/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109
var template = new Error(this.message);
^
UnknownError: chrome not reachable
(Driver info: chromedriver=2.10.267518,platform=Linux 3.14.13-c9 x86_64)
at new bot.Error (/home/ubuntu/workspace/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
..
I installed the chromedriver. The only thing is how to install the actual Chrome on cloud9 and run the tests?
Thank you in advance,
cheers, Haytham
回答1:
I'm a fan of webase IDE and Cloud9 is one of the best. Here a way to install Xvfb, chrome and Protractor for doing AngularJS end-to-end automated testing on Cloud9
Open a terminal (xvfb already installed on c9.io)
install X11 fonts
$ sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
install last chrome
$ wget -q -O - \ https://dl-ssl.google.com/linux/linux_signing_key.pub \ | sudo apt-key add - $ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" \ >> /etc/apt/sources.list.d/google-chrome.list' $ sudo apt-get update $ sudo apt-get install -y google-chrome-stable
install protractor
$ npm install -g protractor
update webdriver
$ webdriver-manager update
use --no-sandbox option with chrome
As c9.io is running inside container this option is needed.
Update protractor conf.js to pass the option to chromecapabilities: { browserName: 'chrome', 'chromeOptions': { args: ['--no-sandbox'] } }
run protractor test on headless chrome
start webdriver with xvfb (headless)
$ xvfb-run webdriver-manager start
run the test on other terminal
$ protrator conf.js
From http://blog.maduma.com
回答2:
Its not possible to 'install' browsers onto cloud9 to run browser-based end-to-end test scenarios. The selenium web driver is looking to load chrome on which to run the tests but is throwing an error as it isn't something which can be found on the cloud9 development environment.
If you are committed to running these tests on an online IDE like cloud9 your only option is to use a headless browser like phantomJS but a note of caution from protractor docs
We recommend against using PhantomJS for tests with Protractor. There are many reported issues with PhantomJS crashing and behaving differently from real browsers.
I would recommend downloading your app locally and running extensive E2E tests across the browsers which your users will actually be using to access your app.
Another option is to use something like Saucelabs (https://saucelabs.com/) for automated cloud-based cross-browser testing; this will need some configuration in the protractor_conf.js
file. Note that there may be additional costs involved with cloud-based testing.
回答3:
I just tested this and it is working for me on my chromebook. It contains all of the steps necessary to complete the first page of https://docs.angularjs.org/tutorial, including setting up the protractor tests.
create new blank workspace
run these commands
rm -rf * .c9
git clone --depth=16 https://github.com/angular/angular-phonecat.git
cd angular-phonecat
nvm install 7
nvm alias default node
npm install minimatch
sudo npm install npm -g
edit this file
angular-phonecat/package.json
"start": "http-server ./app -a $IP -p $PORT -c-1"
run these commands
npm start
click 'Share'
browse to url next to 'Application'
yay! the phonecat webapp should be running!
karma
add these lines to karma.conf.js
hostname: process.env.IP,
port: process.env.PORT
edit package.json
"test": "karma start karma.conf.js --no-browsers"
run this command
npm test
browse to http://<projectName>.<cloud9User>.c9.io:8081
go forth and test!
protractor
run these commands
sudo apt-get update
sudo apt-get install -y xvfb
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable
edit protractor.conf.js
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
args: ['--no-sandbox']
}
}
run these commands
npm install -g protractor
sudo webdriver-manager update
xvfb-run webdriver-manager start
edit protractor.conf.js
baseUrl: 'http://' + process.env.IP + ':' + process.env.PORT + '/'
seleniumAddress: 'http://127.0.0.1:4444/wd/hub'
run these commands
protractor protractor.conf.js
来源:https://stackoverflow.com/questions/27370707/how-to-make-protractor-work-while-using-cloud9