L`OUTIL QUI VA DEVENIR VOTRE MEILLEUR AMI !
Transcription
L`OUTIL QUI VA DEVENIR VOTRE MEILLEUR AMI !
CASPERJS L'OUTILQUIVADEVENIRVOTRE MEILLEURAMI! ParisJS#34-25/02/2014 QU'EST-CEQUECASPERJS? Unoutildescriptingwebetdetesting Testsfonctionnels InitialementunesurcouchedePhantomjs FAITESENTRERLEFANTOME InstallerPhantomJs:http://phantomjs.org InstallerCasperJs:http://casperjs.org LancerCasper:allons-y! varcasper=require('casper').create({}); ComplètementCross/Plateforme bonus:lescriptshellen1clicpourlesdistribGNU/Linux SUPPORTS... PhantomJspermetd'utiliserWebkitJs Safari Chrome&chromium Opera Firefox? =>CasperJssupportesSlimerJs InternetExplorer? =>TrifleJsestenWIP,etgèreIE8+(\o/) TESTERDESFORMS varcasper=require('casper').create({}); //http://docs.casperjs.org/en/latest/quickstart.html#now-let-s-scrape-google casper.start('http://www.google.fr',function(){ this.test.pass('AccesstoGoogleSearchEngineSuccess'); }); //Fillloginformandsubmit casper.thenOpen('http://www.google.fr',function(){ this.test.info('Currentlocationis'+this.getCurrentUrl()); this.fill('form[action="/search"]',{q:'esgi'},true); }); Rechercher"esgi"dansGoogle CLIC&SUIVIDELIENS varcasper=require('casper').create({}); //AccesstoGoogleSearchEngineFrance casper.start('http://www.siteduzero.com/'); casper.then(function(){ //Clickon1stresultlink this.click('a[href="/conditions-generales-utilisation"]'); }); //accesstoCGUpage casper.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')) { //Screenshotifgoogleisunreachable this.capture('error.png'); } }); casper.thenOpen('http://www.cockpit.airlines-manager.com',function(){ this.test.assertTitle('AirlinesManager:jeuenlignedegestiongratuit','Ok,it\'sgood '); }); Supportesjpg/png/gifet...PDF CasperJsest"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')) { //Screenshotifgoogleisunreachable this.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#assertinstanceof functionCow(){ 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(); }); BienmoinsbonqueMocha.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,stdo ut,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??