I love automated testing, and I really love Protractor testing. Although Protractor is an e2e testing tool created by Google and popularized on AngularJS projects, I've heard that it was possible to use it with non-Angular sites. When I tried I had a bit of trouble, but in this post I'll show you how I managed to get it working.
If you don't know by now, my go-to yeoman generator that I recommend to everyone is Gulp-Angular. This will set you up with protractor testing right out of the box! All you have to do is run this from the command line:
The only thing the above script really does is load up the index page of your application. This is all fine and dandy, but suppose you wanted to run protractor on a random site like www.facebook.com? If we naively just swap out the '/index' with 'http://www.facebook.com' our protractor runner will crash with a message, "Failed: Angular could not be found on the page **: retries looking for angular exceeded". Ouch!
Thanks to the number 1 answer of this stack overflow question, I realized that in order to tell Protractor not to look for Angular you have to load up the page with the underlying web-driver instance. To do this simply use browser.driver.get(...) instead of usual browser.get(...) syntax. The completed suite for testing Facebook with Protractor would look something like this:
The posts on this site are written and maintained by Jim Lynch. About Jim...
Want FREE access to
my daily stock tips
"The Triple Gainers"?
Sign up here!