Front end testing with CleverStack

posted in: AngularJS, Cleverstack, Testing | 0

What is Protractor and how to use it, for reference:

http://www.ng-newsletter.com/posts/practical-protractor.html

https://egghead.io/lessons/angularjs-getting-started-with-protractor

http://engineering.wingify.com/posts/e2e-testing-with-webdriverjs-jasmine/

http://ramonvictor.github.io/protractor/slides/#/

http://ng-learn.org/2014/02/Protractor_Testing_With_Angular_And_Non_Angular_Sites/

https://www.exratione.com/2013/12/angularjs-headless-end-to-end-testing-with-protractor-and-selenium/

http://product.moveline.com/testing-angular-apps-end-to-end-with-protractor.html

Create a new project:

clever init clever-walking-skeleton-10.0/

Preparing...
  Creating installation path /Users/nomad/Projects/clever-walking-skeleton-10.0/...
  Finding seeds to target for installation...
  Starting installation...

Installing Backend...
  Installation path is /Users/nomad/Projects/clever-walking-skeleton-10.0/backend...
  Downloading and extracting node-seed...
  Creating local configuration file config/local.json...
  Installing NPM modules...
  Installing bundledDependencies...
  Backend installation has completed successfully!

Installing Frontend...
  Installation path is /Users/nomad/Projects/clever-walking-skeleton-10.0/frontend...
  Downloading and extracting angular-seed...
  Installing NPM modules...
  Installing bundled modules...
  Installing bower components...
  Building frontend...
  Frontend installation has completed successfully.
  Installing protractor...
  Protractor successfully installed...


Project clever-walking-skeleton-10.0/ has been created in /Users/nomad/Projects/clever-walking-skeleton-10.0/

Delete the backend directory.

Edit this file:

/Users/nomad/Projects/clever-walking-skeleton-10.0/frontend/test-e2e.conf.js

  // The location of the selenium standalone server .jar file.
  // http://docs.seleniumhq.org/download/
  // seleniumServerJar: './scripts/selenium-server-standalone-2.39.0.jar',
  // The port to start the selenium server on, or null if the server should
  // find its own unused port.
  // seleniumPort: 4444,
  // https://npmjs.org/package/protractor
  seleniumAddress: 'http://localhost:4444/wd/hub',
  // Chromedriver location is used to help the selenium standalone server
  // find chromedriver. This will be passed to the selenium jar as
  // the system property webdriver.chrome.driver. If null, selenium will
  // attempt to find chromedriver using PATH.
  // chromeDriver: isWin ? './scripts/Chromedriver.exe' : './scripts/Chromedriver',
  // Additional command line options to pass to selenium. For example,
  // if you need to change the browser timeout, use
  // seleniumArgs: ['-browserTimeout=60'],
  seleniumArgs: [],

 

Go into the frontend folder
cd frontend/

 

clever test unit
Scanning folders for Gruntfiles...
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.10 server started at http://localhost:9090/
INFO [launcher]: Starting browser Chrome
INFO [launcher]: Starting browser PhantomJS
WARN [watcher]: Pattern "/Users/nomad/Projects/clever-walking-skeleton-10.0/frontend/app/modules/**/directives/*.js" does not match any file.
WARN [watcher]: Pattern "/Users/nomad/Projects/clever-walking-skeleton-10.0/frontend/app/modules/**/factories/*.js" does not match any file.
WARN [watcher]: Pattern "/Users/nomad/Projects/clever-walking-skeleton-10.0/frontend/app/modules/**/services/*.js" does not match any file.
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket a0H2On9cZfUpsxhP-L74
INFO [Chrome 35.0.1916 (Mac OS X 10.9.3)]: Connected on socket 4sdEC29aciR51il_-L75
PhantomJS 1.9.7 (Mac OS X) WARN: 'Unable to read href attr from base tag'
PhantomJS 1.9.7 (Mac OS X) WARN: 'Unable to read href attr from base tag'
Chrome 35.0.1916 (Mac OS X 10.9.3) WARN: 'Unable to read href attr from base tag'
Chrome 35.0.1916 (Mac OS X 10.9.3) WARN: 'Unable to read href attr from base tag'
PhantomJS 1.9.7 (Mac OS X): Executed 1 of 1 SUCCESS (0.213 secs / 0.009 secs)
Chrome 35.0.1916 (Mac OS X 10.9.3): Executed 1 of 1 SUCCESS (0.297 secs / 0.014 secs)
TOTAL: 2 SUCCESS

Done, without errors.


Execution Time (2014-06-28 10:15:12 UTC)
loading tasks  815ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25%
karma:unit      2.5s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 75%
Total 3.3s
Tests ran successfully.

Open a new console window in frontend

 

webdriver-manager start
seleniumProcess.pid: 5119
Jun 28, 2014 12:18:07 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
Setting system property webdriver.chrome.driver to /usr/local/lib/node_modules/protractor/selenium/chromedriver
12:18:07.797 INFO - Java: Apple Inc. 20.65-b04-462
12:18:07.797 INFO - OS: Mac OS X 10.9.3 x86_64
12:18:07.806 INFO - v2.42.2, with Core v2.42.2. Built from revision 6a6995d
12:18:07.866 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: MAC
12:18:07.895 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
12:18:07.896 INFO - Version Jetty/5.1.x
12:18:07.897 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
12:18:07.897 INFO - Started HttpContext[/selenium-server,/selenium-server]
12:18:07.897 INFO - Started HttpContext[/,/]
12:18:07.930 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1f25fefa
12:18:07.930 INFO - Started HttpContext[/wd,/wd]
12:18:07.937 INFO - Started SocketListener on 0.0.0.0:4444
12:18:07.937 INFO - Started org.openqa.jetty.jetty.Server@1d5a0305

From the previous console window run:

Expect it to fail because of many reasons.

We will remedy this by deleting all the tests and starting from scratch

DO:

cd backend

grunt db

grunt serve

Change home.test.js

// test if the homepage is loading
describe('e2e: home', function() {

 var ptor;
 beforeEach(function() {
 ptor = protractor.getInstance();
 ptor.ignoreSynchronization = true;
 ptor.get('/');
 });

 it('should load the home page', function() {
 expect(ptor.isElementPresent(protractor.By.id('home'))).toBe(true);
 });

});

clever

DO:

clever test e2e

 

clever test e2e
Scanning folders for Gruntfiles...
Running "connect:livereload" (connect) task
Started connect web server on 127.0.0.1:9000.

Running "protractor:singlerun" (protractor) task
Using the selenium server at http://localhost:4444/wd/hub
.

Finished in 1.578 seconds
1 test, 1 assertion, 0 failures


Done, without errors.


Execution Time (2014-07-02 09:25:32 UTC)
loading tasks         885ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 21%
protractor:singlerun   3.3s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 79%
Total 4.2s
Running "mochaTest:e2e" (mochaTest) task
No files to check...OK

Done, without errors.
Tests ran successfully.

Leave a Reply