Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Using Protractor on Non-Angular Sites

6/16/2016

0 Comments

 
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.

Step 1: Set up A Project with Protractor

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: 
gulp protractor

Step 2: Create a Test Suite

Remember, test suites in JavaScript can be thought of as a "describe full of it's". Our gulp scripts from Gulp-Angular will look for files in our e2e directory that have a .spec.js ending. Here's an example of a simple protractor test suite:
'use strict';

describe('The main view', function () {
  
  beforeEach(function () {
    browser.get('/index');

 });

  it('should do nothing', function () {

  })

});
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!
Picture

Step 3 (The Aha Moment): Use browser.DRIVER.get

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:
'use strict';

describe('The main view', function () {
  
  beforeEach(function () {
    browser.driver.get('http://www.facebook.com');

 });

  it('should do nothing', function () {

  })

});
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Want FREE access to
    my daily stock tips 
    ​newsletters??
    Sign up here:

    - Triple Gainers
    - Rippers N' Dippers
    - Growingest Growers
    ​

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021