SlideShare une entreprise Scribd logo
1  sur  17
Ajay Dutta
CasperJS
What we’ll cover?
○ Installation
○ What’s CasperJS?
○ What’s PhantomJS?
○ Doing common task
○ Quick start
○ Module fill
○ Click
○ Evalute
○ Evalute Flow
○ Wait for Selection
○ Real life example
Installation
○ Prerequisites
○ PhantomJS
○ PhantomJS is a headless WebKit scriptable with a JavaScript API.
○ It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas,
and SVG.
○ http://phantomjs.org/download.html
○ CasperJS
CasperJS
○ CasperJS is an open source navigation scripting & testing
utility written in Javascript for the PhantomJS WebKit
headless browser or SlimerJS.
○ It eases the process of defining a full navigation scenario
and provides useful high-level functions, methods &
syntactic sugar
PhantomJS
○PhantomJS is a headless WebKit with a JavaScript API. It has fast
and native support for various web standards: DOM handling, CSS
selectors, JSON, Canvas and SVG.
Doing common tasks
○ such as:
○ defining & ordering browsing navigation steps
○ filling & submitting forms
○ clicking & following links
○ capturing screenshots of a page (or part of it)
○ testing remote DOM
○ logging events
○ downloading resources, including binary ones
○ writing functional test suites, saving results as JUnit XML
○ scraping Web contents
A minimal scraping script
○ What did we just do?
○ we created a new Casper instance
○ we started it and opened http://casperjs.org/
○ once the page has been loaded, we asked to print
the title of that webpage (the content of its <title>
tag)
○ then we opened another url, http://phantomjs.org/
○ once the new page has been loaded, we asked to
print its title too
○ we executed the whole process
start(), then(), run(), exit()
○ start()
○ Signature: start(String url [, Function then])
○ Configures and starts Casper, then open the provided url and optionally adds the step provided by the then argument
○ then()
○ Signature: then(Function then)
○ run()
○ Signature: run(fn onComplete[, int time])
○ Runs the whole suite of steps and optionally executes a callback when they’ve all been done. Obviously, calling this method is
mandatory in order to run the Casper navigation suite.
○ exit()
○ Signature: exit([int status])
○ Exits PhantomJS with an optional exit status code.
○ Note that the current Casper instance automatically binds the this keyword for you within step functions
casper module – fill
○ Signature: fill(String selector, Object values[, Boolean submit])
○ Fills the fields of a form with given values and optionally submits it.
○ Fields are referenced by their name attribute.
click
○ click(Number x, Number y)
○ click(String selector)
○ Performs a click on the first element found matching the provided selector expression
or at given coordinates if two numbers are passed
○ selector expression
○ CSS3 selector strings
○ Xpath expressions
evaluate
○ Signature: evaluate(Function fn[, arg1[, arg2[, …]]])
○ Evaluates an expression in the current page DOM context
Understanding evaluate()
○ Think of the evaluate() method as a gate between the CasperJS environment and the
one of the page you have opened;
○ Every time you pass a closure to evaluate(), you’re entering the page and execute
code as if you were using the browser console.
Asynchronous rendering of page
waitForSelector
○ Signature: waitForSelector(String selector[, Function then, Function onTimeout, Number
timeout])
○ Waits until an element matching the provided selector expression exists in remote DOM
to process any next step
Real Life Example
Let’s talk about real life example
references
○ http://docs.casperjs.org/en/latest/quickstart.html
○ http://docs.casperjs.org/en/latest/modules/index.html
○ http://docs.casperjs.org/en/latest/modules/casper.html#start
○ http://docs.casperjs.org/en/latest/modules/casper.html#then
○ http://docs.casperjs.org/en/latest/modules/casper.html#run
○ http://docs.casperjs.org/en/latest/modules/casper.html#exit
○ http://docs.casperjs.org/en/latest/modules/casper.html#fill
○ http://docs.casperjs.org/en/latest/selectors.html
○ http://docs.casperjs.org/en/latest/modules/mouse.html#click
Thank you

Contenu connexe

En vedette

6 a megan johnson
6 a megan johnson6 a megan johnson
6 a megan johnsonColorGirl
 
Ronaldo
RonaldoRonaldo
RonaldoAldo24
 
Electrización por-frotamiento
Electrización por-frotamientoElectrización por-frotamiento
Electrización por-frotamientoOkabe Makise
 
Smart goal playing basketball
Smart goal playing basketballSmart goal playing basketball
Smart goal playing basketballfjhayes1
 
The tao of winnie the pooh
The tao of winnie the poohThe tao of winnie the pooh
The tao of winnie the poohboshears1
 
The test angelica gibb
The test   angelica gibbThe test   angelica gibb
The test angelica gibbMissCoull
 
Blink 182 All The Small Things Analysis
Blink 182   All The Small Things AnalysisBlink 182   All The Small Things Analysis
Blink 182 All The Small Things AnalysisGreenshaw High School
 
Chivas regal - Company Analysis
Chivas regal - Company AnalysisChivas regal - Company Analysis
Chivas regal - Company AnalysisPallav Tyagi
 
Sheet Music: Inuyasha - Hanyou (violin)
Sheet Music: Inuyasha - Hanyou (violin)Sheet Music: Inuyasha - Hanyou (violin)
Sheet Music: Inuyasha - Hanyou (violin)sayakahime
 
Self harm - what? why? and how to help
Self harm - what? why? and how to helpSelf harm - what? why? and how to help
Self harm - what? why? and how to helpPooky Knightsmith
 
Sixty reasons why i love you
Sixty reasons why i love youSixty reasons why i love you
Sixty reasons why i love youAlan Ross
 

En vedette (20)

Villanos spiderman
Villanos spidermanVillanos spiderman
Villanos spiderman
 
6 a megan johnson
6 a megan johnson6 a megan johnson
6 a megan johnson
 
Tic karina leon
Tic karina leonTic karina leon
Tic karina leon
 
Por Eso Te Quiero Cuenca
Por Eso Te Quiero CuencaPor Eso Te Quiero Cuenca
Por Eso Te Quiero Cuenca
 
slipknot
slipknotslipknot
slipknot
 
Ronaldo
RonaldoRonaldo
Ronaldo
 
Electrización por-frotamiento
Electrización por-frotamientoElectrización por-frotamiento
Electrización por-frotamiento
 
Smart goal playing basketball
Smart goal playing basketballSmart goal playing basketball
Smart goal playing basketball
 
The tao of winnie the pooh
The tao of winnie the poohThe tao of winnie the pooh
The tao of winnie the pooh
 
The test angelica gibb
The test   angelica gibbThe test   angelica gibb
The test angelica gibb
 
Inuyasha
InuyashaInuyasha
Inuyasha
 
Dia Del Te Quiero(2)
Dia Del Te Quiero(2)Dia Del Te Quiero(2)
Dia Del Te Quiero(2)
 
Blink 182 All The Small Things Analysis
Blink 182   All The Small Things AnalysisBlink 182   All The Small Things Analysis
Blink 182 All The Small Things Analysis
 
Chivas regal - Company Analysis
Chivas regal - Company AnalysisChivas regal - Company Analysis
Chivas regal - Company Analysis
 
Angina de pecho
Angina de pechoAngina de pecho
Angina de pecho
 
Slipknot
SlipknotSlipknot
Slipknot
 
Cuento piluca la mariposa artista
Cuento piluca la mariposa artistaCuento piluca la mariposa artista
Cuento piluca la mariposa artista
 
Sheet Music: Inuyasha - Hanyou (violin)
Sheet Music: Inuyasha - Hanyou (violin)Sheet Music: Inuyasha - Hanyou (violin)
Sheet Music: Inuyasha - Hanyou (violin)
 
Self harm - what? why? and how to help
Self harm - what? why? and how to helpSelf harm - what? why? and how to help
Self harm - what? why? and how to help
 
Sixty reasons why i love you
Sixty reasons why i love youSixty reasons why i love you
Sixty reasons why i love you
 

Similaire à Casper js

Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Igalia
 
Lightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just RightLightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just Rightmircodotta
 
Google Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptGoogle Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptOmar Miatello
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScriptDenis Voituron
 
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the UglyKotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the UglyHaim Yadid
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?Ankara JUG
 
Dmytro Kochergin Angular 2 and New Java Script Technologies
Dmytro Kochergin Angular 2 and New Java Script TechnologiesDmytro Kochergin Angular 2 and New Java Script Technologies
Dmytro Kochergin Angular 2 and New Java Script TechnologiesLogeekNightUkraine
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scaladatamantra
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개Reagan Hwang
 
Blockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchainHub Graz
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for CassandraEdward Capriolo
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"DataStax Academy
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponLaurent Duveau
 

Similaire à Casper js (20)

CasperJS
CasperJSCasperJS
CasperJS
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
 
Lightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just RightLightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just Right
 
Google Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptGoogle Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScript
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Ajax-Tutorial
Ajax-TutorialAjax-Tutorial
Ajax-Tutorial
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScript
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the UglyKotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
Dmytro Kochergin Angular 2 and New Java Script Technologies
Dmytro Kochergin Angular 2 and New Java Script TechnologiesDmytro Kochergin Angular 2 and New Java Script Technologies
Dmytro Kochergin Angular 2 and New Java Script Technologies
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
Understanding Implicits in Scala
Understanding Implicits in ScalaUnderstanding Implicits in Scala
Understanding Implicits in Scala
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Revealing ALLSTOCKER
Revealing ALLSTOCKERRevealing ALLSTOCKER
Revealing ALLSTOCKER
 
Blockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub Graz
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 

Dernier

KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Dernier (20)

KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Casper js

  • 2. What we’ll cover? ○ Installation ○ What’s CasperJS? ○ What’s PhantomJS? ○ Doing common task ○ Quick start ○ Module fill ○ Click ○ Evalute ○ Evalute Flow ○ Wait for Selection ○ Real life example
  • 3. Installation ○ Prerequisites ○ PhantomJS ○ PhantomJS is a headless WebKit scriptable with a JavaScript API. ○ It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. ○ http://phantomjs.org/download.html ○ CasperJS
  • 4. CasperJS ○ CasperJS is an open source navigation scripting & testing utility written in Javascript for the PhantomJS WebKit headless browser or SlimerJS. ○ It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar
  • 5. PhantomJS ○PhantomJS is a headless WebKit with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selectors, JSON, Canvas and SVG.
  • 6. Doing common tasks ○ such as: ○ defining & ordering browsing navigation steps ○ filling & submitting forms ○ clicking & following links ○ capturing screenshots of a page (or part of it) ○ testing remote DOM ○ logging events ○ downloading resources, including binary ones ○ writing functional test suites, saving results as JUnit XML ○ scraping Web contents
  • 7. A minimal scraping script ○ What did we just do? ○ we created a new Casper instance ○ we started it and opened http://casperjs.org/ ○ once the page has been loaded, we asked to print the title of that webpage (the content of its <title> tag) ○ then we opened another url, http://phantomjs.org/ ○ once the new page has been loaded, we asked to print its title too ○ we executed the whole process
  • 8. start(), then(), run(), exit() ○ start() ○ Signature: start(String url [, Function then]) ○ Configures and starts Casper, then open the provided url and optionally adds the step provided by the then argument ○ then() ○ Signature: then(Function then) ○ run() ○ Signature: run(fn onComplete[, int time]) ○ Runs the whole suite of steps and optionally executes a callback when they’ve all been done. Obviously, calling this method is mandatory in order to run the Casper navigation suite. ○ exit() ○ Signature: exit([int status]) ○ Exits PhantomJS with an optional exit status code. ○ Note that the current Casper instance automatically binds the this keyword for you within step functions
  • 9. casper module – fill ○ Signature: fill(String selector, Object values[, Boolean submit]) ○ Fills the fields of a form with given values and optionally submits it. ○ Fields are referenced by their name attribute.
  • 10. click ○ click(Number x, Number y) ○ click(String selector) ○ Performs a click on the first element found matching the provided selector expression or at given coordinates if two numbers are passed ○ selector expression ○ CSS3 selector strings ○ Xpath expressions
  • 11. evaluate ○ Signature: evaluate(Function fn[, arg1[, arg2[, …]]]) ○ Evaluates an expression in the current page DOM context
  • 12. Understanding evaluate() ○ Think of the evaluate() method as a gate between the CasperJS environment and the one of the page you have opened; ○ Every time you pass a closure to evaluate(), you’re entering the page and execute code as if you were using the browser console.
  • 14. waitForSelector ○ Signature: waitForSelector(String selector[, Function then, Function onTimeout, Number timeout]) ○ Waits until an element matching the provided selector expression exists in remote DOM to process any next step
  • 15. Real Life Example Let’s talk about real life example
  • 16. references ○ http://docs.casperjs.org/en/latest/quickstart.html ○ http://docs.casperjs.org/en/latest/modules/index.html ○ http://docs.casperjs.org/en/latest/modules/casper.html#start ○ http://docs.casperjs.org/en/latest/modules/casper.html#then ○ http://docs.casperjs.org/en/latest/modules/casper.html#run ○ http://docs.casperjs.org/en/latest/modules/casper.html#exit ○ http://docs.casperjs.org/en/latest/modules/casper.html#fill ○ http://docs.casperjs.org/en/latest/selectors.html ○ http://docs.casperjs.org/en/latest/modules/mouse.html#click