Tag Archives: jasmine

Javascript page object pattern based functional tests via the browser with Protractor and Astrolabe

Update: 26/04/14 – added example github project showing an example project with config setup and simple test.

Example project on github: https://github.com/onekilo79/protractor-astrolabe-example

Purpose

Page Object Pattern

When writing browser based tests with selenium the test can become brittle if they are too attached to the xpath of the css selector when the page look and feel changes.  To limit your exposure to changes in the styling of the page you can use the Page Object Pattern.

Library that does Page Object Pattern in Groovy

In Groovy we have the excellent Geb by Luke Daily.

Continue reading

Configure Grunt-protractor-runner to run with a global install of protractor

Purpose

The reason to install protractor globally is that if you use the inline protractor provided with grunt-protractor-runner you have a 10 second penalty of waiting for the server to spawn a java process and then attach itself to it.

With the server already started and waiting for calls it is a lot faster turnaround for your tests to run.

Install protractor

Install protractor globally

If you have installed protractor globally to do your end to end testing via:

You may have to do this as sudo if you

npm -g install protractor

Download the chromedriver by updating webdriver-manager

webdriver-manager update

Continue reading

Unit testing angularjs with $http

Angularjs unit testing with $http.

How it all hangs together

When calling external servers to get or push data you can use the $http from angular.  $http has a set of methods like Get, Post and Put like you would expect.

$http callback methods.

It treats the call much like a ajax call where it has a .success method and a .error method which it returns to depending on if the call success or failure.

Scoping of parameters and .success() and .errror()

You can interact with the $scope or $rootScope to set or change data.  The scoping of the .success() and .error() means you cannot use a method level parameter and expect the value to be assigned before the the method ends.  It can go out of scope before it is guaranteed to be set.

Continue reading

Angularjs multiple services and Jasminejs unit testing a beginners guide

Angularjs using multiple services and Unit testing services with jasminejs

(update: 29/01/12) I have moved away from angular.module(‘ServiceName’, value( 
and instead use myServices.factory(‘ServiceName’, function(){ as I found  it did not do as I expected to.

Services are a bit harder to unit test and get configured than controllers.
Most examples have a single service or 2 services in a single file.
This is harder to maintain with source control as multiple people could be making changes on the same file.  Here is how to set up and use services in different files.

I have also included some example code on how to Unit test your angularjs service with jasperjs.

Continue reading