Q #1) What is Automation Testing? Automation testing or Test Automation Automation is a process of automating the manual manu al process to test the application/system under test. Automation Automation testing involves use to a separate testing tool which lets you create test scripts which can e e!ecuted repeatedly and doesn"t reuire any manual intervention. Q #$) What are the enefits of Automation Testing? Testing? %enefits of Automation testing are& 1. 'upport 'upportss e!ecut e!ecution ion of of repeat repeated ed test test cases cases $. Aids Aids in testin testing g a larg largee test test matr matri! i! (. n nal ales es para parall llel el e!ec e!ecut utio ion n *. ncoura ncourages ges unatte unattende nded d e!ecu e!ecuti tion on +. ,mproves ,mproves accuracy accuracy therey therey reducing reducing human generated generated errors errors -. 'ave 'avess tim timee and and mon money ey Q #() Why should 'elenium e selected as a test tool? 'elenium 1. is free free and and ope open n sou sourc rcee $. have a larg largee user user ase ase and helpi helping ng commun communiti ities es (. have cross cross %rowser %rowser compatiilit compatiility y irefo!0 irefo!0 chrome0 chrome0 ,nternet ,nternet !plorer0 !plorer0 'afari 'afari etc.) etc.) *. have great great platform platform compati compatiility ility Windows0 Windows0 ac 2'0 3inu! etc.) etc.) +. supports supports multiple multiple programm programming ing languages languages 4ava0 4ava0 5#0 6uy0 6uy0 7ython0 7ython0 7earl etc.) etc.) -. has fresh fresh and and regular regular reposi repositor tory y developm development entss 8. sup suppor ports ts distri distriute uted d testin testing g Q #*) What is 'elenium? What are the different 'elenium components? 'elenium is one of the most popular popu lar automated testing suites. 'elenium is designed in a way wa y to support and encourage automation testing of functional aspects of we ased applications and a
wide range of rowsers and platforms. 9ue to its e!istence in the open source community0 it has ecome one of the most accepted tools amongst the testing professionals. 'elenium is not :ust a single tool or a utility0 rather a pac;age of several testing tools and for the same reason it is referred to as a 'uite. ach of these tools is designed to cater different testing and test environment reuirements. The suite pac;age constitutes of the following sets of tools& •
•
•
•
'elenium ,ntegrated 9evelopment nvironment ,9) < ,9) < 'elenium ,9 is a record and playac; tool. ,t is distriuted as a irefo! 7lugin. 'elenium 6emote 5ontrol 65) < 'elenium 65 is a server that allows user to create test scripts in a desired programming language. ,t also allows e!ecuting test scripts within the large spectrum of rowsers. 'elenium We9river < < We9river We9river is a different tool altogether that has various advantages over 'elenium 65. We9river We9river directly communicates with the we rowser and uses its native compatiility to automate. 'elenium =rid < =rid < 'elenium =rid is used to distriute your test e!ecution e!ecu tion on multiple platforms and environments concurrently. concurrently.
Q #+) What are the testing types that can e e supported y 'elenium? 'elenium supports the following types of testing& 1. unct unctio ional nal Testin sting g $. 6egr 6egres essi sion on Testin sting g Q #-) What are the limitations of 'elenium? ollowing are the limitations of 'elenium& •
'elenium supports testing of only we ased applications
•
oile applications cannot e tested using 'elenium
•
5aptcha and %ar code readers cannot e tested using 'elenium
•
6eports can only e generated ge nerated using third party tools li;e Test>= Test>= or 4unit.
•
As 'elenium is a free tool0 thus there is no ready vendor support though the user can find numerous helping communities.
•
ser is e!pected to possess prior programming language ;nowledge.
Q #8)What is the difference etween 'elenium ,90 'elenium 65 and We We9river? 9river? eature eature
'elenium ,9 'elenium ,9
'elenium 65 'elenium 65
We9river We9river We9river supports a varied 'elenium 65 range of versions supports a varied of o@illa irefo!0 'elenium ,9 range of versions =oogle 5hrome0 comes as a %rowser of o@illa ,nternet !plorer irefo! plugin0 5ompatiility irefo!0 =oogle and 2pera. thus it supports 5hrome0 ,nternet Also supports only irefo! !plorer and tmlnit9river 2pera which is a =, less or headless rowser. 'elenium ,9 'elenium 65 We9riverdoesnBt 6ecord and supports record doesnBt supports support record and 7layac; and playac; record and playac; feature feature playac; feature 'elenium ,9 'elenium 65 We9river doesnBt doesnBt reuire reuires server reuire any server 'erver any server to e to e started to e started efore 6euirement started efore efore e!ecuting e!ecuting the test e!ecuting the the test scripts scripts test scripts We9river uses 'elenium ,9 is 'elenium 65 is the rowserBs a 4avascript a 4ava'cript Architecture native ased ased compatiility to framewor; ramewor; automation 'elenium ,9 is 'elenium 65 is We9river is a 2:ect 2riented not an o:ect semi o:ect purely o:ect oriented tool oriented tool oriented tool 9ynamic inders 'elenium ,9 'elenium 65 We9river for locating we doesnBt support doesnBt support supports dynamic elements on a dynamic finders dynamic finders finders wepage) andling Alerts0 'elenium ,9 'elenium 65 We9river offers a >avigations0 doesnBt doesnBt e!plicitly wide range of 9ropdowns e!plicitly provides aids to utilities and classes provides aids to handle alerts0 that helps in handle alerts0 navigations0 handling alerts0
eature eature
'elenium ,9 'elenium ,9
'elenium 65 'elenium 65
We9river We9river navigations0 and navigations0 dropdowns dropdowns dropdowns efficiently and effectively. We9river is designed in a way to efficiently support testing of 'elenium ,9 'elenium 65 i7hone/Android WA7 doesnBt support doesnBt support applications. The i7hone/Android) testing of testing of tool comes with a Testing i7hone/Andriod i7hone/Andriod large range of applications applications drivers for WA7 ased testing. or e!ample0 Android9river0 i7hone9river We9river 'elenium ,9 'elenium 65 supports the 3istener 'upport doesnBt support doesnBt support implementation of listeners listeners 3isteners 'elenium 65 is slower than 'elenium ,9 is We9river as it fast as it is doesnBt plugged in with communicates We9river the weCrowser directly with the communicates that launches the rowserD rather it directly with the 'peed test. Thus0 the sends selenese we rowsers. ,9 and commands over Thus ma;ing it rowser to 'elenium much faster. communicates 5ore which in directly turn communicates with the rowser. Q #E) When should , use 'elenium ,9? 'elenium ,9 is the simplest and easiest of all the tools within the ' elenium 7ac;age. ,ts record and playac; feature ma;es it e!ceptionally easy to learn with minimal acuaintances to any programming language. 'elenium ,9 is an ideal tool for a naFve user. Q #G) What is 'elenese?
'elenese is the language which is used to write test scripts in 'elenium ,9. Q #1H)What are the different types of locators in 'elenium? 3ocator can e termed as an a n address that identifies a we element uniuely uniuel y within the wepage. Thus0 to identify we elements accurately and precisely we have different types of locators in 'elenium&& 'elenium •
,9
•
5lass>ame
•
>ame
•
Tag>ame
•
3in;Te!t
•
7artial3in;Te!t
•
Ipath
•
5'' 'elector
•
92
Q #11)What is difference etween assert and verify commands? Assert& Assert command chec;s whether the given condition is true or false. 3et"s say we assert whether the given element is present on the we page or not. n ot. ,f the condition is true then the program control will e!ecute the ne!t test step ut if the condition is false0 false0 the e!ecution would stop and no further test would e e!ecuted. Jerify& Jerify& Jerify Jerify command also chec;s chec ;s whether the given condition is true or false. ,rrespective of the condition eing true or false0 the program e!ecution doesn"t halts i.e. any failure during verification would not stop the e!ecution and all the test steps would e e!ecuted. Q #1$) What is an Ipath? Ipath is used to locate a we element ased on its I3 path. I3 stands for !tensile Ipath is ar;up 3anguage and is used to store0 organi@e and transport aritrary data. ,t stores data in a ;eyCvalue pair which is very much similar to T3 tags. %oth eing mar;up languages and since they fall under the same umrella0 Ipath Ip ath can e used to locate T3 elements.
The fundamental ehind locating elements using Ipath is the traversing etween various elements across the entire page and thus enaling a user to find an element with the reference of another element. Q #1() What is the difference etween K/L and K//L in Ipath? 'ingle 'lash K/L < 'ingle slash is used to create Ipath with asolute path i.e. the !path would e created to start selection from the document node/start node. 9oule 'lash K//L < 9oule slash is used to create Ipath with relative path i.e. the !path would e created to start selection from anywhere within the document. Q #1*) What is 'ame origin policy and how it can e handled? The prolem of same origin policy disallows to access the 92 of a document from an origin that is different from the origin we are trying to access the document. 2rigin is a seuential comination of scheme0 host and port of the 63. or e!ample0 for a 63 http&// http&//www.softwaretestinghelp.com/resources/0 the origin is a comination of http0 softwaretestinghelp.com0 EH correspondingly. Thus the 'elenium 5ore 4ava'cript 7rogram) cannot access the elements from an origin that is different from where it was launched. or !ample0 if , have launched the 4ava'cript 7rogram from Khttp&//www.softwaretestinghelp.comL0 then , would e ale to access the pages within the same domain such as Khttp&//www.softwaretestinghelp.com/resourcesL or Khttp&//www.softwaretestinghelp.com/istCfreeCupdates/L. The other domains li;e google.com0 seleniumh.org would no more e accessile. 'o0 ,n order to handle same origin policy0 'elenium 6emote 5ontrol was introduced. Q #1+)When should , use 'elenium =rid? 'elenium =rid can e used to e!ecute same or different test scripts on multiple platforms and rowsers concurrently so as to achieve distriuted test e!ecution0 testing under different environments and saving e!ecution time remar;aly. Q #1-) What do we mean y 'elenium 1 and 'elenium $? 'elenium 65 and We9river0 in a comination are popularly ;nown as 'elenium $. 'elenium 65 alone is also referred as 'elenium 1. Q #18) Which is the latest 'elenium tool? We9river Q #1E) ow do , launch the rowser using We9river?
The following synta! can e used to launch %rowser& WebDriver driver = newFirefoxDriver(); WebDriver driver = newChromeDriver(); WebDriver driver = newInternetExplorerDriver(); Q #1G) What are the different types of 9rivers availale in We9river? The different drivers availale in We9river are& •
irefo!9river
•
,nternet!plorer9river
•
5hrome9river
•
'afari9river
•
2pera9river
•
Android9river
•
,7hone9river
•
tmlnit9river
Q #$H) What are the different types of waits availale in We9river? There are two types of waits availale in We9river & 1. ,mplicit Wait $. !plicit Wait ,mplicit Wait& ,mplicit waits are used to provide a default waiting time say (H seconds) etween each consecutive test step/command across the entire test script. Thus0 suseuent test step would only e!ecute when the (H seconds have elapsed after e!ecuting the previous test step/command. !plicit Wait& !plicit waits are used to halt the e!ecution till the time a particular condition is met or the ma!imum time has elapsed. nli;e ,mplicit waits0 e!plicit waits are applied for a particular instance only. Q #$1)ow to type in a te!to! using 'elenium? ser can use sendMeysK'tring to e enteredL) to enter the string in the te!to!.
'ynta!& WebElement username = drv.findElement(!.id("Email#)); $$ enterin% username username.send&e!s("sth#); Q #$$)ow can you find if an element in displayed on the screen? We9river facilitates the user with the following methods to chec; the visiility of the we elements. These we elements can e uttons0 drop o!es0 chec;o!es0 radio uttons0 laels etc. 1. is9isplayed) $. is'elected) (. isnaled) 'ynta!& is9isplayed)& booleanbutton'resene = driver.findElement(!.id("%bfba#)).isDispla!ed(); is'elected)& booleanbutton*eleted = driver.findElement(!.id("%bfba#)).isDispla!ed(); isnaled)& booleansearhIonEnabled = driver.findElement(!.id("%bfb#)).isEnabled(); Q #$()ow can we get a te!t of a we element? =et command is used to retrieve the inner te!t of the specified we element. The command doesn"t reuire any parameter ut returns a string value. ,t is also o ne of the e!tensively used commands for verification of messages0 laels0 errors etc displayed on the we pages. 'ynta!& *trin% +ext = driver.findElement(!.id("+ext#)).%et+ext(); Q #$*) ow to select value in a dropdown? Jalue in the drop down can e selected using We9river"s 'elect class. 'ynta!& select%yJalue& *elet selet!,alue = new *elet(driver.findElement(!.id("*eletID-ne#))); selet!,alue.selet!,alue("%reenvalue#);
select%yJisileTe!t& *elet selet!,isible+ext = new *elet (driver.findElement(!.id("*eletID-+wo#))); selet!,isible+ext.selet!,isible+ext("/ime#); select%y,nde!& *elet selet!Index = new *elet(driver.findElement(!.id("*eletID-+hree#))); selet!Index.selet!Index(0); Q #$+) What are the different types of navigation commands? ollowing are the navigation commands& navigate).ac;) < The aove command reuires no parameters and ta;es ac; the user to the previous wepage in the we rowser"s history. 'ample code& driver.navi%ate().ba1(); navigate).forward) < This command lets the user to navigate to the ne!t we page with reference to the rowser"s history. 'ample code& driver.navi%ate().forward(); navigate).refresh) < This command lets the user to refresh the current we page there y reloading all the we elements. 'ample code& driver.navi%ate().refresh(); navigate).to) < This command lets the user to launch a new we rowser window and navigate to the specified 63. 'ample code& driver.navi%ate().to("https2$$%oo%le.om#); Q #$-) ow to clic; on a hyper lin; using lin;Te!t? driver.findElement(!.lin1+ext("3oo%le#)).li1();
The command finds the element using lin; te!t and then clic; on that element and thus the user would e reCdirected to the corresponding page. The aove mentioned lin; can also e accessed y using the following command. driver.findElement(!.partial/in1+ext("3oo#)).li1();
The aove command find the element ased on the sustring of the lin; provided in the parenthesis and thus partial3in;Te!t) finds the we element with the specified sustring and then clic;s on it. Q #$8)ow to handle frame in We9river ? An inline frame acronym as iframe is used to insert another document with in the current T3 document or simply a we page into a we page y enaling nesting. 'elect iframe y id driver.swith+o().frame("ID of the frame"); 3ocating iframe using tag>ame driver.swith+o().frame(driver.findElements(!.ta%4ame("iframe#).%et(5)); 3ocating iframe using inde! frameinde!) driver.swith+o().frame(5); CCCCCCCCCCCC
frame>ame of rame) driver.swith+o().frame("name of the frame#); frameWelement element) 'elect 7arent Window driver.swith+o().defaultContent(); Q #$E) When do we use findlement) and findlements)? findlement)& findlement) is used to find the first element in the current we page matching to the specified locator value. Ta;e a note that only first matching element would e fetched . 'ynta!& WebElement element = driver.findElements(!.xpath("$$div67id=8example89$$ul$$li#)); findlements)& findlements) is used to find all the elements in the current we page matching to the specified locator value. Ta;e a note that all the matching elements would e fetched and stored in the list of Welements.
'ynta!& /ist :WebElementelement/ist = driver.findElements(!.xpath("$$div67id=8example89$$ul$$li#));
Q #$G)ow to find more than one we element in the list? At times0 we may come across elements of same type li;e multiple hyperlin;s0 images etc arranged in an ordered or unordered list. Thus0 it ma;es asolute sense to deal with such elements y a single piece of code and this can e done using Welement 3ist. 'ample 5ode 1 // Storing the list List
elementList = 2 driver.findElements(By.x!th("//div#$id=%ex!mle%&//'l//li") * 4 7
// +et,hing the si-e of the list intlistSi-e = elementList.si-e() for(inti=0) i
Q #(H) What is the difference etween driver.close) and driver.uit command? close)& We9river"s close) method closes the we rowser window that the user is currently wor;ing on or we can also say the window that is eing currently accessed y the We9river. The command neither reuires any parameter nor does is return any value. uit)& nli;e close) method0 uit) method closes down all the windows that the program has opened. 'ame as close) method0 the command neither reuires any parameter nor does is return any value. Q #(1) 5an 'elenium handle windows ased pop up? 'elenium is an automation testing tool which supports only we application testing. Therefore0 windows pop up cannot e handled using 'elenium. Q #($) ow can we handle we ased pop up? We9river offers the users with a very efficient way to handle these pop ups using Alert interface. There are the four methods that we would e using along with the Alert interface. •
•
void dismiss) < The accept) method clic;s on the K5ancelL utton as soon as the pop up window appears. void accept) < The accept) method clic;s on the K2;L utton as soon as the pop up window appears.
•
•
'tring getTe!t) < The getTe!t) method returns the te!t displayed on the alert o!. voidsendMeys'tring stringTo'end) < The sendMeys) method enters the specified string pattern into the alert o!.
'ynta!& $$ aeptin% driver.%et+itle().euals("+itle of the pa%e#));
Q #(+) ow to mouse hover on a we element using We9river? We9river offers a wide range of interaction utilities that the user can e!ploit to automate mouse and ;eyoard events. Action ,nterface is one such utility which simulates the single user interactions. Thus0 ,n the following scenario0 we have used Action ,nterface to mouse hover on a drop down which then opens a list of options. 'ample 5ode& 1 // nst!nti!ting ,tion nterf!,e 2 ,tions !,tions=ne,tions(driver) * // hoering on the drodon !,tions.move?oElement(driver.findElement(By.id("id of the drodon".erform() // 5li,6ing on one of the items in the list otions WebElements'bLin6@tion=driver.findElement(By.id("id of the s'b lin6") 4 s'bLin6@tion.,li,6()
Q #(-) ow to retrieve css properties of an element? The values of the css properties can e retrieved using a get) method&
'ynta!& driver.findElement(!.id("id")).%etCss,alue("name of ss attribute#); driver.findElement(!.id("id")).%etCss,alue("font?si@e#); Q #(8) ow to capture screenshot in We9river? 1 2 * 4
imortorg.A'nit.fter) imortorg.A'nit.Before) imortorg.A'nit.?est) imortA!v!.io.+ile) imortA!v!.io.@Ex,etion) imortorg.!!,he.,ommons.io.+iletils) imortorg.oenC!.seleni'm.@'t't?ye)
7 imortorg.oenC!.seleni'm.?!6esS,reenshot) 9 imortorg.oenC!.seleni'm.WebDriver) 10 imortorg.oenC!.seleni'm.firefox.+irefoxDriver) 11 12 1* 1 1 1 14 17 19 20 21 22
'bli,,l!ss5!t'reS,reenshot 3 WebDriver driver) $Before 'bli,voidset( throsEx,etion 3 driver = ne+irefoxDriver() driver.get("htts//google.,om") ; $fter 'bli,voidte!rDon( throsEx,etion 3 driver.C'it() ;
2* 2 $?est 2 'bli,voidtest( thros@Ex,etion 3 2 // 5ode to ,!t're the s,reenshot 24 +ile s,r+ile = ((?!6esS,reenshotdriver.getS,reenshots(@'t't?ye.+LE) 27 // 5ode to ,oy the s,reenshot in the desired lo,!tion +iletils.,oy+ile(s,r+ileF 29 ne+ile("5GG5!t'reS,reenshotGGgoogle.Ag") *0 ; *1 ;
Q #(E) What is 4unit? 4unit is a unit testing framewor; introduced y Apache. 4unit is ased on 4ava. Q #(G) What are 4unit annotations? ollowing are the 4unit Annotations&
•
•
•
•
•
•
NTest& Annotation lets the system ;now that the method annotated as NTest is a test method. There can e multiple test methods in a single test script. N%efore& ethod annotated as N%efore lets the system ;now that this method shall e e!ecuted every time efore each of the test method. NAfter& ethod annotated as NAfter lets the system ;now that this method shall e e!ecuted every time after each of the test method. N%efore5lass& ethod annotated as N%efore5lass lets the system ;now that this method shall e e!ecuted once efore any of the test method. NAfter5lass& ethod annotated as NAfter5lass lets the system ;now that this method shall e e!ecuted once after any of the test method. N,gnore& ethod annotated as N,gnore lets the system ;now that this method shall not e e!ecuted.
Q #*H)What is Test>= and how is it etter than 4unit? Test>= is an advance framewor; designed in a way to leverage the enefits y oth the developers and testers. With the commencement of the framewor;s0 4nit gained an enormous popularity across the 4ava applications0 4ava developers and 4ava testers with remar;aly increasing the code uality. 9espite eing easy to use and straightforward0 4nit has its own limitations which give rise to the need of ringing Test>= into the picture. Test>= is an open source framewor; which is distriuted under the Apache software 3icense and is readily availale for download. Test>= with We9river provides an efficient and effective test result format that can in turn e shared with the sta;e holders to have a glimpse on the product"s/application"s health therey eliminating the drawac; of We9river"s incapaility to generate test reports. Test>= has an inuilt e!ception handling mechanism which lets the program to run without terminating une!pectedly. There are various advantages that ma;e Test>= superior to 4nit. 'ome of them are& •
Added advance and easy annotations
•
!ecution patterns can set
•
5oncurrent e!ecution of test scripts
•
Test case dependencies can e set
Q #*1)ow to set test case priority in Test>=?
'etting 7riority in Test>= 5ode 'nippet 1 2 * 4 7 9 10 11 12 1*
!,6!ge?est:H) imortorg.testng.!nnot!tions.I) 'bli,,l!ssSetting8riority 3 $?est(riority=0 'bli,voidmethod1( 3 ; $?est(riority=1 'bli,voidmethod2( 3 ; $?est(riority=2 'bli,voidmethod*( 3 ; ;
Test !ecution 'euence& 1. ethod1 $. ethod$ (. ethod( Q #*$) What is a framewor;? ramewor; is a constructive lend of various guidelines0 coding standards0 concepts0 processes0 practices0 pro:ect hierarchies0 modularity0 reporting mechanism0 test data in:ections etc. to pillar automation testing. Q #*()What are the advantages of Automation framewor;? Advantage of Test Automation framewor; •
6eusaility of code
•
a!imum coverage
•
6ecovery scenario
•
3ow cost maintenance
•
inimal manual intervention
•
asy 6eporting
Q #**) What are the different types of framewor;s? %elow are the different types of framewor;s& 1. odule %ased Testing ramewor;& The framewor; divides the entire KApplication nder TestL into numer of logical and isolated modules. or each module0 we create a separate and independent test script. Thus0 when these test scripts ta;en together uilds a larger test script representing more than one module. $. 3irary Architecture Testing ramewor;& The asic fundamental ehind the framewor; is to determine the common steps and group them into functions under a lirary and call those functions in the test scripts whenever reuired. (. 9ata 9riven Testing ramewor;& 9ata 9riven Testing ramewor; helps the user segregate the test script logic and the test data from each other. ,t lets the user store the test data into an e!ternal dataase. The data is conventionally stored in KMeyCJalueL pairs. Thus0 the ;ey can e used to access and populate the data within the test scripts. *. Meyword 9riven Testing ramewor;& The Meyword driven testing framewor; is an e!tension to 9ata driven Testing ramewor; in a sense that it not only segregates the test data from the scripts0 it also ;eeps the certain set of code elonging to the test script into an e!ternal data file. +. yrid Testing ramewor;& yrid Testing ramewor; is a comination of more than one aove mentioned framewor;s. The est thing aout such a setup is that it leverages the enefits of all ;inds of associated framewor;s. -. %ehavior 9riven 9evelopment ramewor;& %ehavior 9riven 9evelopment framewor; allows automation of functional validations in easily readale and understandale format to %usiness Analysts0 9evelopers0 Testers0 etc. Q #*+) ow can , read test data from e!cels? Test data can efficiently e read from e!cel using 4I3 or 72, A7,. 'ee detailed tutorial here. Q #*-) What is the difference etween 72, and :!l :ar? #
4I3 :ar 4I3 supports K.!lsL format i.e. inary ased format. 4I3 1 doesn"t support !cel $HH8 and K.!ls!L format i.e. I3 ased format
72, :ar
72, :ar supports all of these formats
72, is regularly updated and released ( The 4I3 documentation is not as comprehensive as that of 72, has a well prepared and highly $ 4I3 A7, was last updated in the year $HHG
#
4I3 :ar 72,
* 4I3 A7, doesn"t support rich te!t formatting + 4I3 A7, is faster than 72, A7,
72, :ar comprehensive documentation 72, A7, supports rich te!t formatting 72, A7, is slower than 4I3 A7,
Q #*8)What is the difference etween 'elenium and QT7? eature
'elenium 'elenium supports almost all the popular rowsers li;e irefo!0 5hrome0 'afari0 ,nternet !plorer0 2pera etc 'elenium is distriuted as an open source tool and is freely availale
Quic; Test 7rofessional QT7) QT7 supports ,nternet !plorer0 %rowser irefo! and 5hrome. QT7 only 5ompatiility supports Windows 2perating 'ystem QT7 is distriuted as a licensed tool 9istriution and is commerciali@ed QT7 supports testing of oth the we Application 'elenium supports testing of only we ased application and windows ased under Test ased applications application 2:ect 2:ect 6epository needs to e created QT7 automatically creates and 6epository as a separate entity maintains 2:ect 6epository 'elenium supports multiple 3anguage programming languages li;e 4ava0 5#0 QT7 supports only J% 'cript 'upport 6uy0 7ython0 7erl etc As 'elenium is a free tool0 user would sers can easily get the vendor"s Jendor 'upport not get the vendor"s support in support in case of any issue trouleshooting issues Q #*E) 5an We9river test oile applications? We9river cannot test oile applications. We9river is a we ased testing tool0 therefore applications on the moile rowsers can e tested. Q #*G) 5an captcha e automated? >o0 captcha and ar code reader cannot e automated. Q #+H) What is 2:ect 6epository? ow can we create 2:ect 6epository in 'elenium? 2:ect 6epository is a term used to refer to the collection of we elements elonging to Application nder Test AT) along with their locator values. Thus0 whenever the element is reuired within the script0 the locator value can e populated from the 2:ect 6epository. 2:ect 6epository is used to store locators in a centrali@ed location instead of hard coding them within the scripts.
,n 'elenium0 o:ects can e stored in an e!cel sheet which can e populated inside the script whenever reuired.
SELENIUM REAL TIME INTERVIEW QUESTIONS 1. Difference between Absolute path & Relative path.
Asolute path will start with root path /) and 6elative path will from current path //) 2. Tell me some TestNG Annotations.
NTest0N7arameters0N3isteners0N%efore'uite0NAfter'uite0N%eforeTest0NAfterTest0 N9ata7rovider0N%efore=roups0NAfter=roups0N%efore5lass0NAfter5lass0 N%eforeethod0NAfterethod0Nactory 3. What are esire capabilities!
9esired 5apailities help to set properties for the We 9river. A typical use case would e to set the path for the irefo! 9river if your local installation doesnBt correspond to the default settings. ". Difference between #elenium R$ an #eleniumWeb river.
'elenium 65 'elenium 65"s architecture is way more complicated.
'elenium We driver
We 9river"s architecture is simpler than 'elenium 65"s.
'elenium 65 is slower since it uses a 4ava'cript We 9river is faster than 'elenium 65 program called 'elenium 5ore. This 'elenium 5ore since it spea;s directly to the rowser uses is the one that directly controls the rowser0 not the rowser"s own engine to control it. you. 'elenium 5ore0 :ust li;e other 4ava'cript codes0 can We 9river interacts with page elements in access disaled elements. a more realistic way.
'elenium 65"s A7, is more matured ut contains redundancies and often confusing commands.
We 9river"s A7, is simpler than 'elenium 65"s. ,t does not contain redundant and confusing commands.
'elenium 65 cannot support the headless tmlnit We 9river can support the headless rowser. ,t needs a real0 visile rowser to operate tmlnit rowser. on. 'elenium 65 as %uiltC,n Test 6esult =enerator. We 9river has no uiltCin command that 'elenium 65 automatically generates an T3 file automatically generates a Test 6esults ile. of test results. 'elenium 65 needs the help of the 65 'erver in order to do so.
we 9river directly tal;s to the rowser
'elenium 65 can support new rowsers
,t cannot readily support new rowsers
%. Difference between Web river listener anTestNG istener.
Test>= and We driver 3istener have different interfaces to implement and call them. They oth modify respective ehaviour. Oou can use 3isteners in Annotation. %elow $ 63 gives the detailed list of listener and their interfaces. '. Describe (our framewor). *. Which is the best wa( to locate an element!
inding elements y ,9 is usually going to e the fastest option0 ecause at its root0 it eventually calls down to document.getlement%y,d)0 which is optimi@ed y many rowsers. inding elements y I7ath is useful for finding elements using ver y comple! selectors0 and is the most fle!ile selection strategy0 ut it has the potential to e very slow0 particularly in ,. ,n , -0 80 or E0 finding y I7ath can e an order of magnitude slower than doing the same in irefo!. , provides no native I7athCoverCT3 solution0 so the pro:ect must use a 4ava'cript I7ath implementation0 and the 4ava'cript engine in legacy versions of , really is that much slower. ,f you have a need to find an element using a comple! selector0 , usually recommend using 5'' 'electors0 if possile. ,tBs not uite as fle!ile as I7ath0 ut will cover many of the same cases0 without e!hiiting the e!treme performance penalty on , that I7ath can.
+. Wh( we refer ,irefo- river to the web riverinheritance.
we 9river driver P new ireo!9river)D We9river is an interface which contain several astract methods such as get...)0 findlament%y...) etc. We simply create reference of we 9river and we can assign o:ects irefo! driver0 5rome9river0 ,9river0 Andriod driver etc) to it. ! & We9river driver P new ireo!9river)DCCCCCCCCCCC1) ,f we are using 1) we can do the same thing y using ireo!9river driver P new ireo!9river)DCCCCCCCCC$) We can use 1) and $) for same purpose ut if we want to switch to another rowser in same program then again we have to create the o:ect of other class as for e!ample 5rome9river driver P new 5rome9river)D. creating o:ect of several class is not good. 'o we create the reference of We9river and we assign the o:ects of another class as for e!ample We9river driverD // it is created only one time in the program driver P new ireo!9river)D// any where in the program driver P new 5rome9river)D // any where in the program . What are the features of TestNG!
Test>= is a testing framewor; designed to simplify a road range of testing needs0 from unit testing testing a class in isolation of the others) to integration testing testing entire systems made of several classes0 several pac;ages and even several e!ternal framewor;s0 such as application servers). Oou can use test suite0annotations0 automatically generation of report and much more.
1/. What is the ifference between threa.#leep0an selenium. #et #pee 02///!
,f the application is ta;ing time to load the page then we use selenium.waitforpageload ). This command is doesn"t wait upto the given time whenever the page load is completed. ,f the application is ta;ing time to refresh the page0 then we use Thread. 'leep ).it is a standard wait it simply wait to the given time. selenium.set'peed 1. Ta;es a single argument in string format !& selenium.set'peed$HHH) C will wait for $ seconds $. 6uns each command in after set'peed delay y the numer of milliseconds mentioned in set 'peed. thread.sleep 1. Ta;es a single argument in integer format e!& thread. 'leep$HHH) C will wait for $ seconds $. Waits for only once at the command given at sleep. 11. n what situation selenium finin4 element 4et fails! •
Element loading issue
•
Dynamic id of e! element
12. What is the ifference between G5T an NA6GAT5 to open a web pa4e in selenium web river!
=et method will get a page to load or get page source or get te!t thatBs all whereas navigate will guide through the history li;e refresh0 ac;0 forward.or e!a mple if we want to move forward and do some functionality and ac; to the home page this can e achieved through navigate) only. driver.get will wait till the whole page gets loaded and driver.navigate will :ust redirect to that page and will not wait 13. 7lease tell me the ifference b8w implicitl( Wait an 5-plicit wait.
,mplicit Wait sets internally a timeout that will e used for all consecutive We lement searches. ,t will try loo;up the element again and again for the specified amount of time efore throwing a >o'uchlement!ception if the element could not have een found. ,t does only this and canBt e forced into anything else C it waits for elements to show up. !plicit Wait or :ust Wait is a oneCtimer used y you for a particular search. ,t is more e!tendile in the means that you can set it up to wait for any condition you might li;e. sually0 you can use some of the preuilt !pected 5onditions to wait for elements to ecome clic;ale0 visile0 invisile0 etc.0 or :ust write your own condition that suits your ne eds. 1". 9ow we can retrieve the (namicall( chan4in4 s! When we lo4in ,aceboo) the lo4in label:s i chan4es (namicall( thus resultin4 in failure.
We have a hierarchy of locators and aceoo; ,s dynamic in nature0so we are not ale to use id for identification for after that we have remaining 8 locatorBs for that &$. !path ).. (. name..*. css.. +. lin; te!t.. -. partiallin;te!t...8.tag name. so u can use any one for identifying it. ost proaly u can use !path or cssClocator and if there r tag then lin; te!t or partialClin; te!t. it depend on u . %ut we never use idBs in A:a! application ecause it"s not possile. 1%.What is the ifference between river.$lose0an river.;uit 0 metho!
5lose) C ,t is used to close the rowser or page currently which is having the focus. Quit) C ,t is used to shut down the we driver instance or destroy the we driver instance 5lose all the windows)
1'. 9ow to scroll web element!<
irefo!7rofile profilePnew irefo!7rofile)D profile.setnale>ativeventstrue)D We9river driverPnew irefo!9riverprofile)D driver.navigatehttp&//:ueryui.com/draggale/)D
Thread.sleep-HHH3)D Welement elementPdriver.findlement%y.!path//divRNidPBdraggaleBS))D Actions actnPnew Actionsdriver)D actn.dragAnd9rop%yelement0 +H0 +H).uild).perform)D 1*. What is the basic use of ,irefo- profiles an how can we use them usin4 selenium!
A profile in irefo! is a collection of oo;mar;s0 rowser settings0 e!tensions0 passwords0 and historyD in short0 all of your personal settings. We use them to change user agent0 changing default download directory0 changing versions etc. 1+. $ustomi>e the name of file 4oin4 to be ownloae!
Oou have to download AT2 ,T.e!e file and has to e install and later you have create .au( file in this file you have to specify the commands in J% script li;e your file name0 where have to save0 it will e easy may e ( or * steps ) using AT2,T...then right clic; the .au( file you have to compile ....after that you will get the .e!e file with the name of .au( file ..,n eclipse you will give the code li;e this UCCCC7rocess%uildderps P new 7rocess%uilderpath of the .e!e file of au() .start)DCCCV 1. 9ow to hanle internationalisation throu4hweb river!
irefo!7rofile profile P new irefo!7rofile)D profile.set 7referenceintl.acceptlanguages0:p)D We driver driver P new irefo!9riverprofile)D driver.getgoogle.com) will open google in 4apanese 3ang 2/. 9ow to overcome same ori4in polic( throu4h web river! •
" #$o%y se$&e$'
9esired5apailities capailityPnew 9esired5apailities.firefo!)D
capaility.set5apaility5apailityType.762IO0your desire pro!y) We9river driverPnew irefo!9rivercapaility)D 21. 9ow to put te-t in ,aceboo) search bo- usin4 selenium web river. •
" d$i&e$'(ndElement)*y'%+at,)-..di&/contains)0class1 23456i278-77'send9eys)-a!c-7:
22. Difference between fle- an flash application.
,n flash there is no code :ust ased on creativitydesign) we will complete the wor;time consuming process) whereas fle! contain some small functions which is integrated with m!ml077..no tool is there to develop fle! we want to use the properties of css and style sheet) 23. What is 5rror $ollector in TestNG! What is its use!
This class allows the collection of errors during the process of retrieving the test d ata for the test method parameters 2". 9ow can we 4et the font si>e? font color? font t(pe use for a particular te-t on a web pa4e usin4 #elenium web river!
driver.findelement%y.IpathIpath ).getcssvaluefontCsi@e)D driver.findelement%y.IpathIpath ).getcssvaluefontCcolour)D driver.findelement%y.IpathIpath ).getcssvaluefontCtype)D driver.findelement%y.IpathIpath ).getcssvalueac;groundCcolour)D
2%. 9ow to run tests in multiple browser parallel!s there an( other option other than selenium 4ri!
Oou create a class with a method something li;e this&
pulic class 3aunch%rowser X We9river driverPnullD
// 7ass parameter rowser from test.!ml N7arametersKrowserL) pulic void initiate%rowser'tring rowser)X // compare rowser to fire fo! and then open firefo! driver ifrowser.eualsKirefo!L)) X driver P new irefo!9river)D else X Y set path to the , driver correctly here 'ystem.set7ropertywedriver.ie.driver0 Yie!ploredriver.e!e)D driver Pnew ,nternet!plorer9river)D >ow create Oour5lass>ame class and call e!tend the aove class something li;e this NTest pulic class Oour5lass>ame e!tends 3aunch%rowserX pulic void goto=oogle)X
driver.getKhttp&//www.google.com)D $-. ow to prepare 5ustomi@ed html 6eport using Test>= in hyrid framewor;. %elow are the ( ways& Z 4unit& with the help of A>T.
Z Test>=& using inuilt default.html to get the T3 report. Also I'T reports from A>T0 'elenium0 Test>= comination. Z sing our own customi@ed reports using I'3 :ar for converting I3 content to T3. 2*. @Whats the hierarch( of TestNG annotations!
!plain me aout annotation hierarchy [ e!ecutionorder? ;' o$g'testng'annotations'#a$amete$s )im+lements ' o$g'testng'annotations'Test )im+lements 'o$g'testng'annotations'NoIn
;?'o$g'testng'annotations'Afte$Suite )im+lements
$E. ow the Test>= interacts with 'elenium 5ore? !plain me steps and internal architecture?
W,at is TestNBF 'o far we had een doing 'elenium tests without generating a proper format for the test results. rom this point on0 we shall tac;le how to ma;e these reports using a test framewor; called Test>=.
TestNB is a testing f$ameo$G t,at o&e$comes t,e limitations of anot,e$ +o+ula$ testing f$ameo$G called HUnit' T,e -NB- means -Ne%t Bene$ation-' Most Selenium use$s use t,is mo$e t,an HUnit !ecause of its ad&antages'
T,e$e a$e so many featu$es of TestNB1 !ut e ill only focus on t,e most im+o$tant ones t,at e can use in Selenium'Ad&antages of TestNB o&e$ HUnit There are three ma:or advantages of Test>= over 4nit& •
•
•
Annotations a$e easie$ to unde$stand Test cases can !e g$ou+ed mo$e easily #a$allel testing is +ossi!le
2. s it possible test web services usin4 selenium!
sing 4meter we can test how one wesite is tal;ing to each other means time ta;en to send data0 feeds0 messages from one wesite to other wesite. 4meter does a nice :o of douling for performance and api tests. 3/. 9ow to refresh a pa4e without usin4 conte-t clic)!
1.singsendMeys.Meys method $.singnavigate.refresh) method (.singnavigate.refresh) method *.sing get) method +.singsendMeys) method 1.singsendMeys.Meys method driver.gethttps&//accounts.google.com/'ignp)D driver.findlement%y.idfirstnameCplaceholder)).sendMeysMeys.+)D $.singnavigate.refresh) method driver.gethttp&//ruchiCmyseleniumlog.logspot.in/$H1(/1$/1HHCseleniumCinterviewC uestions.html)D driver.navigate).refresh)D (.sing navigate.to) method
driver.gethttp&//ruchiCmyseleniumlog.logspot.in/$H1*/H1/seleniumChyridCframewor;C using.html)D driver.navigate).todriver.get5urrentrl))D *.sing get) method driver.gethttp&//ruchiCmyseleniumlog.logspot.in/$H1(/1$/asicCcoreC:avaCinterviewC uestions.html)D driver.getdriver.get5urrentrl))D +.singsendMeys) method driver.gethttps&//accounts.google.com/'ignp)D driver.findlement%y.idfirstnameCplaceholder)).sendMeysYuH(+)D 31. $an u sen a coe for printin4 in selenium!
There are two cases& 5ase1. Any hyperlin;/utton on a we page0 n clic;ing that lin;/utton a print dialog o! opens. 7erforming an action on we page) 5ase$.or do u want to open print dialog o! within ur own script0 not y performing any action on we page. 'o ,f 5ase 1& :ust a call for Welement.clic;) event will wor; to open it. ,f 5ase $& 5all a 7rinter 4o o:ect se Awt A7,). or code& =oogle it. ($. ow to find ro;en images in a page using 'elenium We driver. 1. =et !path and then using tag nameD get all the lin;s in the page $. 5lic; on each and every lin; in the page (. ,n the target page title0 loo; for *H*/+HH error.
o to (nd !$oGen images in a +age using Selenium
pac;age programsD import :ava.util.3istD import org.apache.http.ttp6esponseD import org.apache.http.client.methods.ttp=etD import org.apache.http.impl.client.9efaultttp5lientD import org.opena.selenium.%yD import org.opena.selenium.We9riverD import org.opena.selenium.WelementD import org.opena.selenium.firefo!.irefo!9riverD pulic class findro;enimages X static intinvalidimgD static We9river driver D pulic static void main'tringRS args) X try X driver P new irefo!9river)D driver.gethttp&//ruchiCmyseleniumlog.logspot.in)D invalidimg P HD 3ist all,mages P driver.findlements%y.tag>ameimg))D 'ystem.out.printlnTotal images are \ all,mages.si@e))D for int i P HD i Uall,mages.si@e)D i\\) X Welementimg P Welement) all,mages.geti)D if img ]P null) X verifyimgActiveimg)D 'ystem.out.printlnTotal invalid images are \ invalidimg)D driver.uit)D catch !ception e) X e.print'tac;Trace)D 'ystem.out.printlne.getessage))D
pulic static void verifyimgActiveWelementimg) X
try X ttp6esponse response P new 9efaultttp5lient).e!ecutenew ttp=etimg.getAttriutesrc)))D if response.get'tatus3ine).get'tatus5ode) ]P $HH) invalidimg\\D catch !ception e) X e.print'tac;Trace)D 33. 9ow to hanle ABa- popup winow!
%y using getWindowandles) and o:.switchTo.windowwindowid) we can handle popups using e!plicit wait and driver.swtchTH.windowname) commands for your reuire ments. 3". 9ow to hanle auto complete bo- in web river!
o to ,andle autocom+lete !o% in e! d$i&e$
ow to handle autocomplete o! in we driver? driver.findlement%y.idyour search%o!)).sendMeysyour partial ;eyword)D Thread.sleep(HHH)D 3ist UWelementVlist,tems P driver.findlements%y.!pathyour list item locator))D list,tems.getH).clic;)D driver.findlement%y.idyour search%utton)).clic;)D
3%. 9ow to 4et the name of browser usin4 Web Driver!
pulic class 4s!ecute X We9river driverD 4avascript!ecutor:sD N%efore pulic void setp) throws !ception X driverPnew irefo!9river)D driver.gethttp&//www.google.com)D NTest pulic void test) X 4avascript!ecutor:s P 4avascript!ecutor) driverD 'ystem.out.println:s.e!ecute'criptreturn navigator.app5ode>ame))D 26 'tring s P 'tring) 4avascript!ecutor) driver).e!ecute'criptreturn navigator.userAgentD)D 'ystem.out.println%rowser name & \ s)D
3'. 9ow to hanle colors in web river!
se get5ssJalueargH) function to get the colors y sending BcolorB string as an argument. !ample 'tring col P driver.findlement%y.idlocator)).get5ssJaluecolor)D 3*. 9ow to pass parameters from testn4.-ml intotest case.
import org.opena.selenium.We9riverD import org.opena.selenium.chrome.5hrome9riverD import org.opena.selenium.firefo!.irefo!9riverD import org.opena.selenium.htmlunit.tmlnit9riverD import org.opena.selenium.ie.,nternet!plorer9riverD import org.testng.annotations.%eforeTestD import org.testng.annotations.7arametersD import org.testng.annotations.TestD pulic class 7arallele!ecution X private We9river driver P nullD N%eforeTest N7arametersX %62W'6 ) pulic void setup'tring %62W'6) X 'ystem.out.println%rowser& \ %62W'6)D if %62W'6.euals)) X 'ystem.out.printlnirefo! %rowser is selected)D driver P new irefo!9river)D else if %62W'6.euals,)) X 'ystem.out.println,nternet !plorer %rowser is selected)D driver P new ,nternet!plorer9river)D else if %62W'6.euals)) X 'ystem.out.printlntml nit %rowser is selected)D
driver P new tmlnit9river)D else if %62W'6.euals5)) X 'ystem.out.println=oogle chrome %rowser is selected)D driver P new 5hrome9river)D NTest pulic void test7arallel) throws !ception X driver.gethttp&//ruchiCmyseleniumlog.logspot.in/$H1(/1$/1HHCseleniumCinterviewC uestions.html)D 3+. 9ow to 4et te-t from captcha ima4e!!
driver.findlement%y.!path.//^RNidPB';ip5aptchaBS)).clic;)D 'tring attr P ie.findlement%y.!path.//^RNidPB';ip5aptchaBS)).getAttriutevalue)D 'ystem.out.printlnThe value of the attriute B>ameB is \ attr)D (G. ,s there a way to clic; hidden 3,>M in we driver? 'tring %loc;1 P driver.findlement%y.idelement ,9))D 4avascript!ecutor :s1P4avascript!ecutor)driverD :s1.e!ecute'cript_\%loc;1\).cssXBdisplayB&Bloc;B)D)D "/. What $lass 5-tens Web Driver! •
" And$oidD$i&e$1 ,$omeD$i&e$1 E&enti$ingWe!D$i&e$1 i$efo%D$i&e$1 tmlUnitD$i&e$1 Inte$netE%+lo$e$D$i&e$1 I#,oneD$i&e$1 #,antomHSD$i&e$1 RemoteWe!D$i&e$1 Safa$iD$i&e$
"1. What are the A7s that support Web Driver! •
" A#I a$e not,ing !ut collection of all selenium commands fo$ Locating UI Elements )We!Elements71etc,ing a #age1Use$ In+ut etcJ
"2. 9ow to isable coo)ies in browser. •
" Using deleteAllVisi!leooGies)7 in selenium
"3. We have hear about framewor)s well it can bebroal( classifie into these TDD? CDD an ATDD framewor)s .Whats the Difference!
TDDK Test D$i&en De&elo+ment1 *e,a&iou$ D$i&en De&elo+ment Acce+tance TestD$i&en De&elo+ment
Well0 you could see the aove Acronyms u@@ing over all Automation fol;s. , was not sure on what it means and ow it differs each other. ow each methodology will enefit? and where e!actly it will help in the 9evelopment 3ife cycle. inally0 after some analysis , had found out the differences and posting it here. 6eaders are always welcomed to correct me if , am wrong. First lets list out what exatl! eah methodolo%! does means TDD Test D$i&en De&elo+ment
,ts also called testCdriven design0 is a method of software development in which unit testing is repeatedly done on source code. Write your tests watch it fails and then refactor it. The concept is we write these tests to chec; if the code we wrote wor;s fine. After each test0 refactoring is done and then the same or a similar test is performed again. The process is iterated as many times as necessary until each unit is functionally wor;ing as e!pected. T99 was introduced first y I7. , elieve , have e!plained enough in simple terms. *DD *e,a&iou$ D$i&en De&elo+ment
%ehaviorCdriven development comines the general techniues and principles of T99 with ideas from domainCdriven design DDD?Domain Driven +estin% %99 is similar in many ways to T99 e!cept that the word KtestL is replaced with the word K%ehaviourL. ,t"s purpose is to help the the fol;s devising the system i.e.0 the developer) identify appropriate tests to write W> [ T>.
"". 9ow to chan4e user a4ent in ,irefo- b( seleniumweb river.
irefo!7rofile profile P new irefo!7rofile)D profile.set7referencegeneral.useragent.override0 some A string)D We 9river driver P new irefo!9riverprofile)D "%. What is #elenese!
'elenese is T3 language ased command0 which is used in 'elenium ,9. "'. Differences between ;T7 an selenium.
1) 'elenium generates a pro!y while starting rowser. QT7 does not $) QT7 uses only J script. 'elenium is availale in many languages () QT7 is paid and selenium is free. *) Oou can run script from a particular line in QT7 ut in selenium0 you cannot. +) 'elenium wor;s on all rowsers. QT7 only wor;s on ,0 mo@illa. 'upport from chrome has een introduced lately. -) QT7 is more organi@ed and user friendly 8) 'elenium reuires more technical s;ills E) QT7 can also e used on des;top ased applications ut selenium cannot e used "*. What is the E#T challen4in4 test problem in m( career in Automation!
,n my career •
" ,anging #ATS2 !eteen testing se$&e$ and +$oduction se$&e$K!y Gee+ing gene$ic %+at,
•
" 9ee+ se+a$ate +$o+e$ty (les fo$ +$oduction and UAT
•
" automating as, a++s
•
" Mo!ile Automation
"+. @#uppose eveloper chan4e the e-istin4 ima4e to new ima4e with same -path. s test case pass or fail! •
" #ass
". 9ow to hanle networ) latenc( usin4 selenium! •
" Using d$i&e$'manage'+ageLoadingtime fo$ neto$G latency
%/. 9ow oes u hanle (namic elements without usin4-path 0with e-ample! •
" *y using classname o$ css'
%1. What are the ifferent t(pes of river implementation! •
" And$oidD$i&e$1 And$oidWe!D$i&e$1 ,$omeD$i&e$1 E&enti$ingWe!D$i&e$1 i$efo%D$i&e$1 tmlUnitD$i&e$1 Inte$netE%+lo$e$D$i&e$1 I#,oneD$i&e$1 I#,oneSimulato$D$i&e$1 RemoteWe!D$i&e$1 Safa$iD$i&e$1 We!D$i&e$*acGedSelenium
%2. $oe for Epenin4 ,irefo- browser! •
" We!d$i&e$ d$i&e$Pne i$eo%d$i&e$)7:
%3. Which repositor( (ou have use to store the testscripts!
, have created scripts in e!cel file and store them in Test cases folder under src . %". 9ow to wor) with raio button in web river!
We can select the value from the drop down y using ( methods. select%yJisileTe!t C select y the te!t displayed in drop down select%y,nde! C select y inde! of option in drop down select%yJalue C select y value of option in drop down Uselect idP**VUoption valueP1V!y@U/optionV Uoption valueP$VacU/optionV
Uoption valueP(VprU/optionV U/selectV Welement e P driver.findlement%y.id**))D 'elect selectlementPnew 'electe)D // oth of the elow statements will select first option in the welist selectlement.select%yJisileTe!t!y@)D selectlement.select%yJalue1)D %%. 9ow to wor) with (namic web table!
Oou can get the total numer of UtrV tags within a UtdV tag y giving the !path of the UtdV element y using this function C 3istUWelementVele P driver.findlements%y.!pathIpath of the tale))D >ow you can use a for each loop to loop through each of the UtrV tags in the aove list and then read each value y using getTe!t) method. %'. Detail about TestNG Test Eutput foler.
,t is the directory where reports are generated. very time tests run in a suite0 Test>= creates inde!.html and other files in the output directory. %*. n frame if no frame as well as no framename then which attribute shoul consier throu4hout our script.
Oou can go li;e this.....driver.findlements%y.!path//iframe))... Then it will return 3ist of frames then switch to each and every frame and search for the locator which you want then rea; the loop %+. What is obBect repositor(!
,t is collection of o:ect names their properties0 attriutes and their values .,t maye e e!cel0 I30property file or te!t file %. TestNG vs. Funit!
Advantages of Test>= over 4unit ,n 4unit we have to declare N%efore5lass and NAfter5lass which is a constraint where as in Test>= there is no constraint li;e this. •
Additional 3evels of setp/tear9own level are availale in Test>= li;e N%efore/After'uite0N%efore/AfterTest and N%efore/After=roup •
>o >eed to e!tend any class in Test>=.
•
There is no method name constraint in Test>= as in 4unit. Oou can give any name to the test methods in Test>= •
,n Test>= we can tell the test that one method is dependent on another method where as in 4unit this is not possile. ,n 4unit each test is independent of another test. •
=rouping of testcases is availale in Test>=where as the same is not availale in 4unit.
•
!ecution can e done ased on =roups. or e!. ,f you have defined many cases and segregated them y defining $ groups as 'anity and 6egression. Then if you only want to e!ecute the K'anityL cases then :ust tell Test>= to e!ecute the K'anityL and Test>= will automatically e!ecute the cases elonging to the K'anityL group. •
Also using Test>= your selenium test case e!ecution can e done in parallel.
•
'/. What is the ifference between before metho an beforeclass.
,n 4nit* N%efore is used to e!ecute set of preconditions efore e!ecuting a test. or e!ample0 if there is a need to open some application and create a user efore e!ecuting a test0 then this annotation can e used for that method. ethod that is mar;ed with N%efore will e e!ecuted efore e!ecuting every test in the class. ,f a 4nit test case class contains lot of tests which all together nee d a method which sets up a precondition and that needs to e e!ecuted efore e!ecuting the Test 5ase class then we can utilise KN%efore5lassL annotation. '1. What are the ifferent 7arameters for Testannotation!
7arameters are ;eywords that modify the annotation"s function. '2. $an we run 4roup of test cases usin4 TestNG!
Test cases in group in 'elenium using Test>= will e e!ecuted with the elow options. ,f you want to e!ecute the test cases ased on one of the group li;e regression test or smo;e test NTestgroups P Xregressiontest0 smo;etest) '3. Differences between #elenium web river? D5 an R$! '". 9ow to hi4hli4ht an obBect li)e Htp8uft oes throu4h selenium an Bava!
pulic void highlightlementWe9river driver0 Welement element) X for int i P HD i U $D i\\) X 4avascript!ecutor:s P 4avascript!ecutor) driverD :s.e!ecute'criptargumentsRHS.setAttriuteBstyleB0 argumentsR1S)D0 element0 color& yellowD order& $p! solid yellowD)D :s.e!ecute'criptargumentsRHS.setAttriuteBstyleB0 argumentsR1S)D0 element0 )D 5all the highlightlement method and pass wedriver and Welement which you want to highlight as arguments. '%. What are the ifferent assertions in #D5!
Assertions are li;e Accessors0 ut they verify that the state of the application conforms to what is e!pected. !amples include ma;e sure the page title is I and verify that this chec;o! is chec;ed. All 'elenium Assertions can e used in ( modes& assert0 verify0 and waitor. or e!ample0 you can assertTe!t0 verifyTe!t and waitorTe!t. When an assert fails0 the test is aorted. When a verify fails0 the test will continue e!ecution0 logging the failure. This allows a single assert to ensure that the application is o n the correct page0 followed y a unch of verify assertions to test form field values0 laels0 etc. waitor commands wait for some condition to ecome true which can e useful for testing
A:a! applications). They will succeed immediately if the condition is already true. owever0 they will fail and halt the test if the condition does not ecome true within the current timeout setting see the setTimeout action elow). ''. 9ow to store a value which is te-t bo- usin4 web river!
driver.findlement%y.idyour Te!to!)).sendMeysyour ;eyword)D '*. 9ow to hanle alerts an confirmation bo-es.
5onfirmation o!es and Alerts are handled in same way in selenium. var alert P driver.switchTo).alert)D alert.dismiss)D //5lic; 5ancel or 5lose window operation alert.accept)D //5lic; 2M andle 5onfirmation o!es via 4ava'cript0 driver.e!ecute'criptwindow.confirm P functionmessage)Xreturn trueDD)D '+. 9ow to mouse hover on an element!
Actions action P new Actionswedriver)D Welement we P wedriver.findlement%y.!pathhtml/ody/divR1(S/ul/liR*S/a))D action.moveTolementwe).moveTolementwedriver.findlement%y.!path/e!pressionC here))).clic;).uild).perform)D '. 9ow to switch between the winows!
private void handlingultipleWindows'tring windowTitle) X 'etU'tringV windows P driver.getWindowandles)D for 'tring window & windows) X driver.switchTo).windowwindow)D if driver.getTitle).containswindowTitle)) X returnD
*/. 9ow to switch between frames!
We9riverBsdriver.switchTo).frame) method ta;es one of the three possile arguments& A numer.
•
'elect a frame y its @eroCased) inde!. That is0 if a page has three frames0 the first frame would e at inde! H0 the second at inde! 1 and the third at inde! $. 2nce the frame has een selected0 all suseuent calls on the We9river interface are made to that frame. A name or ,9.
•
'elect a frame y its name or ,9. rames located y matching name attriutes are always given precedence over those matched y ,9. A previously found Welement.
•
'elect a frame using its previously located Welement. =et the frame y itBs id/name or locate it y driver.findlement) and youBll e good. *1. What is actions class in web river!
Actions class with we 9river help is 'liding element0 6esi@ing an lement0 9rag [ 9rop0 hovering a mouse0 especially in a case when dealing with mouse over menus. 9ragging [ 9ropping an lement& importorg.opena.selenium.%yD importorg.opena.selenium.We9riverD importorg.opena.selenium.WelementD importorg.opena.selenium.firefo!.irefo!9riverD importorg.opena.selenium.interactions.ActionsD pulic class test9ragand9rop X pulic static void main'tringRS args) throws ,nterrupted!ception X
We9river driver P new irefo!9river)D driver.gethttp&//:ueryui.com/resources/demos/droppale/default.html)D Welementdraggale P driver.findlement%y.!path//^RNidPBdraggaleBS))D Welement droppale P driver.findlement%y.!path//^RNidPBdroppaleBS))D Actions action P new Actionsdriver)D action.dragAnd9ropdraggale0 droppale).perform)D 'liding an lement& importorg.opena.selenium.%yD importorg.opena.selenium.We9riverD importorg.opena.selenium.WelementD importorg.opena.selenium.firefo!.irefo!9riverD importorg.opena.selenium.interactions.ActionsD pulic class test'lider X /^^ ^ Nparamargs ^ Nthrows ,nterrupted!ception ^/ pulic static void main'tringRS args) throws ,nterrupted!ception X We9river driver P new irefo!9river)D driver.gethttp&//:ueryui.com/resources/demos/slider/default.html)D
Welement slider P driver.findlement%y.!path//^RNidPBsliderBS/a))D Actions action P new Actionsdriver)D Thread.sleep(HHH)D action.dragAnd9rop%yslider0 GH0 H).perform)D 6eCsi@ing an lement& importorg.opena.selenium.%yD importorg.opena.selenium.We9riverD importorg.opena.selenium.WelementD importorg.opena.selenium.firefo!.irefo!9riverD importorg.opena.selenium.interactions.ActionsD pulic class test6esi@ale X pulic static void main'tringRS args) throws ,nterrupted!ception X We9river driver P new irefo!9river)D driver.gethttp&//:ueryui.com/resources/demos/resi@ale/default.html)D Welement resi@e P driver.findlement%y.!path//^RNidPBresi@aleBS/divR(S))D Actions action P new Actionsdriver)D action.dragAnd9rop%yresi@e0 *HH0 $HH).perform)D *2. Difference between the selenium1./ an selenium 2./!
'elenium 1 P 'elenium 6emote 5ontrol. 'elenium $ P 'elenium We driver0 which comines elements of 'elenium 1 and We driver. 8(. 9ifference etween find element ) and findelements )? findlement) & ind the first element within the current page using the given locating mechanism. 6eturns a single Welement. findlements) & ind all elements within the current page using the given locating mechanism. 6eturns 3ist of We lements. *". 9ow to ta)e the screen shots in seelnium2./!
// store screenshots pulic static void capture'creen'hot'tring file7ath) X ile scrile P Ta;es'creenshot)driver).get'creenshotAs2utputType.,3)D try X iletils.copyilescrile0 new ilefile7ath))D catch ,2!ception e) X // T292 AutoCgenerated catch loc; e.print'tac;Trace)D *%. What is the efault time for selenium e an webriver!
9efault timeout in selenium ide is (H seconds. *'. Write own scenarios which we can:t automate!
%arcode 6eader0 5aptcha etc.
**. n TestNG have some test:s Test1
" Use +$io$ity +a$amete$ in 0test annotation o$ TestNB annotations'
*+. Differences between B-l an Apache7E. •
" <%l does not su++o$t LS (les
•
" <%l e%e$ts less load on memo$y as com+a$ed to A+ac,e#OI
•
" <%l doesn2t su++o$t $ic, te%t fo$matting ,ile A+ac,e#OI does'
•
" <%l ,as not !een maintained +$o+e$ly ,ile A+ac,e#OI is mo$e u+ to date'
•
" Sam+le code on A+ac,e #OI is easily a&aila!le as com+a$e to <%l'
*. 9ow to I7 files in #elenium with an 5-ample!
// 'ample unction to ma;e @ip of reports pulic static void @ip'tring filepath)X try X ile inputolderPnew ileBention file path her)D ile outputolderPnew ile6eports.@ip)D `ip2utput'tream out P new `ip2utput'treamnew %uffered2utput'treamnew ile2utput'treamoutputolder)))D %uffered,nput'tream in P nullD yteRS data P new yteR1HHHSD 'tring filesRS P inputolder.list)D for int :PHD :Ufiles.lengthD i\\) X in P new %uffered,nput'treamnew ile,nput'tream inputolder.get7ath) \ / \ filesR:S)0 1HHH)D out.put>e!tntrynew `ipntryfilesR:S))D inttotalcountD whiletotalcountP in.readdata0H01HHH)) ]P C1) X out.writedata0 H0 totalcount)D out.closentry)D
out.flush)D out.close)D catch!ception e) X e.print'tac;Trace)D return ail C \ e.getessage)D +/. What is efault port no!
****
+1. f Default port no is bus( how to chan4e port no!
We can use any port numer which is valid.. irst create an o:ect to remote control configuration. se Bset7ortB method and provide valid port numer*+*+0++++0+-++0 etc).. There after attach this remote control configuration o:ect to selenium server..i.e 6emote5ontrol5onfiguration rP new 6emote5ontrol5onfiguration)D r.set7ort*+-8)D 'elenium'erver sP new 'elenium'erverr)D +2. Does #elenium support https protocols!
Oes +3. aBorl( as)e test scenario with framewor) in nterviews!
a:orly as;ed are&
3ogin for =mail scenario =oggle search and finding no of results 9ownloading a file and save it 5hec;ing mails and deleting them 9o shopping in flip;art.com +". #elenium support mobile applications!
>o0 it is rowser automation tool0 it only automates Wesites opening in moile rowser0 and moile A77s canBt e automated. E+. What is wraps 9river? or casting selenium instance to selenium$ wedriver).wraps driver is used. or more details. +'. $an (ou e-plain Funit Annotation! f there are 1/// test cases. %// test cases are e-ecute. 9owwill (ou e-ecute the rest of the test cases b( usin4 annotation!
The annotations generated with 4nit * tests in 'elenium are& 1. N%efore pulic void method) C Will perform the method) efore each test. This method can prepare the test $. NTest pulic void method) C Annotation NTest identifies that this method is a test method.environment0e.g. read input data0 initiali@e the class) (. NAfter pulic void method) C Test method must start with testN%efore C this annotation is used for e!ecuting a method efore +*. Difference between assert an verif( in seleniumweb river. •
" W,en an asse$t fails1 t,e test ill !e a!o$ted' Asse$t is !est used ,en t,e c,ecG &alue ,as to +ass fo$ t,e test to !e a!le to continue to $un log in'
•
" W,e$e if a &e$ify fails1 t,e test ill continue e%ecuting and logging t,e failu$e' Ve$ify is !est used to c,ecG non c$itical t,ings' LiGe t,e +$esence of a ,eadline element'
++. want to fin the location of b in the belowcoe? how can fin out without usin4 -path? name?i? csslocator? ine-.JivK
U%uttonVaU/uttonV U%uttonVU/uttonV U%uttonVcU/uttonV U/divV driver.findlement%y.!path//^Rcontainste!t)0BB)S)).clic;)D or
•
//div/uttonRcontainste!t)0BBS
•
•
"
+. 9ow to o Applet testin4 usin4 selenium!
.. selenium setu+ selenium P ne DefaultHa&aSelenium)-local,ost-1????1 !$ose$St$ing 1 u$l7: selenium'sta$t)7: selenium'o+en)u$l7: .. get t,e a++let(%u$e to cont$ol fest HA++leti%tu$e A++leti%tu$e dialog P selenium'a++let)LIST3A##LET3ID7 .. fest simila$ A#I fo$ autmation testing dialog'com!o*o%)-domain-7'select)-Use$s-7: dialog'te%t*o%)-use$name-7'ente$Te%t)-ale%'$ui-7: dialog'!utton)-oG-7'clicG)7: /. Name % ifferent e-ceptions (ou ha in selenium web river an mention what instance (ou 4ot it an how o (ou resolve it! •
" We!D$i&e$E%ce+tion
•
" NoAle$t#$esentE%ce+tion
•
" NoSuc,WindoE%ce+tion
•
" NoSuc,ElementE%ce+tion
•
" TimeoutE%ce+tion
1. 9ow o (ou mana4e the coe versions in (our proBect! •
" Using SVN o$ ot,e$ &e$sioning tools
2. atest version of ,irefo- an selenium in mar)et an the version on which (ou are testin4which (ou are testin4. •
•
" Latest &e$sion till Dec1=C;> fo$ indos@16? !it =6'C'I use =4'C'; )u$ ans' may die$7 " Selenium e! d$i&e$ latest &e$sion till dec1=C;>K ='>'C I use selenium ='>@ see latest at
3. 9ow to )now all the methos supporte in web river an its s(nta-. •
" In O$g'o+ena'selenium +acGage1 e! d$i&e$ inte$face ,as all t,e main met,ods t,at can
e used in 'elenium We driver •
"
". 9ow o (ou create html test report from (our test script!
Z , would see elow ( ways& Z 4unit& with the help of A>T. Z Test>=& using inuilt default.html to get the T3 report. Also I3'T reports from A>T0 'elenium0 Test>= comination. Z sing our own customi@ed reports using I'3 :ar for converting I3 content to T3. %. ist the browsers? E# supporte b( the #eleniumWinows inu- ac
, O >A >A O OO 'afari O > O 2pera O OO 5hrome O OO '. $an (ou e-plain #elenium obile Automation!
im+o$t