Author: Pranab Kumar Ghatak Test Test Automation Automation Architect Architect | IBM India Pvt. Ltd. Ltd. Mobile: +91 (!"#9$1"1$% | ranab.)hata*in.ibm.com Blog: http://pranabghatak.wordpress.com
&'mail:
Contents TOPIC: SELENIUM.........................................................................................................................4
1. P,-P/& 0 T& 0 T& 23,M&4T:............................................................................................................4 5. /0T6A-& -&7,I-&M&4T/:...............................................................................................................4 8. P-&'-&7,I/IT&/:.................................................................................................................................4 %. LBAL &4I-4M&4T /&T,P:.........................................................................................................4 ;. I4T-2,3T-< 4T&.........................................................................................................................5 #. ,I2&2 &=&-3I/& 1: -&3-2 > PLA
Author: Pranab Kumar Ghatak Test Test Automation Architect Architect | IBM India India Pvt. Ltd. Blog: http://pranabghatak.wordpre http://pranabghatak.wordpress.com ss.com
Assi)nments ' /elenium
ATA 2-I&4 0-AM&6-? .........................................................................20 ". ,I2&2 &=&-3I/& 8: 2ATA .........................................................................20 343&PT : TI/ I43L,2&/ &IT PA-T/ @................................................................................................20 ".1 PLA4 0- T& 0- T& 3A-A3T&-I/TI3/ 0 0-AM&6-? ........................................................................20 ".5 &4I-4M&4T /&T,P /P&3I0I3 T /P&3I0I3 T T& T& 0-AM&6-? ....................................................................21 ".8 2&/I4 A BA/I3 0L6 T&MPLAT&/ T&MPLAT&/ 0 0-AM&6-? .....................................................................21 -&PA-& T&/T 2ATA..........................................................................................................................22 ".% P-&PA-& T&/T ".; P-&PA-& 0,43TI4/ -&7,I-&2.......................................................................................................25 ".# 6-IT& T&/T -IT& T&/T /3-IPT/........................................................................................................................26 ".$ 2&3I2& 2-I&- 0IL&.........................................................................................................................27 "." &=&3,T& T&/T =&3,T& T&/T /3-IPT/ A42 &T /6 -&/,LT/..........................................................................27 I4T-/P&3TI4...........................................................................................................................................27 &<6-2!...............................................28 9. ,I2&2 &=&-3I/& %:
9.# 6-IT& ? &<6-2 &<6-2..............................................................................................................................32 9.$ 6-IT& T&/T -IT& T&/T /3-IPT/........................................................................................................................34 9." 2&3I2& 2-I&- 0IL&.........................................................................................................................35 =&3,T& T&/T /3-IPT/ A42 &T /6 -&/,LT/..........................................................................35 9.9 &=&3,T& T&/T I4T-/P&3TI4...........................................................................................................................................36 1. ,I2&2 &=&-3I/& ;: PA& B&3T M2&L..................................................................................36 343&PT : TI/ I43L,2&/ T-&& PA-T/ @...............................................................................................36 6 T T /TA-T.............................................................................................................................36 1.1 6 1.5 3-&AT& LI4 PA& 3LA//........................................................................................................38 1.8 3-&AT& T&/T 3A/& ......................................................................................................................39 I4T-/P&3TI4...........................................................................................................................................40 11. ,I2&2 &=&-3I/& #: MA&4...........................................................................................................41 11.1 6< MA&4 P-&3TC................................................................................................................41 11.5 264LA2 A42 340I,-& MA&4 8.8.8..............................................................................41 11.8 3-&AT& A MA&4 P-&3T..........................................................................................................41 11.% 34&-T T& 4&-T T& MA&4 P-&3T I4T &3LIP/& P-&3T...........................................................42 11.; 3A4& PM.=ML......................................................................................................................42 11.# 3MPIL& 6IT MA&4.................................................................................................................43 11.$ 3-&AT& M5D-&P A-IABL&.....................................................................................................43 I4T-/P&3TI4...........................................................................................................................................44 15. ,I2&2 &=&-3I/& $: 3I 6IT &4?I4/ A42 IT..........................................................................45 15.1 I4/TALLI4 &4?I4/ A42 340I,-I4 6IT IT....................................................................45 15.5 3-&ATI4 IT -&P/IT-< A42 ,PLA2I4 T& P-&3T.....................................................45 ,4 T& P-&3T ,/I4 &4?I4/ ..............................................................................................46 15.8 -,4 T& .............................................................................51 18. ,I2&2 &=&-3I/& ": 3,3,MB&- 0-AM&6-? .............................................................................51 343&PT : TI/ I43L,2&/ /&&4 PA-T/ @...............................................................................................51 18.1 3-&AT& T& -&AT& T& MA&4 P-&3T .....................................................................................................51 18.5 3-&AT& T& -&AT& T& 0&AT,-& 0IL& /T&P 3LA// A42 -,44&- 3LA//..................................................54 -&AT& T& /&L&4I,M LA<&- ' 6&B344&3T- ....................................................................56 18.8 3-&AT& T& -&ATI4 T& B&3T MAP........................................................................................................57 18.% 3-&ATI4 T& 18.; IMPL&M&4T /T&P 3LA//...............................................................................................................58 18.# PA-AM&T&-IE& T& 0&AT,-& 0IL&...............................................................................................59 18.$ -,44I4 T& T&/T T& T&/T 6IT MA&4...............................................................................................59 I4T-/P&3TI4...........................................................................................................................................60
Author: Pranab Kumar Ghatak Test Test Automation Architect Architect | IBM India India Pvt. Ltd. Blog: http://pranabghatak.wordpre http://pranabghatak.wordpress.com ss.com
Assi)nments ' /elenium
Toic: Toic: /elenium 1. Purpose Purpose of the document document:: The urose oF this this document is to )uide the user user to create create diGerent diGerent tHes oF automation Frameor*s Frameor*s ith /elenium li*e Modular 2ata 2riven Hbrid PM and 3ucumber and imlementin) concets li*e Test4 Test4 ,nit Maven Maven IT and en*ins etc.
2. Software Software Requiremen Requirements: ts: /oFtare &clise I2 Aache PI Test4 Test4 ava Maven 3ucumber en*ins A4T /4 IT
ersion 8.% 8.# 5.# 1.$ 8.8.8 1.5.5 1.#1% 1.9.% 5..% 1.9.;
-emar*s r hi)her r hi)her r hi)her r hi)her r hi)her r hi)her r hi)her r hi)her r hi)her r hi)her
3. Pre-requi Pre-requisites: sites: This ands on assumes assumes that the user user has basic *noled)e *noled)e oF &clise I2 and *no ho to create ProJect ProJect ac*a)e and classes in &clise. A ractitioner level *noled)e on /elenium 6eb 6eb 2river /critin) is eKected beFore beFore )oin) ahead ith the ands on.
4. Global n!ironment Setup: Step 1: Install latest 2? in Hour machine. Step 2: 2onload and install latest &clise I2& For ava && 2eveloers '' htts:eclise.or)donloads
Step 3: Install Test4 in &clise as a lu)in. Author: Pranab Kumar Ghatak Test Test Automation Architect Architect | IBM India India Pvt. Ltd. Blog: http://pranabghatak.wordpre http://pranabghatak.wordpress.com ss.com
Assi)nments ' /elenium
• • •
•
3oH the ,-L htt:beust.comeclise. en &clise and )o to el ' Install ne /oFtare. Paste the ,-L in the N6or* ithO section select Test4 and clic* neKt. 0inish the installation.
". #ntroductor$ %ote Test automation involves automatin) a manual rocess alreadH in lace that uses a Formalied testin) rocess. •
•
• •
•
•
Most 7A start out creatin) test scrits bH usin) record > laHbac* tools hich later roves not suQcient For their reRuirements. In second hase 7A usuallH imroves their tests bH creatin) a business Function librarH Modular reusable test libraries oF Functions. 4eKt 7A usuallH imroves their tests bH addin) data'driven techniRues. In the neKt hase 7A usuallH imroves their tests bH creatin) a *eHord'driven librarH. The earlier hase oF 2ata 2riven techniRues and ?eHords to)ether called the Hbrid aroach. As time asses 7As become more technical and imrove their tests bH usin) obJect oriented testin) techniRues. TheH uses hat is called Pa)e bJect Models hich is also the most advanced techniRue oF creatin) Test Automation 0rameor*s. In 515 ith the introduction oF Behavior'2riven 2eveloment 7ASs no have otion to develo Frameor*s ith the 3ucumber tool. 6e ill be tal*in) about all the above techniRues one bH one in the Folloin) eKercises.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
&. Guided 'ercise 1: Record ( Pla$bac) 6ith the hel oF /elenium I2& record edit and relaH the test in 0ireFoK.
&.1Selenium #* installation /elenium I2& is an inte)rated develoment environment For /elenium tests. It is imlemented as a 0ireFoK eKtension and allos Hou to record edit and relaH the test in 0ireFoK. /elenium I2& allos Hou to save tests as TML ava -ubH scrits or anH other Format. It allos Hou to automaticallH add assertions to all the a)es. Allos Hou to add /elenese commands as and hen reRuired. 1. ,sin) 0ireFoK rst donload the I2& From the /elenium7 donloads a)e.
5. /elect Install 4o. The 0ireFoK Add'ons indo os u rst shoin) a ro)ress bar and hen the donload is comlete dislaHs the belo indo.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. -estart 0ireFoK. AFter 0ireFoK reboots Hou ill nd the /elenium'I2& listed under the 0ireFoK Tools menu. %. To run the /elenium'I2& simlH select it From the 0ireFoK Tools menu. It oens as Follos ith an emtH scrit'editin) indo and a menu For loadin) or creatin) ne test cases.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
&.2Recodin+ a Selenium ,est ase 1. 5. 8. %. ;.
en 0ireFoK that has the I2& installed. en the base ,-L oF the alication to record. ?ee the alication in a common base state. o to Tools ' /elenium I2& and the I2& ill be oened. 4o erForm the oerations on the alication as Hou are testin) the alication. #. nce Hou are done ith the recordin) clic* on the sto recordin) button and save the test case throu)h the le menu. BH deFault it ill be saved as a selenese scrit (TML Format!. $. eneral /elenese 3ommands: a. 3lic*in) a lin* ' clic* or clic*And6ait commands. b. &nterin) values ' tHe command. c. /electin) otions From a dro'don listboK ' select command. d. 3lic*in) chec*boKes or radio buttons ' clic* command.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
&.3Runnin+ our /irst Selenium Script 1. Ma*e sure the alication is in the common base state. 5. 3lic* on the run button. ere Hou can also control the seed oF the eKecution usin) the toolbar. 8. nce the test is run Hou can vie the test lo) in the bottom oF the I2& indo.
&.4reatin+ a ,est Suite 1. In the /elenium I2& Hou can create anH number oF test cases and save them as test suite. 5. To run the test /uite clic* on the NPlaH entire test suiteO button as shon belo.
&."Pla$in+ the test Suite with ,est Runner 1. Test -unner allos Hou to run the test case in a broser loaded ith the /elenium'3ore Test-unner. 5. Test runner is invo*ed bH clic*in) the belo shon button in the I2&.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. n 3lic*in) the Test -unner Button Hou ill the indo as seen belo.
&.&Runnin+ 0ptions 1. -un a Test 3ase: 3lic* the -un button to run the currentlH dislaHed test case. 5. -un a Test /uite: 3lic* the -un All button to run all the test cases in the currentlH loaded test suite. 8. /to and /tart: The Pause button can be used to sto the test case hile it is runnin). The icon oF this button then chan)es to indicate the -esume button. To continue clic* -esume. %. /to in the Middle:
•
•
•
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
;. /tart From the Middle:
•
&.ddin+ ssertions to the Script 1. /elenium allos multile aHs oF chec*in) For ,I elements. 5. erications and assertions are used to chec* iF ' a. An element is resent somehere on the a)eC b. /ecic teKt is somehere on the a)eC c. /ecic teKt is at a secic location on the a)eC 8. erications and assertions are not one and the same. %. IF an assertion Fails the scrit ill be aborted but iF a verication Fails the scrit ill continue.
&.eri5cation ommands 1. veriFHTeKtPresent a. This command is used to chec* iF a articular teKt is resent in a a)e or not. b. To add this command hile recordin) the test stes ri)ht clic* on the teKt item that Hou ant veriFH. nce ri)ht clic*ed Hou can nd an otion N/ho all commandsO. n 3lic*in) it Hou ill nd an otion NveriFHTeKtPresentO select it.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
5. veriFHTitle a. This command is used to chec* iF the a)e title is correct or not. b. To add this command 6hile recordin) the test stes ri)ht clic* anHhere on the a)e that Hou ant veriFH. nce ri)ht clic*ed Hou can nd an otion N/ho all commandsO. n 3lic*in) it Hou ill nd an otion NveriFHTitleO select it.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. veriFH&lementPresent a. This command is used to veriFH iF a a)e element is resent in the a)e or not. b. To add this command 6hile recordin) the test stes ri)ht clic* anH element on the a)e that Hou ant veriFH. nce ri)ht clic*ed Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
Hou can nd an otion N/ho all commandsO. n 3lic*in) it Hou ill nd an otion NveriFH&lementPresentO select it.
%. veriFHalue a. This method is used to chec* iF edit boK has articular value or iF the chec* boK is on. BasicallH this method returns the value oF resent in the obJect.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
b. To add this command 6hile recordin) the test stes ri)ht clic* anH element on the a)e that Hou ant veriFH the value oF. nce ri)ht clic*ed Hou can nd an otion N/ho all commandsO. n 3lic*in) it Hou ill nd an otion NveriFHalueO select it.
&.6ssertion Statements 1. assertTeKtPresent This ill assert iF the teKt is resent in the a)e 5. assertTeKt This ill assert iF a articular element is havin) the articular teKt. •
•
8. assertTitle This ill assert iF the a)e is havin) a roer title. %. assertalue This ill assert iF a TeKt boK or chec* boK has a articular value ;. assert&lementPresent This ill assert iF a articular ,I &lement is resent in the a)e. •
•
•
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
&.17 Selenium 8ait/or ommands 1. ait0orPa)eToLoad a. This command ill ma*e the scrit to ait till the a)e loads. b. /HntaK is ait0orPa)eToLoad (timeout!U Time out is the maKimum time the scrit ill ait For the a)e to load.
5. ait0orAlert This command ill ait For the alert messa)e to aear 8. ait0orTable This command ill ait For the 6eb table to comletelH load in the a)e %. ait0orTitle This command ill For the a)e Title to aear on the broser. ;. ther ait0or commands /elenium has several other ait command li*e ait0orTeKt ait0orPou and so on. These commands are )enericallH called /Hnchroniation commands. •
•
•
•
#ntrospection
•
There are maJor limitation oF the above record > laHbac* aroach. 1. 3an run the test onlH on 0ireFoK. 5. 4o Pro)rammin) lo)in (li*e loos conditional statements! can be alied. 8. /elenium I2& can eKecute scrits created in /elenese onlH. %. It is diQcult to use /elenium I2& For chec*in) comleK test cases involvin) dHnamic contents. To overcome these limitations, QA usuall improves their tests b creatin! a business "unction librar, reusable test libraries o" "unctions# This is $escribe$ in the ne%t e%ercise#
. Guided 'ercise 2: 9ibrar$ rchitecture ,estin+ /ramewor) 3reate a LibrarH Architecture Testin) 0rameor* ith /elenium and Test4. 3reate Function libraries For common tas* in the Frameor*.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
oncept: ,his includes ei+ht parts 1. 5. 8. %. ;. #. $. ".
Plan For the characteristics oF 0rameor*. &nvironment setu secic to the Frameor*. 2esi)n a basic Vo temlates oF Frameor*. Preare test data. Preare Functions reRuired. 6rite test scrits. 2ecide driver le. &Kecute test scrits and )et sho results.
.1Plan for the characteristics of /ramewor). &rame'ork Tpe: LibrarH Architecture Testin) 0rameor*. Test 3haracteristics: a. 6e initialie 0ireFoK 2river and lo)in in the BeFore method. The ,-L can be read From the con) class. b. AFter BeFore method e ill create the Test method and rite our actual test code. 6e maH reRuire to access the values stored in the bJect Ma and con) class. c. LastlH e ill create the AFter method For lo)out and Ruittin) the broser. d. 6e ill create common Functions For tas*s li*e Lo)in and lo)out. e. 0or runnin) the scrit Hou ill use the testin).Kml le.
.2n!ironment setup speci5c to the framewor). 1. 2onload 6eb2river Jar les '' htt:.seleniumhR.or)donload 2. 4o in &clise create a ne roJect bH clic*in) on 0ile menu @ 4e @ ava ProJect ' 4ame the roJect as NtestroJectO and clic* nish. 3. 4o -i)ht'clic* on testProJect and select Proerties. 4. n the Proerties indo clic* on Nava Build PathO. ". 3lic* on the Libraries tab and then clic* NAdd &Kternal A-sO &. 4avi)ate to 3:Wselenium'5.8$.W (or anH other location here Hou saved the eKtracted contents oF NJar les.iO!. . Add all the A- les inside and outside the NlibsO Folder.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
.3*esi+n a basic ;ow< templates of framewor). The LibrarH Architecture Testin) 0rameor* is FundamentallH and FoundationallH built on Module Based Testin) 0rameor* ith some additional advanta)es. Instead oF dividin) the alication under test into test scrits e se)re)ate the alication into Functions or rather common Functions can be used bH the other arts oF the alication as ell. Thus e create a common librarH constitutin) oF common Functions For the alication under test. ThereFore these libraries can be called ithin the test scrits henever reRuired.
The basic Fundamental behind the Frameor* is to determine the common stes and )rou them into Functions under a librarH and call those Functions in the test scrits henever reRuired. (%ample: The lo)in stes can be combined into a Function and *et into a librarH. Thus all the test scrits those reRuire to lo)in the alication can call that Function instead oF ritin) the code all over a)ain. Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
.4Prepare test data. Test data is hard coded in this Frameor*. &ach test scrit has its on data encasulated ithin its on lo)ic. 2ata sharin) is not ossible in this aroach hich is its maJor disadvanta)e.
."Prepare functions required. 1. 6e can create small reusable Functions hich are commonlH used in most oF our test scrits and *ee them in a searate le. Those Functions ill be called bH our test scrits hile erFormin) diGerent actions.
.&8rite test scripts. Step 1: 3reate /crit ac*a)e. Inside the src Folder create a scrit ac*a)e. Inside the obJect ac*a)e create a class N2emoTest.JavaO. The N2emoTest.JavaO ill contain Hour actual scrit. This Folder ill contain all Hour roJect related scrits. • • • •
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
)ote 3: I)nore the errors in the code sniet. Those are due to some name conVict.
.*ecide dri!er 5le. Step 1: 3reate testin).Kml le. Inside the root Folder create testin).Kml le The le ill contain the test name hich has to be eKecuted. • •
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
.'ecute test scripts and +et show results. Step 1: -i)ht clic* on the testin).Kml le. Step 2: /elect -un as ' Test4 /uite. Step 3: o to test'outut Folder ()enerated automaticallH! and oen the indeK.html For the reorts.
#ntrospection The limitations oF the above LibrarH Architecture Testin) 0rameor* is that the data is hard coded inside the scrits. 0or anH chan)e in the data e need to chan)e each and everH scrits here it is used. To overcome this limitation, QA usuall improves their tests b a$$in! $ata*$riven techni+ues# e 'ill see that in the ne%t e%ercise.
. Guided 'ercise 3: *ata *ri!en /ramewor) 3reate a 2ata 2riven testin) (22T! 0rameor* ith /elenium and Test4. -ead the data From the eKcel le and obJect From the obJect ma. ?ee all the common static variables in the con) le.
oncept: ,his includes ei+ht parts 1. 5. 8. %. ;. #. $. ".
Plan For the characteristics oF 0rameor*. &nvironment setu secic to the Frameor*. 2esi)n a basic Vo temlates oF Frameor*. Preare test data. Preare Functions reRuired. 6rite test scrits. 2ecide driver le. &Kecute test scrits and )et sho results.
.1Plan for the characteristics of /ramewor). &rame'ork Tpe: 2ata 2riven 0rameor*. Test 3haracteristics: a. In our test scrit e ill rst read the values From the data eKcel le and store all reRuired data in some variable. b. /econdlH e initialie 0ireFoK 2river and lo)in in the BeFore method. The ,-L can be read From the con) class. c. AFter BeFore method e ill create the Test method and rite our actual test code. 6e maH reRuire to access the values stored in the bJect Ma and con) class.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
d. LastlH e ill create the AFter method For lo)out and Ruittin) the broser. e. 0or runnin) the scrit Hou ill use the testin).Kml le.
.2n!ironment setup speci5c to the framewor). This is same as the LibrarH Architecture Testin) 0rameor*.
.3*esi+n a basic ;ow< templates of framewor). 2ata 2riven Testin) 0rameor* hels the user se)re)ate the test scrit lo)ic and the test data. It lets the user store the test data into an eKternal database li*e roertH les Kml les eKcel les teKt les etc.
The eKamle in the icture belo shos a real time &clise vie oF a /elenium temlate 0rameor* hich e ill be develoin)
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
The basic comonents are: a. 3on)uration.Java contains static data li*e alication ,-LXs and le aths. b. 2ataProvider.Kls contains data eKcel les. c. =lsD-eader.Java contains code to read or rite eKcel data les. d. bJectMa.Java contains obJect reositorH. e. 2emoTest.Java is Hour actual test scrits. F. Test'outut is the Folder hich contains normal TML reorts. ). =/LTD-eorts Folder contains the =/LT reorts. h. Build.Kml is reRuired For A4T and testin).Kml is to run Hour test scrits.
.4Prepare test data. Step 1: 3reate con) ac*a)e: Inside the src Folder create a con) ac*a)e. 3reate a class inside the ac*a)e Ncon)uration.JavaO. The con) le ill contain all static data li*e Broser ath Alication ,-L etc. deendin) on Hour need.
•
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
Step 2: 3reate data ac*a)e: Inside the src Folder create a data ac*a)e. 3reate an eKcel le inside the ac*a)e Ndatarovider.KlsO. The eKcel le ill contain all data li*e ' testcase name username assord search strin) etc.
•
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
Step 3: 3reate bJect ac*a)e. Inside the src Folder create an obJect ac*a)e. Inside the obJect ac*a)e create a class NbJectMa.JavaO. This NbJectMa.JavaO ill contain all the obJect =Path3// locators.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
."Prepare functions required. Step 1: 3reate heler ac*a)e: Inside the src Folder create a heler ac*a)e. Inside the heler ac*a)e create a class N=lsD-eader.JavaO. 3oH and aste the code attached inside the class. 2onload and include the Aache PI Jar les. htt:oi.aache.or)donload.html This N=lsD-eader.JavaO basicallH ill contain the code For readrite Frominto the data le. • •
•
•
=lsD-eader.Java
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
.&8rite test scripts. Step 1: 3reate /crit ac*a)e. Inside the src Folder create a scrit ac*a)e. Inside the obJect ac*a)e create a class N2emoTest.JavaO. The N2emoTest.JavaO ill contain Hour actual scrit. This Folder ill contain all Hour roJect related scrits. • • • •
)ote 1: The code ill read the bJect Ma and 3on) le bH reFerrin) to their static class. e.). driver.nd&lement (BH.name (bJectMa.serchPa)e.submit!!.clic* (!U )ote 2: The =Ls reader class needs to be initialied and read the reRuired data at the be)innin) oF the test. )ote 3: I)nore the errors in the code sniet. Those are due to some name conVict.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
.*ecide dri!er 5le. Step 1: 3reate testin).Kml le. Inside the root Folder create testin).Kml le The le ill contain the test name hich has to be eKecuted. • •
.'ecute test scripts and +et show results. Step 1: -i)ht clic* on the testin).Kml le. Step 2: /elect -un as ' Test4 /uite. Step 3: o to test'outut Folder ()enerated automaticallH! and oen the indeK.html For the reorts.
#ntrospection The ?eHord driven testin) Frameor* is an eKtension to 2ata driven Testin) 0rameor* in a sense that it not onlH se)re)ates the test data From the scrits it also *ees the certain set oF code belon)in) to the test scrit into an eKternal data le. -et.s learn ho' to implement Ke'or$ $riven &rame'ork 'ith Selenium#
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
6. Guided 'ercise 4: =$brid /ramewor) >*ata ? @e$wordA 3reate a Hbrid testin) 0rameor* ith /elenium and Test4. Imlement ?eHord and data driven techniRues.
oncept: ,his includes ei+ht parts 1. 5. 8. %. ;. #. $. ".
Plan For the characteristics oF 0rameor*. &nvironment setu secic to the Frameor*. 2esi)n a basic Vo temlates oF Frameor*. Preare test data. Preare Functions reRuired. 6rite test scrits. 2ecide driver le. &Kecute test scrits and )et sho results.
6.1Plan for the characteristics of /ramewor). &rame'ork Tpe: Hbrid 0rameor*. Test 3haracteristics: a. In our test scrit e ill rst read the values From the data eKcel le and store all reRuired data in some variable. b. /econdlH e ill create ?eHord eKcel le and imlement those *eHords. c. Then e initialie 0ireFoK 2river and lo)in in the BeFore method. The ,-L can be read From the con) class. d. AFter BeFore method e ill create the Test method and rite our actual test code. 6e maH reRuire to access the values stored in the bJect Ma con) class and *eHords eKcel le. e. LastlH e ill create the AFter method For lo)out and Ruittin) the broser. F. 0or runnin) the scrit Hou ill use the testin).Kml le.
6.2n!ironment setup speci5c to the framewor). This is same as the LibrarH Architecture Testin) 0rameor*.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
6.3*esi+n a basic ;ow< templates of framewor). These set oF code are *non as ?eHords and hence the Frameor* is so named. ?eH ords are selF')uidin) as to hat actions needs to be erFormed on the alication.
The *eHords and the test data are stored in a tabular li*e structure and thus it is also oularlH re)arded as Table driven 0rameor*. Ta*e a notice that *eHords and test data are entities indeendent oF the automation tool bein) used. Belo is the basic structure in &clise.
1. The 3on) ac*a)e contains the con)uration inFormationSs same as in data driven Frameor*. It has eKtra one KlK le hich contains the ?eHords (controller.KlsK!. 5. 2atatable contains the =L/ reader. Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. Testscrit are the individual test secic to the alication. %. ?eHords.Java is the imlementation oF the *eHords.
6.4Prepare test data. Step 1: 3reate con) ac*a)e: Inside the src Folder create a con) ac*a)e. 3reate a class inside the ac*a)e Ncon)uration.JavaO. The con) le ill contain all static data li*e Broser ath Alication ,-L etc. deendin) on Hour need.
•
Step 2: 3reate data ac*a)e: Inside the src Folder create a data ac*a)e. 3reate an eKcel le inside the ac*a)e Ndatarovider.KlsO. The eKcel le ill contain all data li*e ' testcase name username assord search strin) etc.
•
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
Step 3: 3reate bJect ac*a)e. Inside the src Folder create an obJect ac*a)e. Inside the obJect ac*a)e create a class NbJectMa.JavaO. This NbJectMa.JavaO ill contain all the obJect =Path3// locators.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
6."Prepare functions required. Step 1: 3reate heler ac*a)e: Inside the src Folder create a heler ac*a)e. Inside the heler ac*a)e create a class N=lsD-eader.JavaO. 3oH and aste the code attached inside the class. 2onload and include the Aache PI Jar les. htt:oi.aache.or)donload.html This N=lsD-eader.JavaO basicallH ill contain the code For readrite Frominto the data le. • •
•
•
=lsD-eader.Java
6.&8rite @e$word 1. There are to arts in this. a. 0irst create the controller.KlsK le hich ill contain all the *eHords. This le is test scrit secic. &verH test scrit ill have its on *eHord Kls le.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
b. /econdlH e need to imlement the *eHords in the Java le. This is test scrit indeendent. All the *eHords have to be imlemented here.
5. The *eHords.Java le ill contain alication indeendent *eHords li*e @ clic*Lin* clic*Button 4avi)ateTo,-L veriFH&lement veriFHTeKt etc.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
6.8rite test scripts. 1. The test scrit ill have three section: a. BeFore3lass:
b. Test: -ead the controller.KlsK le and eKecute the *eHords ritten in ?eHords.Java.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
c. AFter/uite: 6rite the reort iF anH.
)ote 1: 3on)uration les can be imlemented either in the Form oF teKt le or Java class le. IF it is a teKt le (-.roerties! then Hou need to rite the code to read it. IF it is a Java class le then theH can be easilH reFerred bH their static class name. )ote 2: The =Ls reader class needs to be initialied and read the reRuired data at the be)innin) oF the test. )ote 3: I)nore the errors in the code sniet. Those are due to some name conVict.
6.*ecide dri!er 5le. Step 1: 3reate testin).Kml le. Inside the root Folder create testin).Kml le The le ill contain the test name hich has to be eKecuted. • •
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
6.6'ecute test scripts and +et show results. Step 1: -i)ht clic* on the testin).Kml le. Step 2: /elect -un as ' Test4 /uite. Step 3: o to test'outut Folder ()enerated automaticallH! and oen the indeK.html For the reorts.
#ntrospection 3reatin) /elenium test cases can result in an unmaintainable roJect. ne oF the reasons is that too manH dulicated code is used. 2ulicated code could be caused bH dulicated FunctionalitH and this ill result in dulicated usa)e oF locators. The disadvanta)e oF dulicated code is that the roJect is less maintainable. IF some locator ill chan)e Hou have to al* throu)h the hole test code to adJust locators here necessarH. BH usin) the a)e obJect model e can ma*e non'brittle test code and reduce or eliminate dulicate test code. Beside oF that it imroves the readabilitH and allos us to create interactive documentation. Last but not least e can create tests ith less *eHstro*e. An imlementation oF the a)e obJect model can be achieved bH searatin) the abstraction oF the test obJect and the test scrits.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
17. Guided 'ercise ": Pa+e 0bBect Codel 3reate a test automation Frameor* ith the hel oF Pa)e bJect Model.
oncept: ,his includes three parts 1. o to start. 5. 3reate Lo)in Pa)e class. 8. 3reate test cases. All the other concets remains the same as the other Frameor*s li*e @ data readin) con) les =L/ -eader bJect Ma and driver testin).Kml le to run the test.
17.1 =ow to start. 1. 3reate a Y4e Pac*a)eS le and name it as Ya)ebJectsS bH ri)ht clic* on the ProJect and select 4e Pac*a)e. 6e ill be creatin) diGerent ac*a)es For Pa)e bJects ,tilities Test 2ata Test 3ases and Modular actions. It is alaHs recommended to use this structure as it is easH to understand easH to use and easH to maintain. 5. 3reate a Y4e 3lassS le and reFer the name to the actual a)e From the test obJect bH ri)ht clic* on the above created Pac*a)e and select 4e 3lass. In our case it is ome Pa)e and Lo)In Pa)e. 8. 4o create a /tatic Method For each &lement (bJect! in the ome Pa)e. &ach method ill have an Ar)ument (driver! and a -eturn value (element!.
%. 2river is bein) assed as an Ar)ument so that /elenium is able to locate the element on the broser (driver!. ;. &lement is returned so that an Action can be erFormed on it. #. Method is declared as Public /tatic so that it can be called in anH other method ithout instantiate the class. Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
17.2 reate 9o+#n Pa+e class 1. 3reate the Lo)in a)e class.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
5. 3reate 3reate a Y4e Y4e 3lassY 3lassY and name it as PMDT PMDT3 3 bH ri)ht clic* clic* on the Yautomation0rameor*Y Pac*a)e and select 4e 3lass. 6e ill be creatin) all our test cases under this ac*a)e.
17.3 17 .3 reate reate ,est ,est case. case. 1. 4o create create ne ne Pa)e Pa)e bJect bJect Model Model test test case. case.
Author: Pranab Kumar Ghatak Test Test Automation Architect Architect | IBM India India Pvt. Ltd. Blog: http://pranabghatak.wordpre http://pranabghatak.wordpress.com ss.com
Assi)nments ' /elenium
5.
Author: Pranab Kumar Ghatak Test Test Automation Architect Architect | IBM India India Pvt. Ltd. Blog: http://pranabghatak.wordpre http://pranabghatak.wordpress.com ss.com
Assi)nments ' /elenium
#ntrospection There are are as such no serious serious limitations For the the above Pa)e Pa)e bJect Model 0rameor* but e can introduce certain ne Features to it to ma*e it more oerFul and industrH u'to'the'minute. Till no' 'e have create$ out pro/ect in eclipse manuall an$ a$$e$ the /ars manuall# -et.s inte!rate 0A() to $o all these "or us.
Author: Pranab Kumar Ghatak Test Test Automation Architect Architect | IBM India India Pvt. Ltd. Blog: http://pranabghatak.wordpre http://pranabghatak.wordpress.com ss.com
Assi)nments ' /elenium
11. Guided 'ercise &: Ca!en 3reate a Maven ProJect and imort it in &clise.
11.1 8h$ Ca!en ProBectD 1. Maven uses PM.Kml here Hou can rovide all Hour Jar le name and version. Maven ill automaticallH donload all the reRuired Jars in &clise. 5. IF multile eole are or*in) on the same ProJect there is a chance oF mismatch in the Jar le version and sHnchroniation. 6ith Maven Hou can share the PM.Kml across the team members and ensure that all oF them are usin) the same Jar les ith same version. 8. It is industrH standard. %. Maven ill create a T&/T and MAI4 Folder in eclise. This is MavenSs deFault Folder structure.
11.2 *ownload and con5+ure Ca!en 3.3.3 1. o to htt:maven.aache.or)donload.c)i 5. 2onload the aache'maven'8.8.8'bin.i le and eKtract in Hour machine. 8. 3reate an &nvironment variable NM5DM&O and )ive the ath oF Maven directorH in Hour machine. %. &dit the NPATO variable and add the bin directorH ath oF Maven at the end oF it. ;. /et the AADM& iF it is not set. #. en command console and tHe Nmvn @versionO. $. IF maven version is shoin) correctlH then Hou are all set ith Maven.
11.3 reate a Ca!en ProBect 1. 3reate a directorH N2emoProJectO in Hour machine here Hou ant to create the Maven ProJect. 5. en command console and )o inside the N2emoProJectO Folder. 8. THe Nmvn archetHe:)enerateO %. Press enter hen romt ith N3hoose a numberO. ;. &nter )rouid as Ncom.testin)O. Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
#. &nter artiFactid as NMHMavenProJectO. $. Press &nter hen as*ed For the version. ". Press &nter hen as*ed to choose ac*a)e name.
11.4 on!ert the Ca!en ProBect into clipse ProBect. 1. AFter Hou run the Nmvn archetHe: )enerateO command successFullH Hou ill see the src Folder and PM.Kml le in the roJect directorH. 5. 4o Hou need to convert this roJect to an &clise roJect so that Hou can imort it in &clise 8. o to command romt and )o inside the roJect Folder OMHMavenProJect Nand tHe the command Nmvn eclise:ecliseO. %. .roJect and .classle les ill )et )enerated in the NMHMavenProJectO Folder. ;. 4o Hour roJect is readH to be imorted in eclise. #. o to eclise and ri)ht clic* to imort the ProJect.
11." han+e P0C.'ml 1. In PM.Kml e *ee all the deendent Jar les hich automaticallH ill be donloaded hen e comile the roJect ith Maven. 5. Belo is a samle PM.Kml. 4ote the deendent section.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. en the eKistin) PM.Kml in the roJect and edit it. Add all the deendencies Hou need For Hour roJect. %.
11.& ompile with Ca!en 1. en 3ommand console and )o inside the roJect Folder. 5. THe Nmvn comileO. This ill comile Hour roJect and brin)s all the Jars mentioned in the PM.Kml.
11. reate C2ERP0 !ariable 1. AFter Hou eKecute Nmvn comileO successFullH all the deendent Jars ill be donloaded in the ath N3:W2ocuments > /ettin)sWuserW.m5WreositorHO. 5. en &clise and )o to ava Build Path ' Libraries. 3lic* on NAdd ariableO and add a variable called NM5D-&PO ith the ath oF Hour reositorH. 8.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
#ntrospection
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
12. Guided 'ercise : # with Fen)ins and G#, 3reate a ne reositorH in IT,B and uload Hour roJect les. /chedule the build in en*ins and mail to the admin iF build Fails.
12.1 #nstallin+ Fen)ins and con5+urin+ with G#, This has been covered in the resentation. Please reFer the NIT IT,B > en*insO resentation.
12.2 reatin+ G#, repositor$ and uploadin+ the proBect. 1. en )ithub.com and si)n in. 5. 3lic* on the ne reositorH button.
8. Provide the reositorH name. %. /elect NPublicO or NPrivateO. ;. 3lic* 3reate reositorH.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
#. en N)itbashO in the -un. $. o to the ProJect location and tHe the belo commands one aFter another in the )itbash For creatin) ne reositorH: a. )it init b. )it add . c. )it commit @m Nrst commitO d. )it remote add ori)in )it)ithub.com:usernamereositorH name.)it e. )it ush @u ori)in master ". This ill add commit and ush all Hour roJect les in )ithub.
12.3 Run the ProBect usin+ Fen)ins. 1. o to command console and start en*ins.
5. en en*ins at Nlocalhost:""O. 8. 3lic* N4e itemO and rovide the item name. 3lic* ?.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
%. /elect the /ource 3ode Mana)ement as NITO. ;. Provide the reositorH ,-L hich Hou nd inside IT,B hen Hou oen Hour roJect reositorH.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
#. Add a build tri))er iF Hou ant.
$. Add Build stes. IF it is Maven ProJect select N&Kecute to'level Maven tar)etsO.
". 0or eKamle iF Hou ant to run Nmvn testO add onlH NtestO.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
9. Provide email id For build Failure notications.
1./ave the a)e. 11.o to N2ashboardO and Hou can no see the roJect in the list.
15.n clic*in) NBuild 4oO Hou can see the ro)ress in the leFt hand anel. Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
18.3lic* on the build number and then clic* on the console outut.
1%.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
13. Guided 'ercise : ucumber /ramewor) 3reate Automation Test 0rameor* ith /elenium and 3ucumber. Ta*e /alesForce as the eKamle ebsite.
oncept: ,his includes se!en parts %. 3reate the Maven ProJect. ;. 3reate the Feature le ste class and runner class. #. 3reate the selenium laHer @ 6eb3onnector. $. 3reatin) the bJect ma. ". Imlement ste class. 9. Parameterie the Feature le. 1.-unnin) the test ith Maven.
13.1 reate the Ca!en ProBect 1. 3reate a Maven roJect as shon in the above eKercise For Maven. ,se the PM.Kml attached. (om.Kml
5. AFter Hou create the Frameor* throu)h Maven it ill loo* similar to the belo )ure.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. ATest.Java is a temlate hich is automaticallH created bH Maven.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
13.2 reate the feature 5le< step class and runner class. 1. 3reate the Feature le.
5. 3reate the rst lo)in test in the Feature le.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
8. 3reate the ste class.
%. 3reate the Feature le and the ste class under diGerent source Folder but under same ac*a)e name. This is as er industrH standard but Hou can *ee them under the same Folder as ell. ;. 3reate a runner class.
#. -un the test 'ri)ht clic* on the roJect ' run as unit Test.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
13.3 reate the selenium la$er - 8ebonnector 1. 6eb3onnector is the selenium laHer called bH the ste classes. 5. 6hen e run the runner class it ill call the ste class. The ste class ill ta*e the inut From the 0eature les and run bH usin) the selenium Functions ritten inside the 6eb3onnector methods.
8.
Assi)nments ' /elenium
13.4 reatin+ the 0bBect map. 1. There are to aHs to create the bJect ma. a. 3reate a teKt le and ut all the obJects there. Then rite a ro)ram to read the teKt le. b. 3reate a class le and ut all the bJects as static variable.
13." #mplement step class. Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
1. 4o imlement the ste class.
13.& Parameterie the feature 5le 1.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com
Assi)nments ' /elenium
5. This ill run the same test as number oF times as manH ros Hou secied in the Feature le.
13. Runnin+ the test with Ca!en. 1. The PM.Kml that e are usin) has all the inFormationSs e need. a. Build inFormationSs: AnH ne source Folder created bH the user. b. Plu)in: Tells Maven to eKecute the test c. Inte)ration hase: Tells Maven hich hase oF the test Hou ant to run. d. 3ucumber.ai.cli.Main: &Kecution starts From here.
Author: Pranab Kumar Ghatak Test Automation Architect | IBM India Pvt. Ltd. Blog: http://pranabghatak.wordpress.com