SlideShare ist ein Scribd-Unternehmen logo
1 von 117
Downloaden Sie, um offline zu lesen
1
Automated Testing With
Jasmine, PhantomJS &
Jenkins
Aisha Kaliel | Ronn Abueg
Drupalcon 2013 Portland
1
2
May 2013
Agenda
1.Who we are
2.Testing JS code and front-
end
• Testing without the browser
• Continuous Integration
2
3
May 2013
1.Who we are
2.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
4
May 2013
Agenda
1.Who we are
2.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
5
May 2013
Agenda
1.Who we are
2.Testing JS code and front-
end
• Testing without the browser
• Continuous Integration
o Deploying code
o Integrating testing with
builds
o Review build results
5
6
May 2013
Who are we?
Aisha Kaliel
drupal: akaliel
Ronn Abueg
drupal: ronnbot
twitter: @ronnbot
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration
twitter: @workatplay
facebook: www.facebook.com/workatplay
website: www.workatplay.com
6
7
May 2013
We work with Drupal...
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 7
8
May 2013
And other CMS/frameworks
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 8
9
May 2013
And other CMS/frameworks
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 9
10
May 2013
Repetitive Testing: Why not automate?
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 10
11
May 2013
Why test in general
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 11
12
May 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
13
May 2013
1.Who we are
2.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
14
May 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
15
May 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
16
May 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
17
May 2013
Testing tools
• Selenium
• Watir
• Windmill
• Mocha
• QUnit
• Jasmine
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 17
18
May 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
19
May 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
20
May 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
21
May 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
22
May 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
23
May 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
24
May 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
25
May 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
26
May 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
27
May 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
28
May 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
29
May 2013
Feature to test: basic calculator
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 29
30
May 2013
Basic calculator
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 30
31
May 2013
Basic calculator
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 31
32
May 2013
Basic calculator
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 32
33
May 2013
Test the calculator: Suites
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 33
34
May 2013
Test the calculator: Specs
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 34
35
May 2013
Testing the calculator: Expectations
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 35
36
May 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
37
May 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
38
May 2013
Testing the calculator: Matchers
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 38
39
May 2013
Testing the calculator: More specs!
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 39
40
May 2013
Feature: Setup and Teardown
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 40
41
May 2013
Testing the calculator: Setup
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 41
42
May 2013
Testing the calculator: Spies
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 42
43
May 2013
Testing the calculator with DOM tests
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 43
44
May 2013
Testing the calculator: Nested describe blocks
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 44
45
May 2013
Testing the calculator: Setup and Teardown
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 45
46
May 2013
Feature: Asynchronous Support
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 46
47
May 2013
Feature: Asynchronous Support
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 47
48
May 2013
Feature: Asynchronous Support
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 48
49
May 2013
Testing the calculator: Reporter
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 49
50
May 2013
Testing the calculator: Reporter
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 50
51
May 2013
Testing the calculator: Filtering the Reporter
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 51
52
May 2013
Running the test page without a browser
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 52
53
May 2013
Agenda
1.Who we are
2.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
54
Who 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 testing
o parsing
o screen capture
54
55
Who 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 handling
o CSS selector
o JSON
o Canvas
o SVG
55
56
May 2013
PhantomJS basic how to
Create 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
57
May 2013
PhantomJS modules
WebPage
A WebPage object encapsulates a web page.
System
A set of functions to access system-level functionality.
FileSystem
A set of API functions available to access files and directories.
WebServer
Using 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
58
May 2013
PhantomJS basic how to
Page 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
59
May 2013
PhantomJS basic how to
Page 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
60
May 2013
PhantomJS basic how to
Page 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
61
May 2013
PhantomJS basic how to
Page 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
62
May 2013
PhantomJS basic how to
Page 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
63
May 2013
PhantomJS basic how to
Run 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
64
May 2013
PhantomJS basic how to
Code 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
65
May 2013
Running Jasmine with PhantomJS
Github: phantomjs / examples / run-jasmine.js
Located 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
66
May 2013
Running Jasmine with PhantomJS
From 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
67
May 2013
Running Jasmine with PhantomJS
From 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
68
May 2013
Running Jasmine with PhantomJS
From 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
69
May 2013
Running Jasmine with PhantomJS
From 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
70
May 2013
Running Jasmine with PhantomJS
From 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
71
May 2013
Running Jasmine with PhantomJS
From 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
72
May 2013
Running Jasmine with PhantomJS
From 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
73
May 2013
Running Jasmine with PhantomJS
From 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
74
May 2013
Running Jasmine with PhantomJS
From 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
75
May 2013
Running Jasmine with PhantomJS
From 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
76
May 2013
Running Jasmine with PhantomJS
From 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
77
May 2013
Running Jasmine with PhantomJS
From 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
78
May 2013
Running Jasmine with PhantomJS
From 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
79
May 2013
Running Jasmine with PhantomJS
From 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
80
May 2013
Running Jasmine with PhantomJS
From 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
81
May 2013
Running Jasmine with PhantomJS
From 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
82
May 2013
PhantomJS features
Headless web testing
Lightning-fast testing without the browser with various test frameworks.
Page automation
Access and manipulate web pages with the standard DOM API, or with usual
JavaScript libraries.
Screen capture
Programmatically capture web contents including CSS, SVG and Canvas.
Network monitoring
Automate 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
83
May 2013
PhantomJS custom modules (v1.7)
Require
Users 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
84
CI
May 2013
Lets integrate it with Jenkins
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 84
85
May 2013
Agenda
1.Who we are
2.Testing JS code and front-
end
• Testing without the browser
• Continuous Integration
o Deploying code
o Integrating testing with
builds
o Review build results
85
86
May 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
87
May 2013
Jenkins in action - dashboard
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 87
88
May 2013
Jenkins in action - project
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 88
89
May 2013
Jenkins in action - build
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 89
90
May 2013
Jenkins in action - build detail
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 90
91
May 2013
Deploying code - console output of build
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 91
92
May 2013
PhantomJs & Jasmine with XML
Github: detro / phantomjs-jasminexml-example
Located at: https://github.com/detro/phantomjs-jasminexml-example
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 92
93
May 2013
Jasmine Reporter Plugin
Github: ../ test / lib / jasmine-reporters
Located 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
94
May 2013
Jasmine Reporter Plugin
Github: ../ test / lib / jasmine-reporters
Located 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
95
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
96
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
97
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
98
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
99
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
100
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
101
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
102
May 2013
PhantomJS XML Runner
Github: ../ test / phantomjs_jasminexml_runner.js
https://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
103
May 2013
Running PhantomJS in Jenkins: configuration
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 103
104
May 2013
Running PhantomJS in Jenkins: Console Output
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 104
105
May 2013
Publishing test results in Jenkins: configuration
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 105
106
May 2013
Publishing test results in Jenkins: configuration
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 106
107
May 2013
Publishing test results in Jenkins: Console Output
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 107
108
May 2013
Review build and test results
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 108
109
May 2013
Review build and test results
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 109
110
May 2013
Review test results
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 110
111
May 2013
Review test results
Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 111
112
May 2013
Agenda
1.Who we are
2.Testing JS code and front-
end
• Testing without the browser
• Continuous Integration
112
113
May 2013
Agenda
1.Who we are
2.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
114
May 2013
Agenda
1.Who we are
2.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
115
May 2013
Agenda
1.Who we are
2.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
116
From Mint Digital's blog, original cartoon by xkcd
117
May 2013
Thank you!
Evaluate this session at:
portland2013.drupal.org/schedule
Enjoy the rest of
Drupalcon 2013 Portland
117

Weitere ähnliche Inhalte

Was ist angesagt?

Perils of Page-Object Pattern
Perils of Page-Object PatternPerils of Page-Object Pattern
Perils of Page-Object PatternAnand Bagmar
 
Automated Testing – Web, Mobile, Desktop - Challenges and Successes
Automated Testing – Web, Mobile, Desktop - Challenges and SuccessesAutomated Testing – Web, Mobile, Desktop - Challenges and Successes
Automated Testing – Web, Mobile, Desktop - Challenges and SuccessesTed Drake
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumberNibu Baby
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1Qualitest
 
QA Automation testing online training
QA Automation testing online trainingQA Automation testing online training
QA Automation testing online trainingDivya Shree
 
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...Sargis Sargsyan
 
Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5rtpaem
 
Getting Started With Cypress
Getting Started With CypressGetting Started With Cypress
Getting Started With CypressKnoldus Inc.
 
Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environmentYu-Lin Huang
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPhil Leggetter
 
Agile test-management-test-rail-lastest
Agile test-management-test-rail-lastestAgile test-management-test-rail-lastest
Agile test-management-test-rail-lastestOnur Baskirt
 
Introduction cypress
Introduction cypressIntroduction cypress
Introduction cypressOim Trust
 
Automation Testing Approach for Responsive Web Design
Automation Testing Approach for Responsive Web DesignAutomation Testing Approach for Responsive Web Design
Automation Testing Approach for Responsive Web DesignAgile Testing Alliance
 
Lets cook cucumber !!
Lets cook cucumber !!Lets cook cucumber !!
Lets cook cucumber !!vodQA
 
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarApplitools
 
Nakal think test_2015
Nakal think test_2015Nakal think test_2015
Nakal think test_2015Rajdeep Varma
 

Was ist angesagt? (20)

Perils of Page-Object Pattern
Perils of Page-Object PatternPerils of Page-Object Pattern
Perils of Page-Object Pattern
 
Cucumber ppt
Cucumber pptCucumber ppt
Cucumber ppt
 
Automated Testing – Web, Mobile, Desktop - Challenges and Successes
Automated Testing – Web, Mobile, Desktop - Challenges and SuccessesAutomated Testing – Web, Mobile, Desktop - Challenges and Successes
Automated Testing – Web, Mobile, Desktop - Challenges and Successes
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1
 
QA Automation testing online training
QA Automation testing online trainingQA Automation testing online training
QA Automation testing online training
 
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5
 
React a11y-csun
React a11y-csunReact a11y-csun
React a11y-csun
 
Getting Started With Cypress
Getting Started With CypressGetting Started With Cypress
Getting Started With Cypress
 
Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 apps
 
Eclipse UI automation
Eclipse UI automationEclipse UI automation
Eclipse UI automation
 
Agile test-management-test-rail-lastest
Agile test-management-test-rail-lastestAgile test-management-test-rail-lastest
Agile test-management-test-rail-lastest
 
Introduction cypress
Introduction cypressIntroduction cypress
Introduction cypress
 
Automation Testing Approach for Responsive Web Design
Automation Testing Approach for Responsive Web DesignAutomation Testing Approach for Responsive Web Design
Automation Testing Approach for Responsive Web Design
 
Lets cook cucumber !!
Lets cook cucumber !!Lets cook cucumber !!
Lets cook cucumber !!
 
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
 
Nakal think test_2015
Nakal think test_2015Nakal think test_2015
Nakal think test_2015
 

Andere mochten auch

Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerLuca Milanesio
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarPascal Larocque
 
Sonar qube to impove code quality
Sonar qube   to impove code qualitySonar qube   to impove code quality
Sonar qube to impove code qualityMani Sarkar
 
Design First API's with RAML and SoapUI
Design First API's with RAML and SoapUIDesign First API's with RAML and SoapUI
Design First API's with RAML and SoapUIDaniel Feist
 
Gerrit Code Review with GitHub plugin
Gerrit Code Review with GitHub pluginGerrit Code Review with GitHub plugin
Gerrit Code Review with GitHub pluginLuca Milanesio
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Dave Haeffner
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVMAlan Parkinson
 
Tracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQubeTracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQubePatroklos Papapetrou (Pat)
 
Introduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for JavaIntroduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for JavaSeb Rose
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with CucumberBrandon Keepers
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productiveKarsten Dambekalns
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmineTimothy Oxley
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 
Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twistchristophd
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 

Andere mochten auch (20)

Next level of Appium
Next level of AppiumNext level of Appium
Next level of Appium
 
Automate you Appium test like a pro!
Automate you Appium test like a pro!Automate you Appium test like a pro!
Automate you Appium test like a pro!
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and Docker
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and Sonar
 
Sonar qube to impove code quality
Sonar qube   to impove code qualitySonar qube   to impove code quality
Sonar qube to impove code quality
 
Design First API's with RAML and SoapUI
Design First API's with RAML and SoapUIDesign First API's with RAML and SoapUI
Design First API's with RAML and SoapUI
 
Gerrit Code Review with GitHub plugin
Gerrit Code Review with GitHub pluginGerrit Code Review with GitHub plugin
Gerrit Code Review with GitHub plugin
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
 
Tracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQubeTracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQube
 
Introduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for JavaIntroduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for Java
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productive
 
Gerrit Code Review
Gerrit Code ReviewGerrit Code Review
Gerrit Code Review
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twist
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 

Ähnlich wie Automated Testing With Jasmine, PhantomJS and Jenkins

A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentShawn Jones
 
How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...Max Barrass
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven DevelopmentDhaval Shah
 
Agile evening 22_jul_13
Agile evening 22_jul_13Agile evening 22_jul_13
Agile evening 22_jul_13Atsushi Sano
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and WhenPaul Gower
 
Testing without defined requirements
Testing without defined requirementsTesting without defined requirements
Testing without defined requirementsrrice2000
 
Khayabaane testing
Khayabaane testingKhayabaane testing
Khayabaane testingMajd Uddin
 
Journey to Google
Journey to GoogleJourney to Google
Journey to GoogleGDSC PJATK
 
How to Run Research in Agile Sprints by Democratizing It Across Teams
How to Run Research in Agile Sprints by Democratizing It Across TeamsHow to Run Research in Agile Sprints by Democratizing It Across Teams
How to Run Research in Agile Sprints by Democratizing It Across TeamsUserZoom
 
How companies test their software before released to the digital market.pptx
How companies test their software before released to the digital market.pptxHow companies test their software before released to the digital market.pptx
How companies test their software before released to the digital market.pptxBakr Salim
 
Holistic testing in DevOps
Holistic testing in DevOpsHolistic testing in DevOps
Holistic testing in DevOpsJanet Gregory
 
Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in continuous integration and continuous delivery as an ex...Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in continuous integration and continuous delivery as an ex...Srinivas Kadiyala
 
Testing activities in CI/CD as exploratory tester
Testing activities in CI/CD as exploratory testerTesting activities in CI/CD as exploratory tester
Testing activities in CI/CD as exploratory testerSrinivas Kadiyala
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Abhijeet Vaikar
 
Selenium Deep Dive
Selenium Deep DiveSelenium Deep Dive
Selenium Deep DiveAnand Bagmar
 
Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar
Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar
Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar Applitools
 
Session on Testing Activities in Continuous Integration and Delivery as an Ex...
Session on Testing Activities in Continuous Integration and Delivery as an Ex...Session on Testing Activities in Continuous Integration and Delivery as an Ex...
Session on Testing Activities in Continuous Integration and Delivery as an Ex...Agile Testing Alliance
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and WhenPaul Gower
 

Ähnlich wie Automated Testing With Jasmine, PhantomJS and Jenkins (20)

A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
 
Agile evening 22_jul_13
Agile evening 22_jul_13Agile evening 22_jul_13
Agile evening 22_jul_13
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
Testing without defined requirements
Testing without defined requirementsTesting without defined requirements
Testing without defined requirements
 
Khayabaane testing
Khayabaane testingKhayabaane testing
Khayabaane testing
 
Journey to Google
Journey to GoogleJourney to Google
Journey to Google
 
How to Run Research in Agile Sprints by Democratizing It Across Teams
How to Run Research in Agile Sprints by Democratizing It Across TeamsHow to Run Research in Agile Sprints by Democratizing It Across Teams
How to Run Research in Agile Sprints by Democratizing It Across Teams
 
How companies test their software before released to the digital market.pptx
How companies test their software before released to the digital market.pptxHow companies test their software before released to the digital market.pptx
How companies test their software before released to the digital market.pptx
 
Holistic testing in DevOps
Holistic testing in DevOpsHolistic testing in DevOps
Holistic testing in DevOps
 
Paper Trends
Paper TrendsPaper Trends
Paper Trends
 
Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in continuous integration and continuous delivery as an ex...Testing activities in continuous integration and continuous delivery as an ex...
Testing activities in continuous integration and continuous delivery as an ex...
 
Testing activities in CI/CD as exploratory tester
Testing activities in CI/CD as exploratory testerTesting activities in CI/CD as exploratory tester
Testing activities in CI/CD as exploratory tester
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
Selenium Deep Dive
Selenium Deep DiveSelenium Deep Dive
Selenium Deep Dive
 
Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar
Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar
Collaborating with Developers: How-to Guide for Test Engineers - By Gil Tayar
 
Session on Testing Activities in Continuous Integration and Delivery as an Ex...
Session on Testing Activities in Continuous Integration and Delivery as an Ex...Session on Testing Activities in Continuous Integration and Delivery as an Ex...
Session on Testing Activities in Continuous Integration and Delivery as an Ex...
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
Agile Engineering Environment – 2017
Agile Engineering Environment – 2017Agile Engineering Environment – 2017
Agile Engineering Environment – 2017
 

Kürzlich hochgeladen

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 

Kürzlich hochgeladen (20)

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 

Automated Testing With Jasmine, PhantomJS and Jenkins

  • 1. 1 Automated Testing With Jasmine, PhantomJS & Jenkins Aisha Kaliel | Ronn Abueg Drupalcon 2013 Portland 1
  • 2. 2 May 2013 Agenda 1.Who we are 2.Testing JS code and front- end • Testing without the browser • Continuous Integration 2
  • 3. 3 May 2013 1.Who we are 2.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
  • 4. 4 May 2013 Agenda 1.Who we are 2.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
  • 5. 5 May 2013 Agenda 1.Who we are 2.Testing JS code and front- end • Testing without the browser • Continuous Integration o Deploying code o Integrating testing with builds o Review build results 5
  • 6. 6 May 2013 Who are we? Aisha Kaliel drupal: akaliel Ronn Abueg drupal: ronnbot twitter: @ronnbot Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration twitter: @workatplay facebook: www.facebook.com/workatplay website: www.workatplay.com 6
  • 7. 7 May 2013 We work with Drupal... Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 7
  • 8. 8 May 2013 And other CMS/frameworks Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 8
  • 9. 9 May 2013 And other CMS/frameworks Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 9
  • 10. 10 May 2013 Repetitive Testing: Why not automate? Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 10
  • 11. 11 May 2013 Why test in general Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 11
  • 12. 12 May 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
  • 13. 13 May 2013 1.Who we are 2.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
  • 14. 14 May 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
  • 15. 15 May 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
  • 16. 16 May 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
  • 17. 17 May 2013 Testing tools • Selenium • Watir • Windmill • Mocha • QUnit • Jasmine Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 17
  • 18. 18 May 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
  • 19. 19 May 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
  • 20. 20 May 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
  • 21. 21 May 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
  • 22. 22 May 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
  • 23. 23 May 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
  • 24. 24 May 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
  • 25. 25 May 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
  • 26. 26 May 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
  • 27. 27 May 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
  • 28. 28 May 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
  • 29. 29 May 2013 Feature to test: basic calculator Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 29
  • 30. 30 May 2013 Basic calculator Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 30
  • 31. 31 May 2013 Basic calculator Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 31
  • 32. 32 May 2013 Basic calculator Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 32
  • 33. 33 May 2013 Test the calculator: Suites Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 33
  • 34. 34 May 2013 Test the calculator: Specs Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 34
  • 35. 35 May 2013 Testing the calculator: Expectations Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 35
  • 36. 36 May 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
  • 37. 37 May 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
  • 38. 38 May 2013 Testing the calculator: Matchers Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 38
  • 39. 39 May 2013 Testing the calculator: More specs! Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 39
  • 40. 40 May 2013 Feature: Setup and Teardown Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 40
  • 41. 41 May 2013 Testing the calculator: Setup Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 41
  • 42. 42 May 2013 Testing the calculator: Spies Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 42
  • 43. 43 May 2013 Testing the calculator with DOM tests Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 43
  • 44. 44 May 2013 Testing the calculator: Nested describe blocks Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 44
  • 45. 45 May 2013 Testing the calculator: Setup and Teardown Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 45
  • 46. 46 May 2013 Feature: Asynchronous Support Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 46
  • 47. 47 May 2013 Feature: Asynchronous Support Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 47
  • 48. 48 May 2013 Feature: Asynchronous Support Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 48
  • 49. 49 May 2013 Testing the calculator: Reporter Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 49
  • 50. 50 May 2013 Testing the calculator: Reporter Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 50
  • 51. 51 May 2013 Testing the calculator: Filtering the Reporter Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 51
  • 52. 52 May 2013 Running the test page without a browser Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 52
  • 53. 53 May 2013 Agenda 1.Who we are 2.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
  • 54. 54 Who 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 testing o parsing o screen capture 54
  • 55. 55 Who 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 handling o CSS selector o JSON o Canvas o SVG 55
  • 56. 56 May 2013 PhantomJS basic how to Create 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
  • 57. 57 May 2013 PhantomJS modules WebPage A WebPage object encapsulates a web page. System A set of functions to access system-level functionality. FileSystem A set of API functions available to access files and directories. WebServer Using 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
  • 58. 58 May 2013 PhantomJS basic how to Page 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
  • 59. 59 May 2013 PhantomJS basic how to Page 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
  • 60. 60 May 2013 PhantomJS basic how to Page 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
  • 61. 61 May 2013 PhantomJS basic how to Page 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
  • 62. 62 May 2013 PhantomJS basic how to Page 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
  • 63. 63 May 2013 PhantomJS basic how to Run 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
  • 64. 64 May 2013 PhantomJS basic how to Code 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
  • 65. 65 May 2013 Running Jasmine with PhantomJS Github: phantomjs / examples / run-jasmine.js Located 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
  • 66. 66 May 2013 Running Jasmine with PhantomJS From 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
  • 67. 67 May 2013 Running Jasmine with PhantomJS From 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
  • 68. 68 May 2013 Running Jasmine with PhantomJS From 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
  • 69. 69 May 2013 Running Jasmine with PhantomJS From 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
  • 70. 70 May 2013 Running Jasmine with PhantomJS From 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
  • 71. 71 May 2013 Running Jasmine with PhantomJS From 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
  • 72. 72 May 2013 Running Jasmine with PhantomJS From 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
  • 73. 73 May 2013 Running Jasmine with PhantomJS From 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
  • 74. 74 May 2013 Running Jasmine with PhantomJS From 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
  • 75. 75 May 2013 Running Jasmine with PhantomJS From 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
  • 76. 76 May 2013 Running Jasmine with PhantomJS From 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
  • 77. 77 May 2013 Running Jasmine with PhantomJS From 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
  • 78. 78 May 2013 Running Jasmine with PhantomJS From 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
  • 79. 79 May 2013 Running Jasmine with PhantomJS From 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
  • 80. 80 May 2013 Running Jasmine with PhantomJS From 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
  • 81. 81 May 2013 Running Jasmine with PhantomJS From 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
  • 82. 82 May 2013 PhantomJS features Headless web testing Lightning-fast testing without the browser with various test frameworks. Page automation Access and manipulate web pages with the standard DOM API, or with usual JavaScript libraries. Screen capture Programmatically capture web contents including CSS, SVG and Canvas. Network monitoring Automate 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
  • 83. 83 May 2013 PhantomJS custom modules (v1.7) Require Users 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
  • 84. 84 CI May 2013 Lets integrate it with Jenkins Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 84
  • 85. 85 May 2013 Agenda 1.Who we are 2.Testing JS code and front- end • Testing without the browser • Continuous Integration o Deploying code o Integrating testing with builds o Review build results 85
  • 86. 86 May 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
  • 87. 87 May 2013 Jenkins in action - dashboard Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 87
  • 88. 88 May 2013 Jenkins in action - project Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 88
  • 89. 89 May 2013 Jenkins in action - build Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 89
  • 90. 90 May 2013 Jenkins in action - build detail Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 90
  • 91. 91 May 2013 Deploying code - console output of build Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 91
  • 92. 92 May 2013 PhantomJs & Jasmine with XML Github: detro / phantomjs-jasminexml-example Located at: https://github.com/detro/phantomjs-jasminexml-example Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 92
  • 93. 93 May 2013 Jasmine Reporter Plugin Github: ../ test / lib / jasmine-reporters Located 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
  • 94. 94 May 2013 Jasmine Reporter Plugin Github: ../ test / lib / jasmine-reporters Located 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
  • 95. 95 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 96. 96 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 97. 97 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 98. 98 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 99. 99 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 100. 100 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 101. 101 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 102. 102 May 2013 PhantomJS XML Runner Github: ../ test / phantomjs_jasminexml_runner.js https://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
  • 103. 103 May 2013 Running PhantomJS in Jenkins: configuration Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 103
  • 104. 104 May 2013 Running PhantomJS in Jenkins: Console Output Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 104
  • 105. 105 May 2013 Publishing test results in Jenkins: configuration Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 105
  • 106. 106 May 2013 Publishing test results in Jenkins: configuration Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 106
  • 107. 107 May 2013 Publishing test results in Jenkins: Console Output Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 107
  • 108. 108 May 2013 Review build and test results Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 108
  • 109. 109 May 2013 Review build and test results Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 109
  • 110. 110 May 2013 Review test results Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 110
  • 111. 111 May 2013 Review test results Who we are | Testing JS Code & Front-End | Testing without the Browser | Continuous Integration 111
  • 112. 112 May 2013 Agenda 1.Who we are 2.Testing JS code and front- end • Testing without the browser • Continuous Integration 112
  • 113. 113 May 2013 Agenda 1.Who we are 2.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
  • 114. 114 May 2013 Agenda 1.Who we are 2.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
  • 115. 115 May 2013 Agenda 1.Who we are 2.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
  • 116. 116 From Mint Digital's blog, original cartoon by xkcd
  • 117. 117 May 2013 Thank you! Evaluate this session at: portland2013.drupal.org/schedule Enjoy the rest of Drupalcon 2013 Portland 117

Hinweis der Redaktion

  1. Who we are Testing JS code and front-end Listing the types of tests Looking at some test tools Writing and running tests Testing without the browser What is a headless browser Scripting with a headless browser Testing with a headless browser Continuous Integration Deploying code Integrating testing with builds Review build results
  2. Who we are Testing JS code and front-end Listing the types of tests Looking at some test tools Writing and running tests Testing without the browser What is a headless browser Scripting with a headless browser Testing with a headless browser Continuous Integration Deploying code Integrating testing with builds Review build results
  3. Who we are Testing JS code and front-end Listing the types of tests Looking at some test tools Writing and running tests Testing without the browser What is a headless browser Scripting with a headless browser Testing with a headless browser Continuous Integration Deploying code Integrating testing with builds Review build results
  4. Who we are Testing JS code and front-end Listing the types of tests Looking at some test tools Writing and running tests Testing without the browser What is a headless browser Scripting with a headless browser Testing with a headless browser Continuous Integration Deploying code Integrating testing with builds Review build results
  5. We're both developers from Work at Play. Work at Play is digital agency that provides clients with custom engagement solutions that decrease churn and increase long term customer value. This basically translates to either building apps and using social marketing, or both.
  6. Just some of the Drupal sites we've worked on ABCSpark.ca BarbieCollector.com, Mattel.com, MonsterHigh.com, HotWheels.com (no image), Knowledge.ca NeedForSpeed.com
  7. Some other CMS and frameworks: Yii, CodeIgniter Java Spring, Alfresco Django PhoneGap Not even including some other ones, like Kohana and TYPO3 Then there are the JS frameworks: BackboneJS KendoUI ExtJS jQuery (UI, Mobile)
  8. Now, regardless of the backend, framework the result is lots and lots of HTML and JS (and CSS).
  9. [pause for about 20 or so seconds] / "I'll let you read this comic first" You could test your pages via manual click tests, but that's ridiculous. You have to do these manual tests every time your code evolves with new features, or improvements, to ensure that your code is still working as it should. Which can become frustrating with the amount of time and effort an individual person has to put in in order to do so. So why not automate it and remove that pain? Hence, this session on AUTOMATED TESTING WITH JASMINE AND PHANTOMJS.
  10. This is our company slogan. It is painted on the wall We work smart partly by automating tests... This gives us the opportunity to play hard with new and interesting technology
  11. Saves time and money test to ensure quality but Manually repeating these tests is costly and time consuming. automated tests can be run over and over again at no additional cost and they are much faster than manual tests Improves accuracy tester will make mistakes during monotonous manual testing Automated tests perform the same steps precisely every time they are executed Increases test coverage automated testing can increase the depth and scope of tests to help improve software quality Lengthy tests that are often avoided during manual testing can be run unatten Does what manual testing cannot simulation load and stress tests Helps developers and testers developers can share test codes; tests can be ran by developers and not just testers Improves team moral with the the time saved, the team can work on more building and solving interesting problems instead of manually testing over and over again and continuous integration is the cornerstone of Agile development Agile practices rely on fast feedback, achieved by testing each incremental change Automation allows us to break free of waterfall's "coding phase / testing phase" paradigm, turning them into an integrated development cycle
  12. What we have here is a lit of types of tests. Of course, there are other types of tests, such as stress tests, but they're out of scope. As you can see, unit tests are at the bottom of the list because they're lower level tests compared to GUI tests. The test pyramid is a concept developed by Mike Cohn , described in his book Succeedin g with Agile . It's a pyramid because you have much more low level tests at the base. And as you go up, there are less and less tests of that type. Also, the higher level tests can encompass one to many lower level tests.
  13. On the front-end or client side, the way these tests are normally done are: GUI - automating the browser by scripting it or recording actions Unit test - by writing and running tests in JS
  14. Now, here are some testing tools; there are many more obviously. In this list, the ones at the top like selenium and watir does testing by automating the browser. The ones below are mainly for unit testing your JS/HTML code. Some tools, like Windmill and Mocha, can do a both.
  15. In this session, we're obviously be looking at Jasmine, but we'll also briefly look at Selenium, which sits on the other side of the spectrum.
  16. Compare with selenium. More info on selenium. Highlight what selenium does better than jasmine and vice-versa.
  17. Many other javascript testing frameworks only work from within a browser. Some don't support testing asynchronous code like event callbacks and some still have syntax that's hard for JS developers or IDEs to understand. Jasmine aims to run on any JavaScript-enabled platform, to not intrude on the application nor the IDE , and to have easy-to-read syntax. Jasmine was designed with principles in mind for what makes a good up a JS testing framework. With the goals for writing jasmine, [pause] one being that it should encourage good testing practices. [next slide]
  18. More about what Jasmine is, and what are some of those principles and goals... Well first, Jasmine is a behaviour driven development framework for testing javascript code. [next slide]
  19. - A Behaviour driven development framework is a specialized and continued version essentially of TDD - as it makes more specific choices than TDD does - it focuses on the desired behaviours of software, borrowing from agile software development - so tests are specified in terms of those "desired behaviors", using sentences starting with the word "should"
  20. It is designed to not be tied to any browser, framework, platform, or host language. You don't need any other javascript frameworks or libraries in order to start working with jasmine. It only needs them if it is testing it. It also doesn't need the DOM, which means that we can do not need to rely on it to write unit tests and can just interact with only the javascript objects that we need and want to test. But though it doesn't require it.... [next slide]
  21. ... it can still access the DOM if needed! It can work anywhere JavaScript can run, including browsers, servers, phones, etc. We still have the ability to test the DOM too, and can use any libraries or frameworks we choose to.
  22. Jasmine is designed with the principle that a good JavaScript testing framework should also have clean, idiomatic and unsurprising syntax in order for it to be easy to read and that writing jasmine should be simple to get started with.
  23. Looking back the the test pyramid, we know Jasmine can do unit tests. Not requiring the DOM means we can test our JS objects.
  24. With Jasmine's async support, we can test backend services and APIs by making AJAX calls.
  25. Having access to the DOM means being able to test the UI, e.g. check if certain Drupal blocks exist on a page, fill in a form and submit it, and so on.
  26. So, lets dive into jasmine and how to write these tests: Jasmine has the usual set of features (for a js testing framework), such as the following, which we will go over in more detail later. It has: - test suites and specs - the "expect" test method - various matchers which are included but also the ability to create your own custom matchers - setup and teardown functions - spies - asynchronous support - Plus many more... For this session, we'll look at using these to test a basic calculator that we set up in Drupal.
  27. Here you see the sample Drupal site and calculator.
  28. On closer look, the calculator provides 4 mathematical operations and two input variables, that output the results of the chosen operation to the final field.
  29. This JavaScript object implements our simple calculator.
  30. Here we show how we utilize the calculator object. We have one or more form with the class 'calc' and we simply call 'set' and 'calculate' functions of the calculator object when certain events are triggered. What we'll do initially is to unit test the calculator object (shown in the previous slide).
  31. [after setting up the HTML runner file that actually runs the Jasmine tests, which you can take a look at in the jasmine documentation or sample files] (First thing, ) We can create the test suite to hold all our tests, or "specs", for the calculator. It begins with a call to jasmine's "describe" function. You pass it two parameters, a string and a function. The first parameter, the string, is the name or title of the suite. The function is container for the block of code that implements the tests of the suite. This is where you would start to put in your specs.
  32. A spec is a function very similar to a suite, it also has two parameters with a string and a function, Though it is defined by calling the jasmine's function "it". The string is the title of the spec and what exactly it is testing. As we mentioned before, since it is a behaviour driven testing framework, it is likely a statement that starts with "should" In this case "should be able to add two numbers together". The function is where the block of code to execute that spec is placed, and we begin to interact with our calculate object.
  33. Expectations are written with the function expect. It takes a value, the actual, which we will implement matchers on to evaluate it.
  34. Matchers implement a boolean comparison between that "actual" value and the expected value we compare to. Jasmine has a set of matchers included that we can begin to use, which we can see here. toBe: compares x and y and passes if they are the same toEqual: compares x and y and passes if they are equivalent toMatch: compares x to the string or regular expression and passes if they match toBeDefined: passes if x is not undefined toBeUndefined: passes if x is undefined toBeNull: passes if x is null toBeTruthy: passes if x evaluates to true toBeFalsy: passes if x evaluates to false toContain: passes if the array or string x contains y toBeLessThan: passes if x is less than y toBeGreaterThan: passes if x is greater than y toThrow: passes if the function fn throws an exception e when executed
  35. But any matcher can evaluate to a negative assertion as well by chaining the call to expect with a not before calling that matcher. It compares the "actual" value to the expected and then passes if they are NOT equivalent (in this case).
  36. In our calculator example, we use the toEqual matcher after we using the calculator object to calculate using two numbers (10 and 15) which were in turn ADDED together The result of that action we use as the "actual" value in the expect function then check that the expected value EQUALS in this case 25.
  37. We can start adding more specs for other operations of the calculator within our test suite. Such as ones for subtracting and multiplying seen here. They both use the expect and toEqual matcher to see if the actual value returned from our calculator object is the value we expected. But alternatively, we could possibly use other matchers such as toBeLessThan for the subtraction spec, to test that the "actual" value is less than x. (TODO: Should this be another slide?)
  38. The next feature is setup and teardown. These are functions are called before and after each test within a test suite. Here you see the basic syntax for the setup, which is function beforeEach. Then the teardown, which is function afterEach.
  39. We can use the beforeEach to help set up variables or the state of the code we want before each of our tests. So now we don't have to repeat that code in every spec we write. For these tests, we use the setup to create a new instance of our 'calculator' object.
  40. Another functionality to use is Spies. Spies act as test doubles and can sub any function and track calls to it with all the arguments. Spies have their own set of special matchers to be used to interact with them. Here we set a spy to make sure that the function 'add' is called when the function 'calculate' is executed with the "+" symbol. It should be noted that we can no longer do expects on the value returned for z, as the function "add" was subbed out with the spy. Which means that when add is called by calculate it doesn't call the calculators add function which returns the calculated value. So we no longer check if the value of z is correct in this particular tests. Hence why the spy is in a separate test than those expectation tests.
  41. Now, we can move onto testing the calculator UI. This time we will interact with the DOM using jQuery for our tests. (We will need to remember to include jQuery in our runner HTML file to do this.) In this test: we get the form populate fields with values submit the form by triggering a change then check the resulting value of the answer field When the test pass, we know a few things: our form and input fields do exist the event handlings are good and the calculator object still works while implemented with the DOM
  42. We can add the DOM tests to the rest of our calculator test suite. To do this, we can nest describes within our main test suite: we can group these DOM specific tests together we can add it's own set of beforeEach/afterEach functions for this set of tests
  43. Here we use the beforeEach to set the form variable that we use it our DOM tests. But we also start using the afterEach as well. We use it to reset the form and it's input fields after we finish each test. So the next test we write starts fresh and doesn't have values that could mess up its results.
  44. Jasmine also has support for running specs that require asynchronous operations. Specs can be written with a set of blocks with calls to the function "runs" and "waitsFor". For our calculator example, it does not have any operations that are asynchronous, so here is another example using a timeout to demonstrate this functionality. The first runs holds the asynchronous call, in this case the timeout function.
  45. The waitsFor block has the latch function, which polls until it returns true. Which we set with the timeout in the runs section above. The waitsFor block also takes an optional failure message and a timeout. If the timeout for the waitsFor expires, the spec fails with the error message.
  46. But once the asynchronous conditions are met based on the return in the latch function of waitsFor, another "runs" block defined the final tests. Which is usually the expectations based on the state after the original async call returns. For example, asynchronous operations is very useful when testing things like: - code that requires loading, for instance: downloads, video or music players, and many others - or code with animations that you may have to wait for it to finish before testing the state after that animation - or when submitting forms - or even testing ajax or other api calls (via javascript)
  47. The javascript file with the suite, is then included via a <script> tag within the HTML runner file. The runner file is used to get Jasmine to execute the suite or suites and all its specs, then use an instance of a reporter such as the HTMLReporter, which is included with jasmine, that calls to get the results of each spec and each suite and finally present those results to the user. The HTMLReporter displays all the suites with each individual sub-suite and spec that ran. It displays in green when the test passes, or red if it fails. Plus it gives a final count of the number of specs that ran, and how many were successful. In this case, we ran all the calculator specs within the suites, totally 6, and all passed!
  48. The javascript file with the suite, is then included via a <script> tag within the HTML runner file. The runner file is used to get Jasmine to execute the suite or suites and all its specs, then use an instance of a reporter such as the HTMLReporter, which is included with jasmine, that calls to get the results of each spec and each suite and finally present those results to the user. The HTMLReporter displays all the suites with each individual sub-suite and spec that ran. It displays in green when the test passes, or red if it fails. Plus it gives a final count of the number of specs that ran, and how many were successful. In this case, we ran all the calculator specs within the suites, totally 6, and all passed!
  49. We can also delegate filtering of the specs to the reporter. This allows for us to click on individual suites or specs and run to see that particular subset, and not the entire list of all tests. We can choose to rerun just the "should be able to add two numbers together" test when that is the only one we care about at the moment.
  50. TODO: Image: Possible idea is to have the code for the test suites then a funnel to go into the headless browser? Now we have a suite of tests for our calculator code that we can run in the browser, we can check if our code works and continues to run as expected. But this still is partly a manual process. The test pages are in HTML and need a browser to run it, with a person still that is to initiate the process and run that page manually. To further automate this process, we want to start to be able to have the tests run but outside of a browser now, something that a non-human could execute. Such as in the command line with the use of a headless browser.
  51. [Useful for]..... particularly for AJAX heavy web sites/apps
  52. So, there is PhantomJS! It is a Headless browser, specially a headless webkit. Which is essentially LIKE Chrome, But - no window - no browser, - and an invisible viewport [Accordingly] It has a javascript API, and so you can feed scripts written with javascript or even coffeescript into the command-line based utility. It has support for various web standards such as: DOM handling, CSS selector, JSON, Canvas, SVG... Really, anything that webkit can do!
  53. So, let's try out a basic example of how to execute JS based programs with PhantomJS. We start off by creating a script file, in this example called hello.js With javascript we can output a message from it using console.log. Then tell phantom to stop and exit To run the script that was just created, we call phantomjs in the command line and pass the path to the script file we just created. It runs our script, and as instructed outputs the message we specified.
  54. PhantomJS uses Module API, which is modeled after CommonJS Modules that are available. This set here is available up through PhantomJS 1.6. ... [read slides]... [Webpage] (read above) is an object that encapsulates a web page (and its functionalities) [System] holds the set of function to access the system level functionality... which includes the os, platform, and env, along with access to the arguments passed into the script [FileSystem] (read above) with the ability to read and write [WebServer] on the other hand is experimental. It uses an embedded web server module called Mongoose, which phantomJS can script to start a web server with. This is intended for ease of communication between PhantomJS scripts and the outside world but is not recommended for use as a general production server.
  55. So using those modules we can use phantomJS for things like: Page loading This example shows a script called loadpage.js In the script, we load and create one of phantomJS's webpage objects. We use the object to load the URL to drupalcon portlands website, using page.open for the first parameter. In the second parameter is the function which is called after the page is loaded, or finishes attempting to load. We explain this a bit further in the next slide. After the page loads though in this case, we render the website to a png image called drupalcon.png Then finally exit from phantomjs
  56. But to further extend the page loading script, we want to pass in arguments and tell our script dynamically which url we want it to load in a page. In order to do so, we take the basics of the last example and modify it.
  57. We start by also creating one of PhantomJS's system objects after the page.
  58. Then we get the first argument, AFTER the path to the script that we are running, from the system.args. The arguments include the path to the script as the first argument passed to phantomJs. We use the URL argument passed to be loaded into the WebPage object
  59. As mentioned before, the second parameter is a function that is called after a page is loaded, but is really called after the attempt to load has happened. So it will also be called if the page failed to load. It passes 1 argument to that function for the status of the page load. We can use it to see if the page load was successful or not, then do different actions depending on it. Here, we output to the console that the address was loaded if it was successful.
  60. Now we can run this example, much like we did before. We call phantomjs and pass in the script path as the first argument, but then as the second argument we pass in the URL that we are going to load. For example, we pass in the URL for google. PhantomJS runs our script, using the google.com parameter to load that page and when it successfully loads, outputs to the console window the message that the address was loaded.
  61. Using PhantomJs's webpage object, we can also conduct code evaluation on the page that was loaded. After a page was successfully loaded, we can use phantom to access and manipulate the code on that page within the page.evaluate function. From there we can return elements or information from the page loaded, for instance the document title, and set it to a variable within our phantomjs script. Then output that title to the console when we run it.
  62. Page loading and code evaluation are used in conjunction to run the jasmine tests that we created, then parse the results from the page so that we can output them in a way that is useful for automation. Thankfully, phantomJS has a list of example scripts, one of which is to run tests with jasmine, which you can find on github under the examples folder. So we can take a look now at the code for run-jasmine.js
  63. This example, loads the page to the jasmine runner file that runs the tests which we pass in as the first argument after this script path. Looking at the code we see the what we learned before with page loading....
  64. the webpage object being created....
  65. then opening that webpage with the variable to the jasmine tests. After page loads successfully, the script needs to wait for the tests to finish executing.....
  66. It does this with its own "waitsFor" function which you pass the check for the condition of what we are waiting for as the first parameter...
  67. ...it uses code evaluation with page.evaluate to do this....
  68. ...and test when the pending class on the body is removed. Which is done by jasmine's HTML Reporter after all the tests done running.
  69. Here we can take a bit closer look at this WaitsFor function. [next]
  70. Not only does it pass the waiting condition, but you also pass it a "onready" function that is called when the waiting condition is met...
  71. and an optional time in milliseconds for how long the script should wait for that condition to be met. By default it is set to 3 seconds.
  72. When that time is reached, and the waiting condition is still not returned, it tells the script to stop, and exit with a failure.
  73. Otherwise, it calls our onReady function that we passed in.
  74. Here we see that onready function to be called.
  75. it uses page.evaluate again to access the page the DOM of the finished runner HTML.
  76. It parses the HTML to identify the number of successes
  77. and failures. Which are reported to the console.
  78. Depending on if there were any failures, it exits phantom with the exit status of 0 or 1. 1 being if any errors existed.
  79. So in conclusion, lets take a quick look at some of the features that we went over for PhantomJS and what it is capable of. You can do a lot more with phantomJS outside of using it to run javascript tests with jasmine. phantomJS can do fast headless testing with other test frameworks too such as Mocha, Qunit, WebDriver, etc But using what we have shown today, it can be used for many different possibilities. You don't have to stop at automating tests! We discussed how it handle Page Automation by accessing and manipulating web pages with the DOM API. But it can also do this with the usual javascript libraries like jQuery. It can also be used for Screen capture, to capture web contents including CSS, SVG, and Canvas For example, there is already a Drupal module out there using PhantomJS, called PhantomJS Capture It has provides integration with PhantomJS and the screen capture abilities to allow you to take screenshots of homepages and use them as images on your site. Finally, it is also possible to use it for Network monitoring. Such as automating performance analysis, or track page loading. You can also use YSlow to integrate with PhantomJS (and even Jenkins) which would be useful for automating web performance.
  80. Plus With version 1.7, phantomJS also adds the possibility of creating and using custom modules. Users can reference and load their own modules using the require function in phantomJS scripts, just as they would with the included Phantom ones Seen here we use the require function to load the webserver, but also our "MyAwesomeModule" in the same way then call functions from the loaded object [pause] But let's head back to finish automating our tests...
  81. So to summarize, we can now see how to execute the Jasmine tests, and run them in the command line with PhantomJS. We can easily run our tests as part of a script! Since we use Jenkins for deployments, we can run the tests after commits as part of the [Next slide] Continuous Integration.
  82. Leading open-source Continuous Integration server Built with Java and it's easy to install and configure Plug-in support with over 400 plug-ins RSS/E-mail/IM support for notifications
  83. Here's the dashboard of jenkins Currently mousing over the project and we see a dropdown menu.
  84. Project view. Build history on the bottom left.
  85. We clicked "Build Now" We see a progress bar. We can also see a more detail view of the progress by clicking the build in the build history
  86. Here's the details of the build as it happens. We can click on the console output to see what the server is doing
  87. Here's the console output We can see that it did a git pull
  88. Right now, the script we created in teh previous section, we had the results from the jasmine tests get spit out with PhantomJS into the console window. For Jenkins to properly understand those results we need to convert the output into something that jenkins can use. The way to so that is to structure the results of the tests into XML. There is a couple version already on github that people have contributed, but the one we have used it from the phantomJs - Jasmine XML Example Project. It is an example project layout that is destined to be used standalone or with Maven, but also works with Jenkins! From this repo we essentially use 2 scripts, a new reporter, and an altered phantomjs script.
  89. First, is a plugin for jasmine for a new reporter. It saves the results of the tests which the phantomjs script will interact with.
  90. To enable it, first include the script in the header, but then before executing jasmine, replace the HTMLReporter, with the Trivial Reporter from Jasmine and then this new PhantomJSReporter.
  91. Next, we take a look at the phantom JS script at phantomjs_jasminexml_runner.js We could take this script as is which is really close but uses different waiting functions, or we can the take parts of it we need and replace sections in our current script.
  92. First, we change the code in the evaluate function for the waitsFor to instead, check the variable in jasmine was set from the new phantom js reporter we use instead of checking the DOM.
  93. When it finishes, the waitsfor function needs to call new code for our on ready function
  94. we replace it so that we can get the suite results from the new phantom js reporter instead of parsing the HTML of the page.
  95. We loop through these results, which returns a list with items that contain an: xml file name Which comes from the name of the suite that the results are for. For our script we will only have one, the one called calculator.
  96. The result also include the xml body. It contains the formatted xml with all the specs for that suite: For each spec, it has the title, the passing status, and any possible error messages.
  97. Our script can now takes that xml file name and create a new file using the PhantomJS file system. Then save content with the given xml body to the created file.
  98. Finally, the script to exit changes a bit. It will get the passed status from the new reporter which will be used to return 0 or 1 again. so to summarize, with the changes that were made now when the script runs: it will run the jasmine tests, get the results of those tests with the new reporter and NOT the DOM, it will structure those results into xml and save the xml into files that jenkins can later use to parse to display the results.
  99. Now we can setup Jenkins to use our new script during the build phase. On the confirguration page of Jenkins, we can select to execute a shell command after we build and push our code. Here we tell phantomjs to run our script, passing in the path to our script, referencing it from the jenkin project workspace. Then we will aslo pass in the URL to our jasmine test runner page, and finally a folder within the workspace for the script to save all the xml result files to.
  100. Now when we build, and see the progress in the console output page, we can watch as the jasmine tests run which still show messages in the console for what tests are currently running, and whether or not they passed.
  101. But for Jenkins to start using the results to display outside of the console ouput, we need to tell it to parse the XML files. We go back to the configuration page, and from within the post build actions section, we can add "Publish xUnit test result report" action, and select to use a JUnit Pattern. The resulting input field is where we enter that folder to all our xml files that we passed to our phantom script for the shell command configuration. We can leave the rest of the checkboxes as the defaults.
  102. But now we can also choose to configure how many jasmine failures it should take to mark the build as having failed. In most cases we can set the threshold to 1 for all fields. So that if one or more failures happen during a build, that build is marked as broken. We can also use this to trigger events such as notifications if we needed.
  103. But for now, we can see Jenkins parsing our results after the tests run in the console window.
  104. Then when it is finished we can see the Test Result section on the main build page, with the count of failures in brackets beside it. (Here we see that there we no failures that happened for our build)
  105. Then when it is finished we can see the Test Result section on the main build page, with the count of failures in brackets beside it. (Here we see that there we no failures that happened for our build)
  106. If we click on the Test Result link, we can see more information about the tests that ran. The bar at the top shows the precentage of successful tests to failed tests. Blue for the percentage of successful ones, and red for the failed. If there were any failures, for each of them they would show in the table beneith All Tests. You could click on any of the failed tests, and see a page that displayed the error message from jasmine for why it failed. But in this case, all our tests were successful so we don't see anything here.
  107. If we click on the Test Result link, we can see more information about the tests that ran. The bar at the top shows the precentage of successful tests to failed tests. Blue for the percentage of successful ones, and red for the failed. If there were any failures, for each of them they would show in the table beneith All Tests. You could click on any of the failed tests, and see a page that displayed the error message from jasmine for why it failed. But in this case, all our tests were successful so we don't see anything here.
  108. .... END