117
1 Automated Testing With Jasmine, PhantomJS & Jenkins Aisha Kaliel | Ronn Abueg Drupalcon 2013 Portland 1

Automated Testing With Jasmine, PhantomJS and Jenkins

Embed Size (px)

DESCRIPTION

Work at Play's DrupalCon Portland 2013 presentation on automated testing.

Citation preview

Page 1: Automated Testing With Jasmine, PhantomJS and Jenkins

1

Automated Testing With Jasmine, PhantomJS &

JenkinsAisha Kaliel | Ronn Abueg

Drupalcon 2013 Portland

1

Page 2: Automated Testing With Jasmine, PhantomJS and Jenkins

2May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

2

Page 3: Automated Testing With Jasmine, PhantomJS and Jenkins

3May 2013

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Listing the types of tests

o Looking at some test tools

o Writing and running tests

Agenda

3

Page 4: Automated Testing With Jasmine, PhantomJS and Jenkins

4May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o What is a headless browser

o Scripting with a headless browser

o Testing with a headless browser

4

Page 5: Automated Testing With Jasmine, PhantomJS and Jenkins

5May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Deploying codeo Integrating testing with

buildso Review build results

5

Page 6: Automated Testing With Jasmine, PhantomJS and Jenkins

6May 2013

Who are we?

Aisha Kalieldrupal: akaliel

Ronn Abueg drupal: ronnbottwitter: @ronnbot

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration

twitter: @workatplayfacebook: www.facebook.com/workatplaywebsite: www.workatplay.com

6

Page 7: Automated Testing With Jasmine, PhantomJS and Jenkins

7May 2013

We work with Drupal...

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 7

Page 8: Automated Testing With Jasmine, PhantomJS and Jenkins

8May 2013

And other CMS/frameworks

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 8

Page 9: Automated Testing With Jasmine, PhantomJS and Jenkins

9May 2013

And other CMS/frameworks

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 9

Page 10: Automated Testing With Jasmine, PhantomJS and Jenkins

10May 2013

Repetitive Testing: Why not automate?

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration

10

Page 11: Automated Testing With Jasmine, PhantomJS and Jenkins

11May 2013

Why test in general

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration

11

Page 12: Automated Testing With Jasmine, PhantomJS and Jenkins

12May 2013

Automated testing...

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration

• Saves time and money

• Improves accuracy

• Increases test coverage

• Does what manual testing cannot

• Helps developers and testers

• Improves team moral

• and continuous integration is the cornerstone of Agile development

12

Page 13: Automated Testing With Jasmine, PhantomJS and Jenkins

13May 2013

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Listing the types of tests

o Looking at some test tools

o Writing and running tests

Agenda

13

Page 14: Automated Testing With Jasmine, PhantomJS and Jenkins

14May 2013

Types of tests

GUI

Unit

Service / Integration

Test Pyramid•concepted by Mike Cohn•higher level tests at the top•larger number of test below•high level tests can encompass many low level tests, e.g.ofor form test to pass, functional units must work

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 14

Page 15: Automated Testing With Jasmine, PhantomJS and Jenkins

15May 2013

Tackling the testing pyramid

GUI

Unit

Service / Integration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 15

automating browser

JS testing

Page 16: Automated Testing With Jasmine, PhantomJS and Jenkins

16May 2013

Testing tools

• Selenium• Watir• Windmill• Mocha• QUnit• Jasmine• and etc.

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 16

automating browser

JS testing

Page 17: Automated Testing With Jasmine, PhantomJS and Jenkins

17May 2013

Testing tools

• Selenium• Watir• Windmill• Mocha• QUnit• Jasmine

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 17

Page 18: Automated Testing With Jasmine, PhantomJS and Jenkins

18May 2013

Comparison

Selenium

•Automates browsers

•Simulates user actions

•There's an IDE, a Firefox extension, that allows to record, edit, and debug tests

Jasmine

•Open-source testing framework for JavaScript

•Does not depend on DOM or any other JavaScript frameworks

•Unit tests your JS code

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 18

Page 19: Automated Testing With Jasmine, PhantomJS and Jenkins

19May 2013

Why Jasmine?

• Runs anywhere Javascript can

• Does not intrude on the application

• Plays well with IDEs

• Encourages good testing principles

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 19

Page 20: Automated Testing With Jasmine, PhantomJS and Jenkins

20May 2013

What is Jasmine?

• Behavior-driven development framework

• Does not require require a DOM, or depend on any other JavaScript frameworks

• Clean, obvious syntax

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 20

Page 21: Automated Testing With Jasmine, PhantomJS and Jenkins

21May 2013

What is Jasmine?

• Behavior-driven development framework

• Does not require require a DOM, or depend on any other JavaScript frameworks

• Clean, obvious syntax

• Specialized version of test-driven development

• Focuses on the "desired behavior" of software

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 21

Page 22: Automated Testing With Jasmine, PhantomJS and Jenkins

22May 2013

What is Jasmine?

• Behavior-driven development framework

• Does not require require the DOM, or depend on any other JavaScript frameworks

• Clean, obvious syntax

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 22

Page 23: Automated Testing With Jasmine, PhantomJS and Jenkins

23May 2013

What is Jasmine?

• Behavior-driven development framework

• Does not require require a DOM, or depend on any other JavaScript frameworks

• Clean, obvious syntax

Still has access to the DOM!

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 23

Page 24: Automated Testing With Jasmine, PhantomJS and Jenkins

24May 2013

What is Jasmine?

• Behavior-driven development framework

• Does not require require a DOM, or depend on any other JavaScript frameworks

• Clean, obvious syntax

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 24

Page 25: Automated Testing With Jasmine, PhantomJS and Jenkins

25May 2013

Tackling the testing pyramid with Jasmine

GUI

Unit

Service / Integration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 25

Page 26: Automated Testing With Jasmine, PhantomJS and Jenkins

26May 2013

Tackling the testing pyramid with Jasmine

GUI

Unit

Service / Integration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 26

Page 27: Automated Testing With Jasmine, PhantomJS and Jenkins

27May 2013

Tackling the testing pyramid with Jasmine

GUI

Unit

Service / Integration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 27

Page 28: Automated Testing With Jasmine, PhantomJS and Jenkins

28May 2013

Jasmine Features

• Test suites/specs• Expectations• Matchers• Setup and teardown• Spies• Asynchronous Support

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 28

Page 29: Automated Testing With Jasmine, PhantomJS and Jenkins

29May 2013

Feature to test: basic calculator

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 29

Page 30: Automated Testing With Jasmine, PhantomJS and Jenkins

30May 2013

Basic calculator

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 30

Page 31: Automated Testing With Jasmine, PhantomJS and Jenkins

31May 2013

Basic calculator

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 31

Page 32: Automated Testing With Jasmine, PhantomJS and Jenkins

32May 2013

Basic calculator

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 32

Page 33: Automated Testing With Jasmine, PhantomJS and Jenkins

33May 2013

Test the calculator: Suites

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 33

Page 34: Automated Testing With Jasmine, PhantomJS and Jenkins

34May 2013

Test the calculator: Specs

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 34

Page 35: Automated Testing With Jasmine, PhantomJS and Jenkins

35May 2013

Testing the calculator: Expectations

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 35

Page 36: Automated Testing With Jasmine, PhantomJS and Jenkins

36May 2013

Feature: Matchers

• expect(x).toBe(y);

• expect(x).toEqual(y);

• expect(x).toMatch(/pattern/);

• expect(x).toBeDefined();

• expect(x).toBeUndefined();

• expect(x).toBeNull();

• expect(x).toBeTruthy();

• expect(x).toBeFalsy();

• expect(x).toContain(y);

• expect(x).toBeLessThan(y);

• expect(x).toBeGreaterThan(y);

• expect(x).toBeCloseTo(y, 0);

• expect(function(){ fn(); }).toThrow(e);

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 36

Page 37: Automated Testing With Jasmine, PhantomJS and Jenkins

37May 2013

Feature: Negative Matchers

• expect(x).not.toBe(y);

• expect(x).not.toEqual(y);

• expect(x).not.toMatch(/pattern/);

• expect(x).not.toBeDefined();

• expect(x).not.toBeUndefined();

• expect(x).not.toBeNull();

• expect(x).not.toBeTruthy();

• expect(x).not.toBeFalsy();

• expect(x).not.toContain(y);

• expect(x).not.toBeLessThan(y);

• expect(x).not.toBeGreaterThan(y);

• expect(x).not.toBeCloseTo(y, 0);

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 37

Page 38: Automated Testing With Jasmine, PhantomJS and Jenkins

38May 2013

Testing the calculator: Matchers

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 38

Page 39: Automated Testing With Jasmine, PhantomJS and Jenkins

39May 2013

Testing the calculator: More specs!

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 39

Page 40: Automated Testing With Jasmine, PhantomJS and Jenkins

40May 2013

Feature: Setup and Teardown

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 40

Page 41: Automated Testing With Jasmine, PhantomJS and Jenkins

41May 2013

Testing the calculator: Setup

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 41

Page 42: Automated Testing With Jasmine, PhantomJS and Jenkins

42May 2013

Testing the calculator: Spies

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 42

Page 43: Automated Testing With Jasmine, PhantomJS and Jenkins

43May 2013

Testing the calculator with DOM tests

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 43

Page 44: Automated Testing With Jasmine, PhantomJS and Jenkins

44May 2013

Testing the calculator: Nested describe blocks

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 44

Page 45: Automated Testing With Jasmine, PhantomJS and Jenkins

45May 2013

Testing the calculator: Setup and Teardown

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 45

Page 46: Automated Testing With Jasmine, PhantomJS and Jenkins

46May 2013

Feature: Asynchronous Support

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 46

Page 47: Automated Testing With Jasmine, PhantomJS and Jenkins

47May 2013

Feature: Asynchronous Support

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 47

Page 48: Automated Testing With Jasmine, PhantomJS and Jenkins

48May 2013

Feature: Asynchronous Support

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 48

Page 49: Automated Testing With Jasmine, PhantomJS and Jenkins

49May 2013

Testing the calculator: Reporter

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 49

Page 50: Automated Testing With Jasmine, PhantomJS and Jenkins

50May 2013

Testing the calculator: Reporter

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 50

Page 51: Automated Testing With Jasmine, PhantomJS and Jenkins

51May 2013

Testing the calculator: Filtering the Reporter

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 51

Page 52: Automated Testing With Jasmine, PhantomJS and Jenkins

52May 2013

Running the test page without a browser

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 52

Page 53: Automated Testing With Jasmine, PhantomJS and Jenkins

53May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o What is a headless browser

o Scripting with a headless browser

o Testing with a headless browser

53

Page 54: Automated Testing With Jasmine, PhantomJS and Jenkins

54Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration May 2013

What is a headless browser

• Web browser without a GUI

• Renders web pages

• Outputs to non-humans i.e. other software

• Useful for:o testingo parsingo screen capture

54

Page 55: Automated Testing With Jasmine, PhantomJS and Jenkins

55Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration May 2013

Enter the PhantomJS• Headless WebKit

• Scriptable with JavaScript/CoffeeScript

• Support for various web standards:o DOM handlingo CSS selectoro JSONo Canvaso SVG

55

Page 56: Automated Testing With Jasmine, PhantomJS and Jenkins

56May 2013

PhantomJS basic how toCreate a script: hello.js

console.log('Hello, DrupalCon Portland!');

phantom.exit();

Run script in the command line

phantomjs hello.js

Output

Hello, DrupalCon Portland!

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 56

Page 57: Automated Testing With Jasmine, PhantomJS and Jenkins

57May 2013

PhantomJS modulesWebPageA WebPage object encapsulates a web page.

SystemA set of functions to access system-level functionality.

FileSystemA set of API functions available to access files and directories.

WebServerUsing an embedded web server module called Mongoose, PhantomJS script can start a web server.

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 57

Page 58: Automated Testing With Jasmine, PhantomJS and Jenkins

58May 2013

PhantomJS basic how toPage Loading: loadpage.js

var page = require('webpage').create();

page.open('http://portland2013.drupal.org', function () {

page.render('drupalcon.png');

phantom.exit();

});

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 58

Page 59: Automated Testing With Jasmine, PhantomJS and Jenkins

59May 2013

PhantomJS basic how toPage Loading with arguments

var page = require('webpage').create(),

system = require('system');

page.open(system.args[1], function (status) { if (status == 'success') { console.log('Loaded the address: ' + system.args[1]); } phantom.exit(); });

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 59

Page 60: Automated Testing With Jasmine, PhantomJS and Jenkins

60May 2013

PhantomJS basic how toPage Loading with arguments

var page = require('webpage').create(),

system = require('system');

page.open(system.args[1], function (status) { if (status == 'success') { console.log('Loaded the address: ' + system.args[1]); } phantom.exit(); });

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 60

Page 61: Automated Testing With Jasmine, PhantomJS and Jenkins

61May 2013

PhantomJS basic how toPage Loading with arguments

var page = require('webpage').create(),

system = require('system');

page.open(system.args[1], function (status) { if (status == 'success') { console.log('Loaded the address: ' + system.args[1]); } phantom.exit(); });

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 61

Page 62: Automated Testing With Jasmine, PhantomJS and Jenkins

62May 2013

PhantomJS basic how toPage Loading with arguments

var page = require('webpage').create(),

system = require('system');

page.open(system.args[1], function (status) { if (status == 'success') { console.log('Loaded the address: ' + system.args[1]); } phantom.exit(); });

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 62

Page 63: Automated Testing With Jasmine, PhantomJS and Jenkins

63May 2013

PhantomJS basic how toRun script in the command line

phantomjs loadpage.js http://www.google.com

Output

Loaded the address: http://www.google.com

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 63

Page 64: Automated Testing With Jasmine, PhantomJS and Jenkins

64May 2013

PhantomJS basic how toCode Evaluation

var page = require('webpage').create();

page.open(url, function (status) {

var title = page.evaluate(function () {

return document.title;

}); console.log('Page title is ' + title); });

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 64

Page 65: Automated Testing With Jasmine, PhantomJS and Jenkins

65May 2013

Running Jasmine with PhantomJS

Github: phantomjs / examples / run-jasmine.jsLocated at: https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 65

Page 66: Automated Testing With Jasmine, PhantomJS and Jenkins

66May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 66

Page 67: Automated Testing With Jasmine, PhantomJS and Jenkins

67May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 67

Page 68: Automated Testing With Jasmine, PhantomJS and Jenkins

68May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 68

Page 69: Automated Testing With Jasmine, PhantomJS and Jenkins

69May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 69

Page 70: Automated Testing With Jasmine, PhantomJS and Jenkins

70May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 70

Page 71: Automated Testing With Jasmine, PhantomJS and Jenkins

71May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 71

Page 72: Automated Testing With Jasmine, PhantomJS and Jenkins

72May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 72

Page 73: Automated Testing With Jasmine, PhantomJS and Jenkins

73May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 73

Page 74: Automated Testing With Jasmine, PhantomJS and Jenkins

74May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 74

Page 75: Automated Testing With Jasmine, PhantomJS and Jenkins

75May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 75

Page 76: Automated Testing With Jasmine, PhantomJS and Jenkins

76May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 76

Page 77: Automated Testing With Jasmine, PhantomJS and Jenkins

77May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 77

Page 78: Automated Testing With Jasmine, PhantomJS and Jenkins

78May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 78

Page 79: Automated Testing With Jasmine, PhantomJS and Jenkins

79May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 79

Page 80: Automated Testing With Jasmine, PhantomJS and Jenkins

80May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 80

Page 81: Automated Testing With Jasmine, PhantomJS and Jenkins

81May 2013

Running Jasmine with PhantomJSFrom https://github.com/ariya/phantomjs/blob/master/examples/run-jasmine.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration

...

...

...

81

Page 82: Automated Testing With Jasmine, PhantomJS and Jenkins

82May 2013

PhantomJS featuresHeadless web testingLightning-fast testing without the browser with various test frameworks.

Page automationAccess and manipulate web pages with the standard DOM API, or with usual JavaScript libraries.

Screen captureProgrammatically capture web contents including CSS, SVG and Canvas.

Network monitoringAutomate performance analysis, track page loading and export as standard HAR format.

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 82

Page 83: Automated Testing With Jasmine, PhantomJS and Jenkins

83May 2013

PhantomJS custom modules (v1.7)RequireUsers can reference their own modules from the file system using require function.

General usage

var server = require('webserver').create();

var Awesome = require('MyAwesomeModule');

Awesome.do();

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 83

Page 84: Automated Testing With Jasmine, PhantomJS and Jenkins

84

CI

May 2013

Lets integrate it with Jenkins

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 84

Page 85: Automated Testing With Jasmine, PhantomJS and Jenkins

85May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Deploying codeo Integrating testing with

buildso Review build results

85

Page 86: Automated Testing With Jasmine, PhantomJS and Jenkins

86May 2013

Meet Jenkins

• Leading open-source Continuous Integration server

• Built with Java

• Plug-in support

• RSS/E-mail/IM support

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 86

Page 87: Automated Testing With Jasmine, PhantomJS and Jenkins

87May 2013

Jenkins in action - dashboard

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 87

Page 88: Automated Testing With Jasmine, PhantomJS and Jenkins

88May 2013

Jenkins in action - project

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 88

Page 89: Automated Testing With Jasmine, PhantomJS and Jenkins

89May 2013

Jenkins in action - build

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 89

Page 90: Automated Testing With Jasmine, PhantomJS and Jenkins

90May 2013

Jenkins in action - build detail

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 90

Page 91: Automated Testing With Jasmine, PhantomJS and Jenkins

91May 2013

Deploying code - console output of build

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 91

Page 92: Automated Testing With Jasmine, PhantomJS and Jenkins

92May 2013

PhantomJs & Jasmine with XML

Github: detro / phantomjs-jasminexml-exampleLocated at: https://github.com/detro/phantomjs-jasminexml-example

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 92

Page 93: Automated Testing With Jasmine, PhantomJS and Jenkins

93May 2013

Jasmine Reporter Plugin

Github: ../ test / lib / jasmine-reportersLocated at: https://github.com/detro/phantomjs-jasminexml-example/tree/master/test/lib/jasmine-reporters

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 93

Page 94: Automated Testing With Jasmine, PhantomJS and Jenkins

94May 2013

Jasmine Reporter Plugin

Github: ../ test / lib / jasmine-reportersLocated at: https://github.com/detro/phantomjs-jasminexml-example/tree/master/test/lib/jasmine-reporters

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 94

Page 95: Automated Testing With Jasmine, PhantomJS and Jenkins

95May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 95

Page 96: Automated Testing With Jasmine, PhantomJS and Jenkins

96May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 96

Page 97: Automated Testing With Jasmine, PhantomJS and Jenkins

97May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 97

Page 98: Automated Testing With Jasmine, PhantomJS and Jenkins

98May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 98

Page 99: Automated Testing With Jasmine, PhantomJS and Jenkins

99May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 99

Page 100: Automated Testing With Jasmine, PhantomJS and Jenkins

100May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 100

Page 101: Automated Testing With Jasmine, PhantomJS and Jenkins

101May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 101

Page 102: Automated Testing With Jasmine, PhantomJS and Jenkins

102May 2013

PhantomJS XML Runner

Github: ../ test / phantomjs_jasminexml_runner.jshttps://github.com/detro/phantomjs-jasminexml-example/blob/master/test/phantomjs_jasminexml_runner.js

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 102

Page 103: Automated Testing With Jasmine, PhantomJS and Jenkins

103May 2013

Running PhantomJS in Jenkins: configuration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 103

Page 104: Automated Testing With Jasmine, PhantomJS and Jenkins

104May 2013

Running PhantomJS in Jenkins: Console Output

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 104

Page 105: Automated Testing With Jasmine, PhantomJS and Jenkins

105May 2013

Publishing test results in Jenkins: configuration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 105

Page 106: Automated Testing With Jasmine, PhantomJS and Jenkins

106May 2013

Publishing test results in Jenkins: configuration

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 106

Page 107: Automated Testing With Jasmine, PhantomJS and Jenkins

107May 2013

Publishing test results in Jenkins: Console Output

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 107

Page 108: Automated Testing With Jasmine, PhantomJS and Jenkins

108May 2013

Review build and test results

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 108

Page 109: Automated Testing With Jasmine, PhantomJS and Jenkins

109May 2013

Review build and test results

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 109

Page 110: Automated Testing With Jasmine, PhantomJS and Jenkins

110May 2013

Review test results

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 110

Page 111: Automated Testing With Jasmine, PhantomJS and Jenkins

111May 2013

Review test results

Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 111

Page 112: Automated Testing With Jasmine, PhantomJS and Jenkins

112May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

112

Page 113: Automated Testing With Jasmine, PhantomJS and Jenkins

113May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Wrote and ran tests in Jasmine

o We are able to do various types of testsautomatically

o This is more accurate than manual testing

113

Page 114: Automated Testing With Jasmine, PhantomJS and Jenkins

114May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Executed Jasmine tests via PhantomJS

o The tests can be ran by non-humans

o This saves us resources

114

Page 115: Automated Testing With Jasmine, PhantomJS and Jenkins

115May 2013

Agenda

1.Who we are2.Testing JS code and front-

end• Testing without the

browser• Continuous Integration

o Added tests execution during builds on Jenkins

o Reviewed test results in Jenkins after builds

o Allows us to be more agile

115

Page 116: Automated Testing With Jasmine, PhantomJS and Jenkins

116

From Mint Digital's blog, original cartoon by xkcd

Page 117: Automated Testing With Jasmine, PhantomJS and Jenkins

117May 2013

Thank you!

Evaluate this session at:

portland2013.drupal.org/scheduleEnjoy the rest of

Drupalcon 2013 Portland

117