Upload
mickael-andrieu
View
196
Download
1
Embed Size (px)
Citation preview
CASPERJSL'OUTILQUIVADEVENIRVOTRE
MEILLEURAMI!
ParisJS#34-25/02/2014
QU'EST-CEQUECASPERJS?Unoutildescriptingwebetdetesting
Testsfonctionnels
InitialementunesurcouchedePhantomjs
FAITESENTRERLEFANTOMEInstallerPhantomJs: http://phantomjs.org
InstallerCasperJs:
LancerCasper:allons-y!
http://casperjs.org
varcasper=require('casper').create({});
ComplètementCross/Plateformebonus:lescriptshellen1clicpourlesdistribGNU/Linux
SUPPORTS...PhantomJspermetd'utiliserWebkitJs
SafariChrome&chromiumOpera
Firefox?=>CasperJssupportesSlimerJs
InternetExplorer?=> estenWIP,etgèreIE8+(\o/)TrifleJs
TESTERDESFORMSvarcasper=require('casper').create({});//http://docs.casperjs.org/en/latest/quickstart.html#now-let-s-scrape-googlecasper.start('http://www.google.fr',function(){this.test.pass('AccesstoGoogleSearchEngineSuccess');});//Fillloginformandsubmitcasper.thenOpen('http://www.google.fr',function(){this.test.info('Currentlocationis'+this.getCurrentUrl());this.fill('form[action="/search"]',{q:'esgi'},true);});
Rechercher"esgi"dansGoogle
CLIC&SUIVIDELIENSvarcasper=require('casper').create({});
//AccesstoGoogleSearchEngineFrancecasper.start('http://www.siteduzero.com/');casper.then(function(){//Clickon1stresultlinkthis.click('a[href="/conditions-generales-utilisation"]');});
//accesstoCGUpagecasper.then(function(){console.log('clickedok,newlocationis'+this.getCurrentUrl());});
AccéderàlapagedesCGUensuivantleclic
REALISERDESSCREENSHOTS//Isgooglesearchenginereachable?casper.start('http://www.google.fr',function(){if(!this.test.assertHttpStatus(200,'http://www.google.fr')){//Screenshotifgoogleisunreachablethis.capture('error.png');}});casper.thenOpen('http://www.cockpit.airlines-manager.com',function(){this.test.assertTitle('AirlinesManager:jeuenlignedegestiongratuit','Ok,it\'sgood');});
Supportesjpg/png/gifet...PDFCasperJsest"CSS3-sélecteur"compatible™
TESTSFONCTIONNELS//Isgooglesearchenginereachable?casper.test.begin('AtestSuite',2,functionsuite(test){casper.start('http://www.google.fr',function(){if(!test.assertHttpStatus(200,'http://www.google.fr')){//Screenshotifgoogleisunreachablethis.capture('error.png');}});casper.thenOpen('http://www.cockpit.airlines-manager.com',function(){test.assertTitle('AirlinesManager:jeuenlignedegestiongratuit','Ok,it\'sgood');});});
Disponibilitédelapage,d'élementsduDOM
TESTSUNITAIRES//fromhttp://docs.casperjs.org/en/latest/modules/tester.html#assertinstanceoffunctionCow(){this.moo=functionmoo(){return'moo!';};}casper.test.begin('assertInstanceOf()tests',2,functionsuite(test){vardaisy=newCow();test.assertInstanceOf(daisy,Cow,"Ok,daisyisacow.");test.assertInstanceOf(["moo","boo"],Array,"Wecantestforarraystoo!");test.done();});
Bienmoinsbonque Mocha.js
EXPORTSMULTIPLES
RetoursJUnit/console/(HTML)
ACCEDERAUSHELL(?)//dosomecaspersjsstuff...varchildProcess;try{childProcess=require('child_process');}catch(e){casper.log(e,'error');}if(childProcess){childProcess.execFile('/bin/bash',['echo.sh','Hello','World'],null,function(err,stdout,stderr){casper.log('execFileSTDOUT:'+stdout,'debug');casper.log('execFileSTDERR:'+stderr,'debug');});casper.log('Done','debug');}else{casper.log('Unabletorequirechild_processnativemodule','warning');}
Etd'autresbizarreriesàdécouvrir:-)
POURFINIR...Unesuperdocumentationcomplèteetàjour
Beaucoupdepossibilités:scripting,testing...
SortiesConsole&XML,"Jenkins-ready"
Vousenvoulezencoreplus?
DESQUESTIONS??