Running e2e tests on Sauce Labs from Protractor on Travis

对着背影说爱祢 提交于 2019-12-12 08:22:30

问题


So I have my open source project (https://github.com/ahmednuaman/radian) and I have some e2e tests that run fine locally using Protractor.

I've followed the Sauce Labs docs and set up my .travis.yml accordingly. The tests run right to the point where Protractor tries to connect to selenium server on Sauce Labs, this is a brief snapshot of the error:

Running "exec:e2e" (exec) task
Using the selenium server at ahmednuaman-radian:06dd4e07-0f52-4fdf-be5e-389f2117bbf5@localhost:4445
>> 
>> timers.js:103
>> if (!process.listeners('uncaughtException').length) throw e;
>> ^
>> TypeError: Cannot read property 'length' of undefined
>>     at HttpClient.send (/home/travis/.nvm/v0.8.26/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:62:16)

Here's the full job log: https://travis-ci.org/ahmednuaman/radian/jobs/16250460

So the next thing I did was try to emulate this locally. I read the Sauce Labs Connect docs and eventually ran this in my terminal:

java -jar ~/bin/Sauce-Connect.jar USERNAME PASSWORD

Everything started fine, exactly the same as on Travis but as I then ran my grunt e2e task (after updating the protractor.conf.coffee to match the Travis config locally) and recieved the same error as Travis had, here's a snapshot:

Running "exec:e2e" (exec) task
Using the selenium server at ahmednuaman-radian:06dd4e07-0f52-4fdf-be5e-389f2117bbf5@localhost:4445
>> 
>> /Users/ahmed/bin/node/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1542
>>       throw error;
>>             ^
>> TypeError: Cannot read property 'length' of null
>>     at HttpClient.send (/Users/ahmed/bin/node/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:62:16)

I had a google around but I couldn't find anyone else with this problem. So, is it my config? Is it a protractor/webdriver issue? Care to shed any light on this?


回答1:


Ok so after re-reading all the docs again I found that my config.seleniumAddress was incorrect as it was missing the /wd/hub path at the end; then I got a new error: it was complaining about my credentials.

After diving into Protractor's source I found this doozy, it basically wiped out all the sauce* credentials if I specify a seleniumAddress, so I removed it from my config, tried again and it worked! Woop woop! Here's the Travis output just for fun: https://travis-ci.org/ahmednuaman/radian/jobs/16271613

So the way to get Protractor to run on Sauce Labs via Travis is to use these config options:

config.sauceUser = process.env.SAUCE_USERNAME
config.sauceKey = process.env.SAUCE_ACCESS_KEY
config.capabilities =
  'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER
  'build': process.env.TRAVIS_BUILD_NUMBER

And not to add a seleniumAddress.



来源:https://stackoverflow.com/questions/20881660/running-e2e-tests-on-sauce-labs-from-protractor-on-travis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!