Hello everyone

You can learn the selenium in simple and easiest way within few days and can be a master in Selenium.

In this blog each and every aspects of Selenium is being described in detail along with screenshots and for sure this will be a good tutorial for the beginners and for those who would like to learn the selenium in short period.

You can learn much about Selenium, Selenium IDE and WebDriver by navigating to an appropriate pages. I have included all the commands that we will use in Selenium IDE and in WebDriver.

For interview purpose please go through the “Interview FAQ” where the list of question has been include along with their answers. For more questions please leave a comment or follow by an email so that I can get in touch with you…

If any suggestions please leave a comment for any changes or updates that needs to be done on this blog.

Have a nice day and start learning Selenium now…

Tuesday, January 27, 2015

On 1:10 AM by Unknown   No comments
Answer 1Selenium is a browser automation tool which lets you automated operations like – type, click, and selection from a drop down of a web page.

Answer 2: Selenium is a library which is available in a gamut of languages i.e. java, C#, python, ruby, php etc. while most commercial tools are limited in their capabilities of being able to use just one language. More over many of those tools have their own proprietary language which is of little use outside the domain of those tools. Most commercial tools focus on record and replay while Selenium emphasis on using Selenium IDE (Selenium record and replay) tool only to get acquainted with Selenium working and then move on to more mature Selenium libraries like Remote control (Selenium 1.0) and Web Driver (Selenium 2.0).

Wednesday, November 19, 2014

On 1:03 AM by Unknown   No comments
Answer 11Selenium IDE can be opened either in side bar (View > Side bar > Selenium IDE) or as a pop up window (Tools > Selenium IDE). While using Selenium IDE in browser side bar it cannot record user operations in a pop up window opened by application.

Answer 12Selenium IDE provides a slider with Slow and Fast pointers to control the speed of execution.

Answer 13Result of test execution can be viewed in log window in Selenium IDE


Answer 14Commands of description can be seen in Reference section

On 1:03 AM by Unknown   No comments
Answer 15Yes, you can first record individual test cases and then group all of them in a test suite. Following this entire test suite could be executed instead of executing individual tests.

Answer 16There are largely three types of verification points available with Selenium –
  • Check for page title
  • Check for certain text
  • Check for certain element (text box, drop down, table etc.)


Answer17

Verification: A verification check lets test execution continue even in the wake of failure with check.

Assertion: Assertion stops the test execution once the failure is obtained and would not continue further.


Consider an example of checking text on page, you may like to use verification point and let test execution continue even if text is not present. But for a login page, you would like to add assertion for presence of text box login as it does not make sense continuing with test execution if login text box is not present.

On 1:03 AM by Unknown   No comments
Answer 18You need to use context menu to add check points to your Selenium IDE tests

Answer 19There are two ways to edit tests in Selenium IDE: One is the table view while other looking into the source code of recorded commands.

Answer 20There are three entities associated with a command –
  • Name of Command
  • Element Locator (also known as Target)
  • Value (required when using echo, wait etc.)

On 1:03 AM by Unknown   No comments
Answer 21This entirely boils down to operations you are carrying out with Selenium. Though you would definitely be using following Selenium Commands more often –

  • Open: opens a web page.
  • click/clickAndWait: click on an element and waits for a new page to load.
  • Select: Selects a value from a drop down value.
  • verifyTitle/assertTitle: verifies/asserts page title.
  • verify/assert ElementPresent: verifies/asserts presence of element, in the page.
  • verify/assert TextPresent: verifies/asserts  expected text is somewhere on the page.


Answer 22Html id and name can be used as it is in selenium IDE.

For example Google search box has name – “q” and id – “list-b” and they can be used as target in selenium IDE

Answer 23XPath is a way to navigate in xml document and this can be used to identify elements in a web page. You may have to use XPath when there is no name/id associated with element on page or only partial part of name/id is constant.
  • Direct child is denoted with - / 
  • Relative child is denoted with - // 
  • Id, class, names can also be used with XPath –
    •  //input[@name=’q’]
    • //input[@id=’lst-ib’]
    • //input[@class=’ lst’]


If only part of id/name/class is constant than “contains” can be used as –
  • //input[contains(@id,'lst-ib')]

On 1:03 AM by Unknown   No comments
Answer 24CSS location strategy can be used with Selenium to locate elements, it works using cascade style sheet location methods in which -

Direct child is denoted with – (a space)
Relative child is denoted with - > Id, class, names can also be used with XPath –
  • css=input[name=’q’]
  • css=input[id=’lst-ib’] or input#lst-ib
  • css=input[class=’ lst’] or input.lst 

If only part of id/name/class is constant than “contains” can be used as –
  • css=input[id*=' lst-ib ')]

Element location strategy using inner text
  • css = a:contains(‘log out’)


Answer 25If there is constant name/id available then you should use instead of XPath and CSS locators. If not then CSS locators should be given preference as their evaluation is faster than XPath in most modern browsers.

Answer 26This can be achieved by executing java script in Selenium. Java script can be executed using following syntax –

Type(Command)             css=input#s (Target)           javascript{Math.random()}(value)
And for date –
Type (Command)             css=input#s(Target)             javascript{new Date()}(value)



On 1:03 AM by Unknown   No comments
Answer 27You can use “store” command to achieve this. You can save result of an evaluation in a variable and use it later in your Selenium IDE script.

For example we can store value from a text box as following, and later use it to type it in another text box –

            storeText (Command)           css=input#s (Target)           var1(value)

             Type (Command)            css=input#d (Target)            ${var1} (value)

Answer 28You can use echo command as following to check the stored value in Selenium IDE –

           storeText (Command)           css=input#s (Target)           var1(value)

            echo (Command)                                                          ${var1}(value)

Answer 29You could use verify/assertAlert to check presence of alert on page. Since selenium cannot click on “Ok” button on JS alert window, the alert itself does not appear on page when this check is carried out.

On 1:02 AM by Unknown   No comments
Answer 30You can use drop down available next to Find in Selenium to change element locator used by Selenium –

Answer 31You can use Find button of Selenium IDE to test your locator. Once you click on it, you would see element being highlighted on screen provided your element locator is right else one error message would be displayed in log window.

Answer 32You could specify you JS extension in “Options” window of Selenium IDE.


Answer 33You could use Format option of Selenium IDE to convert tests in another programming language.

On 1:02 AM by Unknown   No comments
Answer 34This is because Selenium IDE does not support execution of test in any other language than Selenese (language of Selenium IDE). You can convert Selenium IDE in a language of your choice and then use Selenium 1.0 to execute these tests in that language.

Answer 35You can execute your Selenese test in another browser by specifying the “-htmlSuite” followed by path of your Selenese suite while starting the Selenium Server.
  
Answer 36You can double click on newly added command and Selenium IDE would execute only that command in browser.


Answer 37You could set a command as “start” command from context menu. When a command is set as start command then a small green symbol appears before command. Same context menu can be used to toggle this option.

On 1:02 AM by Unknown   No comments
Answer 38You could XPath checker - https://addons.mozilla.org/en-US/firefox/addon/xpath-checker/  to test you XPath locators and Firefinder (a firebug add on) to test you css locators – https://addons.mozilla.org/en-US/firefox/addon/firefinder-for-firebug/

Firefinder can also be used to test XPath locators.

Answer 39The latest advancement in Selenium IDE would be to have capabilities of converting Selenium IDE tests in Webdriver (Selenium 2.0) options. This would help generating quick and dirty tests for Selenium 2.0


Answer 40Selenese does not provide support for looping, but there is extension which could be used to achieve same. This extension can be downloaded and has to be added under “Selenium IDE User-Extension” section to use loop feature in Selenium IDE.

On 1:02 AM by Unknown   No comments
Answer 41You would need to use clickAt command to achieve. ClickAt command accepts element locator and x, y coordinates as arguments

ClickAt (locator, (coordStrings like...) “X, Y”)

Ex: clickAt (Command)    css=#gb_2 > span.gbts(Target)           10,10 (Value) -----  IDE

ClickAt ("//li[@id='tab-panel-id__second-tab-id']/a[2]/em/span/span","0,0") ---- Java code

Answer 42Use assertSelectOptions as following to check options in a drop down list – assertSelectOptions

Answer 43Use storeTable command to get data from a specific cell in an html table.

Following example store text from cell 0,4 from an html table –

storeTable (Command)             css=#tableId.0.4(Target)            textFromCell(Value)

On 1:02 AM by Unknown   No comments
Answer 44You can change default behavior of Selenium IDE > element locator preference by crating JS file with following–

LocatorBuilders.order = ['css:name', 'css:id', 'id', 'link', 'name', 'xpath:attributes']; 

And add the file under “Selenium IDE Extension” under Selenium Options.

Answer 45If you want to simulate clicking “ok “ on alert than use – chooseOkOnNextConfirmation and if you want to simulate clicking “cancel” on alert than use - 
chooseCancelOnNextConfirmation ( )

Answer 46You can use command - contextMenu (locator) to simulate right click on an element in web page.


Answer 47Use command – captureEntirePageScreenshot to take screen shot of page.

On 1:02 AM by Unknown   No comments
Answer 48Use pause command which takes time in milliseconds and would pause test execution for specified time –  
pause ( waitTime )

Answer 49This happens because open commands waits for only 30 seconds for page to load.
          If your application takes more than 30 sec then you can use “setTimeout (timeout)” to make selenium IDE wait for specified time, before proceeding with test execution.


Answer 50: Type command simulates enter operations at one go while TypeKeys simulates keystroke key by key.

TypeKeys could be used when typing data in text box which bring options (like Google suggestion list) because such operations are not usually simulated using type command.

On 1:02 AM by Unknown   No comments
Answer 51Selenium RC is an offering from SeleniumHQ which tries to overcome following draw backs of Selenium IDE –
  • Able to execute tests only with Firefox
  • Not able to use full-fledged programming language and being limited to Selenese

Answer 52Selenium RC has two primary components – 
  • Client libraries which let you writes tests in language of your preference i.e. java, C#, perl, php etc.
  • Selenium sever which acts as a proxy between browser and application under test (AUT)


Answer 53Selenium uses java script to drives tests on a browser; Selenium injects its own JS to the response which is returned from AUT. But there is a java script security restriction (same origin policy) which lets you modify html of page using JS only, if JS also originates from the same domain as html. This security restriction is of utmost important but spoils the working of Selenium. This is where Selenium server comes to play an important role.


Selenium server stands between AUT and browser and injects selenium JS to the response received from AUT and then it is delivered to browser. Hence browser believes that entire response was delivered from AUT.

On 1:01 AM by Unknown   No comments
Answer 54Selenium core is the core JS engine of Selenium which executes tests on browser, but because of same origin policy it needs to be deployed on app server itself, which is not always feasible. Hence Selenium core is not used in isolation. Selenium IDE as well as Selenium RC use Selenium core to drive tests while overcoming same origin policy. In case of Selenium IDE tests are run in context of browser hence it is not hindered by same origin policy and with Selenium RC, Selenium Server over comes same origin policy.

Answer 55Installation is a misnomer for Selenium RC. You don’t install Selenium RC you only add client libraries to your project.

For example in case of java you add client driver and Selenium server jars in Eclipse or IntelliJ which are java editors.

Answer 56To start Selenium Server, you need to navigate to installation directory of Selenium server and execute following command –   
java -jar selenium-server.jar (This will start Selenium server at port 4444 by default).

Notice that you need to have java version 1.5 or higher available on your system to be able to use Selenium server.

On 1:01 AM by Unknown   No comments
Answer 57You can specify port while running the selenium server as –   
java -jar selenium-server.jar –port 5555

Answer 58You can first record tests in Selenium IDE and then use format option to convert them in a language of your choice.

Answer 59If you are using java then you can start Selenium server using SeleniumServer class.

For this you need to instantiate SeleniumServer and then call start () method on it.

RemoteControlConfiguration rc; 
rc = new RemoteControlConfiguration(); 
rc.setPort(4445); 
SeleniumServer seleniumserver=new SeleniumServer(rc); 
seleniumserver.boot(); 
seleniumserver.start(); 
seleniumserver.getPort();

On 1:01 AM by Unknown   No comments
Answer 60While using java you need to create instance of DefaultSelenium class and pass it four parameters –

     selenium = new DefaultSelenium(serverHost, serverPort, browser, appURL); 
     selenium.start();

Herein you need to pass:
  • Host -- where Selenium server is running
  • Port -- of Selenium server
  • Browser -- where tests are to be executed and
  • application URL
Example: 
selenium=new DefaultSelenium("localhost", 4445, "*iexplore","http://www.imdb.com/"); 
selenium.start(); 
selenium.open("/"); 
selenium.windowMaximize(); 
selenium.windowFocus();

Answer 61Yes, since Selenium server is written in java you need java to be installed on your system to be able to use it. Even though, you are not being using java to program your tests.

Answer 62Following browsers could be used with Selenium – 
  • *firefox
  • *firefoxproxy
  • *pifirefox
  • *chrome
  • *iexploreproxy
  • *iexplore
  • *firefox3
  • *safariproxy
  • *googlechrome
  • *konqueror
  • *firefox2
  • *safari
  • *piiexplore
  • *firefoxchrome
  • *opera
  • *iehta
  • *custom 
Here pi and proxy stand for proxy injection mode of Selenium server
On 1:01 AM by Unknown   No comments
Answer 63Yes you can instruct Selenium Server to launch just one window. To do so you must specify –singleWindow while starting the Selenium server as –

           java -jar selenium-server.jar –singleWindow

Answer 64This usually happens while using open method with Selenium. One way to overcome this is to use setTimeOut method in your test script another way is to specify time out while starting Selenium server as following –

           java -jar selenium-server.jar –timeout

Answer 65You can specify your corporate proxy as following while starting Selenium Server –


java -jar .jar-Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttp.proxyUser= -Dhttp.proxyPassword=

On 1:01 AM by Unknown   No comments
Answer 66Changing domains is also a security restriction from java script. To overcome this you should start your Selenium server in proxy injection mode as –

java -jar selenium-server.jar –proxyInjectionMode

Now Selenium server would act as proxy server for all the content going to test application

Answer 67Yes you can. To do so you need to specify following parameters while starting Selenium server –
  • Browser
  • Test domain
  • Path to html suite (you Selenese tests) and
  • Path to result 

Ex: java -jar <>.jar -htmlSuite   

Answer 68If you want to log browser side option during test execution then you should start Selenium server as following – 
java -jar <>.jar –browserSideLog

On 1:01 AM by Unknown   No comments
Answer 69You can use Selenium RC on any system which is capable I running Java. Hence you can use Selenium RC on MAC and UNIX machines also

Answer 70You can specify *custom followed by path to browser to execute your tests on any browser while starting Selenium server -  *custom

Answer 71Selenium RC itself does not provide any mechanism for test reporting. Test reporting is driven from the framework you use for Selenium.

For example with java client driver of Selenium –
  • If you are using JUnit then you can use ANT plug-in of JUnit to generate test report
  • If you are using TestNG then TestNG generates reports for you 


Same reporting option is available with PHP unit and other client libraries you are using.

On 1:01 AM by Unknown   No comments
Answer 72Power of recovery scenarios lies with the programming language you use. If you are using java then you can use Exception handling to overcome same.

For example if you are reading data from a file and file is not available then you should keep you code statements in “try catch” block so that test execution could continue even in the wake of errors. Such mechanism entirely boils down the errors you want to recover from, while being able to continue with test execution.

Answer 73You can use loop features of the programming language, for example you can use “for” loop in java as following to type different test data in a text box –

// test data collection in an array 
       String[] testData = {"test1", "test2", "test3"};

// iterate through each test data 
     for (String s : testData) { 
              selenium.type(“elementLocator”, testData); 
     }

Answer 74You can use method getEval() to evaluate java script.

For example if you want to count number of images then you can pass following DOM statement to getEval() as following –

            selenium.getEval("window.document.images.length;");

Or to get all anchor objects from a page

            selenium.getEval("window.document.getElementsByTagName(‘a’);");

On 1:01 AM by Unknown   No comments
Answer 75If you want to see all options available while starting Selenium server then you should use option “-h” while starting Selenium server -    
  
java -jar selenium-server.jar –h 
(It will display you all the options which you can use while starting the Selenium server.)

Answer 76You may like to create your own Firefox profile because Selenium always created a clean Firefox profile while executing the tests and none of your Firefox settings and plug-in are considered with this clean profile. If you want to execute tests on Firefox with your settings then you should create custom profile for Firefox.

To be able to execute tests on a custom Firefox profile you should specify its path while starting Selenium server. For example if your new profile is stored at “awesome location” in your directory then you should start Selenium server as following –

  java -jar selenium-server.jar -firefoxProfileTemplate   "awesome location"

Answer 77Start your Selenium Server as following – 

java -jar selenium-server.jar -log selenium.log

And Selenium would start logging server side info, i.e.

20:44:25 DEBUG [12] org.openqa.selenium.server.SeleniumDriverResourceHandler -Browser 12345/:top frame1 posted START NEW