Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running e2e tests on Sauce Labs from Protractor on Travis

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?

like image 221
Ahmed Nuaman Avatar asked Jan 02 '14 11:01

Ahmed Nuaman


People also ask

How do you run tests on Sauce Labs?

First of all we need to create a function in our script to run Sauce Labs. In order get the sample code to create the function, go to the Sauce Labs web site and click Support & Services tab and then click Documentation link. After that, navigate to Getting Started tab and navigate to Instant Selenium Java Tests tab.

Why is Protractor being deprecated?

Protractor Will Be Deprecated Some of the reasons behind these deprecation plans are: State of Protractor. Protractor is dependent on selenium-webdriver , and is not able to upgrade to the new version without introducing a huge breaking change, and forcing users to do a migration for all their tests.

What is Sauce Labs live testing?

With Sauce Labs, you can test your mobile apps on a variety of Android and iOS devices. If you do not have an app, consider using the Sauce Labs Swag Labs sample app for validating your account functionality as well as your tests.


1 Answers

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.

like image 168
Ahmed Nuaman Avatar answered Oct 13 '22 22:10

Ahmed Nuaman