SlideShare a Scribd company logo
1 of 18
Download to read offline
Superfast Automated Web
Testing
with CasperJS & PhantomJS
Agenda
1. What’s Casper
2. Why Casper
3. Installation
4. Live demo
5. Debugging
6. Refactoring
7. Advanced topics
Web UI testing framework
Similar to Selenium Watir
Built on top of PhantomJS
Started around Sep 2011
3329 stars on Github
What’s CasperJS?
Why Casper?
Fast
No browser UI
Webkit based
Execution Speed
Write front end UI testing using JS
Did I mention how fast test runs?
How to install and run
Requirements: python + phantomJS
Available on Windows, OSX, Linux
Install
OSX: $	brew	install	casperjs	--devel	
Node: $	npm	install	-g	casperjs	
Run	
$	casperjs	test	mytest.js
test.assertTextExists("Todo	App")	
test.assert(1	==	1)	
test.assertDoesntExist("#justin_bieber")	
test.assertEquals(1+1,	2)	
test.assertElementCount(".good_justin_bieber_son
gs",	0)	
Assertions
casper.click("#create_task")	
casper.clickLabel("My	link	is	beautiful",	"a");	
casper.clickLabel("But	my	button	is	sexier",	
"button");	
Navigation clicks
WTF is then()?
“then() basically adds a new navigation step in a stack. A step is a javascript
function which can do two different things:
- waiting for the previous step - if any - being executed
- waiting for a requested url and related page to load”
Niko, Creator of CasperJS
Source: http://stackoverflow.com/questions/13785670/passing-variable-from-this-evaluate-to-casper-then
casper.waitForSelector("#sun",	function()	{	alert("Go	out	and	play");	});	
	
casper.waitWhileSelector(".dark_clouds",	function()	{	alert("Go	out	and	
play");	});	
	
casper.waitFor(function	check()	{		
		return	this.evaluate(function()	{		
				return	$(".dark_clouds").length	==	0		
		});	
},	function	then()	{	alert("Go	out	and	play!");	});	
Waiting for element to load
casper.waitUntilVisible("#natalie_portman",	function()	{});	
casper.waitWhileVisible(".one_direction_fans",	function()	{});	
casper.waitForSelectorTextChange("#inbox_unread_count",	
function()	{});	
	
casper.start("http://why.univer.se/").waitForText("42",	
function()	{});	
casper.start("http://foo/").waitForUrl(/login.html$/,	
function()	{});	
	
casper.waitForResource("scarlett_johansson.png",	function()	{});	
casper.wait(1000,	function()	{});	//	No!!	
Waiting for element to load (cont.)
casper.sendKeys('form#contact	input#name',	
'Chuck	Norris');	
	
casper.fill('form#contact',	{	
			'name':	'Chuck	Norris'	
},	true);	
	
Type text, fill forms
casper.evaluate(function()	{	
				return	$('.tasks').length;	
});	
Execute Javascript
casper.click("#link");	
	
x	=	require('casper').selectXPath;	
casper.click(x("//a[@id='link']"));	
CSS3 VS XPath selectors
Debugging Casper
casper.echo(casper.getHTML()	
casper.capture("screenshot.png")	
casper.on("remote.message",	function	(msg)	
{	casper.echo('Browser	says:	'	+	msg)	}	
Verbose mode
$	casper	--verbose	--log-level=debug	
Use safari (for rendering issues)
Refactoring
common.js
casper.createTask	=	function(title)	{	
		this.sendKeys('#new-todo',	title);	
		return	this.sendKeys('#new-todo',	this.page.event.key.Enter);	
};	
	
mytest.js
casper.createTask('Code	feature	1');
Advanced topics
1.  Setup/tear down
2.  Support for file downloads, HTTP auth
3.  Support for browser back/forward, scroll, reload, viewport site
4.  Support for page events, alerts handling
5.  Support for Continuous Integration
a.  Jenkins XUnit output
$	casperjs	test	mytest.js	--xunit=outcome.xml	
b.  GruntJS
6.  Support for HTTPS
$	casperjs	tumblr.js	--ssl-protocol=any	
7.  Weak support for Drag and Drop
About me+us
Author: Herve Vu Roussel (see source at GitHub)
Find me at: hroussel@gmail.com
This presentation was made for Javascript Ho Chi Minh City meetup group
You can find us at:
http://www.meetup.com/JavaScript-Ho-Chi-Minh-City/
https://www.facebook.com/JavaScriptHCMC
https://plus.google.com/u/0/communities/116105314977285194967
http://www.slideshare.net/JavascriptMeetup
PLEASE CLAP

More Related Content

What's hot

Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and Groovy
Kiyotaka Oku
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
John Anderson
 

What's hot (20)

Vagrant plugin development intro
Vagrant plugin development introVagrant plugin development intro
Vagrant plugin development intro
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web Applications
 
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
Like a Genie from a Lamp: Headless JavaScript Unit Testing with Jasmine and P...
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginx
 
NodeJS: n00b no more
NodeJS: n00b no moreNodeJS: n00b no more
NodeJS: n00b no more
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End Workflow
 
Haibu: dev deployment is fast and easy again
Haibu: dev deployment is fast and easy againHaibu: dev deployment is fast and easy again
Haibu: dev deployment is fast and easy again
 
Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and Groovy
 
Code ceptioninstallation
Code ceptioninstallationCode ceptioninstallation
Code ceptioninstallation
 
Windows Azure loves OSS
Windows Azure loves OSSWindows Azure loves OSS
Windows Azure loves OSS
 
Node.jsやってみた
Node.jsやってみたNode.jsやってみた
Node.jsやってみた
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
 
Service worker - Offline Web
Service worker - Offline WebService worker - Offline Web
Service worker - Offline Web
 
Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Node.js Cloud deployment
Node.js Cloud deploymentNode.js Cloud deployment
Node.js Cloud deployment
 

Similar to Superfast Automated Web Testing with CasperJS & PhantomJS

Node.js in a heterogeneous system
Node.js in a heterogeneous systemNode.js in a heterogeneous system
Node.js in a heterogeneous system
GeeksLab Odessa
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 

Similar to Superfast Automated Web Testing with CasperJS & PhantomJS (20)

Node.js in a heterogeneous system
Node.js in a heterogeneous systemNode.js in a heterogeneous system
Node.js in a heterogeneous system
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Node.js in a heterogeneous system
Node.js in a heterogeneous systemNode.js in a heterogeneous system
Node.js in a heterogeneous system
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development tools
 
Selenium Webdriver
Selenium WebdriverSelenium Webdriver
Selenium Webdriver
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
Frisby.js - Give it a Toss
Frisby.js - Give it a TossFrisby.js - Give it a Toss
Frisby.js - Give it a Toss
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Unit testing for User Interfaces
Unit testing for User InterfacesUnit testing for User Interfaces
Unit testing for User Interfaces
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
 
Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript
 
Webpack packing it all
Webpack packing it allWebpack packing it all
Webpack packing it all
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
 

More from Hervé Vũ Roussel (6)

Offline First with CouchDB
Offline First with CouchDBOffline First with CouchDB
Offline First with CouchDB
 
Groovify your java code by hervé roussel
Groovify your java code by hervé rousselGroovify your java code by hervé roussel
Groovify your java code by hervé roussel
 
Code fast & Break things with Jenkins & Continuous Integration
Code fast & Break things with Jenkins & Continuous IntegrationCode fast & Break things with Jenkins & Continuous Integration
Code fast & Break things with Jenkins & Continuous Integration
 
3 lessons i learned from building a killer start up
3 lessons i learned from building a killer start up3 lessons i learned from building a killer start up
3 lessons i learned from building a killer start up
 
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
How I learned to stop worrying and love the bugs with Jenkins & Continuous In...
 
GW SDAB Dev Tools 2012
GW SDAB Dev Tools 2012GW SDAB Dev Tools 2012
GW SDAB Dev Tools 2012
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Superfast Automated Web Testing with CasperJS & PhantomJS

Editor's Notes

  1. Pros - Speed Cons - Faceless
  2. Pros - Speed Cons - Faceless
  3. Pros - Speed Cons - Faceless
  4. Pros - Speed Cons - Faceless
  5. Pros - Speed Cons - Faceless
  6. Pros - Speed Cons - Faceless
  7. Pros - Speed Cons - Faceless
  8. Pros - Speed Cons - Faceless
  9. Pros - Speed Cons - Faceless
  10. Pros - Speed Cons - Faceless
  11. Pros - Speed Cons - Faceless
  12. Pros - Speed Cons - Faceless
  13. Pros - Speed Cons - Faceless