Skip to content

Instantly share code, notes, and snippets.

View EdwinGuzman's full-sized avatar
🐺
yep

Edwin Guzman EdwinGuzman

🐺
yep
  • The New York Public Library
View GitHub Profile
@EdwinGuzman
EdwinGuzman / protractor_chrome_conf.js
Last active August 29, 2015 14:09
Protractor configuration
// protractor_chrome_conf.js
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
suites: {
homepage: ['test/e2e/homepage/homepage.spec.js'],
location: ['test/e2e/location/circulating.spec.js',
'test/e2e/location/research.spec.js'],
// location.spec.js
describe('Locations: Schwarzman Building', function () {
beforeEach(function () {
browser.get('/schwarzman');
// Wait for the AngularJS app to load before testing DOM elements.
browser.waitForAngular();
});
it('should display the branch\'s name on the page', function () {
var name = element(by.css('.location-name'));
// Assertion
// location.po.js
var LocationPage = function () {
this.name = element(by.css('.location-name'));
this.street_address = element(by.binding('location.street_address'));
// ...
};
module.exports = new LocationPage();
// updated location.spec.js
describe('Locations', function () {
var locationPage = require('./location.po.js');
it('should display the research branch\'s name on the page', function () {
browser.get('/schwarzman');
browser.waitForAngular();
expect(locationPage.name.getText()).toEqual('Stephen A. Schwarzman Building');
expect(locationPage.street_address.getText()).toEqual('Fifth Avenue at 42nd Street');
describe('Google Analytics: pageview tracking', function () {
var landingPage = require('../homepage/homepage.po.js');
function mockGA() {
return "window.ga_msg = [];" +
"ga = function () {" +
" var msg = [];" +
" for (var i = 0; i < arguments.length; i++) {" +
" msg.push(arguments[i]); " +
" }" +
var landingPage = require('../homepage/homepage.po.js');
it('should track branch searching near the user', function () {
landingPage.geolocation.click();
browser.executeScript('return window.ga_msg;').then(function (ga) {
expect(ga[0][2]).toEqual('Locations');
expect(ga[0][3]).toEqual('Filter by');
expect(ga[0][4]).toEqual('Near me');
});
});
var httpBackendMock = function (response) {
var API_URL = 'url_for_the_api';
angular
.module('httpBackendMock', ['ngMockE2E'])
.run(function ($httpBackend) {
$httpBackend
.whenJSONP(API_URL + '/locations/grand-central?callback=JSON_CALLBACK')
.respond(response);
describe('Research branch page', function () {
'use strict';
var locationPage = require('./location.po.js'),
// Mocked API response for a research library.
APIresponse = require('../APImocks/research.js'),
httpBackendMock = function (response) {
// Defined above
};
# Run only once
$ ./node_modules/protractor/bin/webdriver-manager update
# Run everytime to start the Selenium Server
$ ./node_modules/protractor/bin/webdriver-manager start
# To run all tests
$ protractor protractor_chrome_conf.js
# To run a specific section
describe('Geolocation', function () {
var landingPage = require('./homepage.po.js');
function mockGeo(lat, lon) {
return 'window.navigator.geolocation.getCurrentPosition = ' +
' function (success, error) {' +
' var position = {' +
' "coords" : {' +
' "latitude": "' + lat + '",' +
' "longitude": "' + lon + '"' +