Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

First Steps in Selenium WebDriver: Useful Questions with Answers

In this post, we discusses on the few initial questions before starting with using Selenium WebDriver for automation of web application. This will cover the basic topics on Selenium WebDriver and in later articles, we will go further on discussing the use of selenium WebDriver, how to use it in project and framework creation using Selenium in Java.

Question 1: What is Selenium Web Driver?

Answer:  Selenium Web driver uses accessibility API to drive the browser and recognizes the object in web-based application. It allows writing automated tests replicating the behavior of real user, e.g. Clicking on a link or feeding data in an edit box. Using Selenium Web Driver together with any programming language and other testing framework like TestNG and JUnit, automation test framework to execute tests on different browsers can be created. We can use the robust features of the programming language to interact with other components of application like database interaction, files interaction to create a robust and reliable framework.

Question 2: What are the various browsers supported by Selenium WebDriver?

Answer: WebDriver available for automation in different browsers are ChromeDriver, InternetExplorerDriver, FirefoxDriver, OperaDriver and HtmlUnitDriver.

Question 3: What are the programming languages supported by WebDriver?

Answer: Python, Ruby, C#, Java, Perl, php and javascript are supported.

Question 4: What are the necessary steps required, before I start creating selenium tests on java using eclipse?

Answer: We require following configuration to be set up before creating test in eclipse:
1. Java needs to be installed in the machine.
2. Eclipse IDE needs to be installed.
3. Selenium Libraries for WebDriver should be available.
Please click on link below for details for configuration steps in eclipse.

Question 5: Do we need to install some additional executable files working with Selenium WebDriver?

Answer: For Firefox driver, we do not require any additional executable as it is bundled with Java client bindings, For IE driver, Chrome driver, and Opera driver, we require additional executable that can be downloadable from Selenium Official website.
An example of how to create an instance of Internet Explorer Web Driver is shown in below example.
How to create an instance of driver in IE and Firefox

Question 6: Is there any specific pre-condition before executing a selenium script on Internet Explorer?

Answer: Yes, Protected Mode settings should be same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.

Question 7: What are Firefox profile preferences?

Answer: Using Firefox Profile, we can set the preferences for the Firefox in the profile.
The steps to define profile in Selenium are:
1.  Create an object of firefox profile
FirefoxProfile profile = new FirefoxProfile();
2.   Set the required preference of the firefox :
                  profile.setPreference("browser.startup.homepage",”http://www.google.com”)
3.  Create the driver object with profile as defined above.
     WebDriver driver = new FirefoxDriver(profile);

Question 8: What is the use of using TestNG with selenium in Java?

Answer: TestNG is a unit testing framework used for java programming language. Test Cases using Selenium Webdriver to identify webelement in the web application can be integrated/created on TestNG framework. Some of the useful features TestNG provides are as follows:
          1.  Using Annotation to describe order of test cases, defining start conditions and end condition using  @after and @before annotations.
                2.  Reporting feature for test execution status in html and xml format.


Enhancing and Understanding features in Selenium IDE: Questions and Answers

In previous articles on Selenium, we understand the basics of Selenium IDE, Selenese Commands, Selenium Locators. In this article, we will discuss on features Selenium IDE provides and enhancement that can be done using these features.


Question1:  Explain the various features provided by Selenium IDE?

Answer: The layout of Selenium IDE is divided into following four areas:  
               1. MenuBar – Following are the menu options available in Selenium IDE:
a.   File – Allows creating new test case, test suite, open existing test case, test suite, exporting tests to other formats.
b.   Edit – Allows editing existing test steps, and adding new commands and comments.
c.   Actions – Allows to record, play a test, execute command, toggle breakpoint and set entry point.
d.  Options – Allows the changing of settings including set the timeout value for commands and specifying the format used for saving test cases. 
e.  Help – provides documentation for selenium IDE.

            2.  Toolbar – Provides buttons to manage test execution including test execution and test execution.
            3.  Test Case Pane – Test Case Pane shows the list of test case on the left and test steps in table or    
                 source pane on the right. We can add/modify commands, target and value in the table for the test.
            4.  Log/Reference/UI-Element/Rollup Pane – This pane helps us to view logs of execution, reference explaining the selected command. We can also set to filter logs for info, warning, error and debug in this window.

Understanding various Pane in Selenium IDE

Question 2: Explain what are the various items available from file menu?

       Answer: From the File Menu, We can perform various tasks:
a.   Create New Test Case.
b.   Create new Test Suite.
c.   Save test cases and test suites.
d.   Export Test cases/test suites to various formats. E.g : Ruby/Python/java/c# with WebDriver or RC.
e.  Open existing test cases and test suites.
f.   Rename a test case.

Option to export test cases to different formats

Question 3: Can the script prepared in Selenium IDE be used with webdriver/Remote control?

Answer: Yes, the script created in Selenium IDE can be exported to WebDriver/Remote Control in the languages java/c#/python/ruby that can be run using junit(java), RSpec(ruby), nUnit. Below is an example of script exported to java/junit/WebDriver.

Test Case in Selenium IDE exported to Java/Junit/Webdriver

Question 4: My Application is running slowly, can I change the default timeout value of recorder command?

Answer: We can reset the default timeout value for recorded command from Options Menu. By default the timeout is set as 30000 ms. In options, we can also define the recording settings and order of locator preference for object identification.

Question 5: What is the short cut key to create a new test in Selenium IDE?

Answer: The shortcut key to create a new test in Selenium IDE is Ctrl + N.
Some other useful shortcut keys in Selenium are:
Open a test – Ctrl + O :  Save a test – Ctrl + S  : Add test to test suite : Ctrl + D.

Question 6: What is the use of Select and find button in target in Selenium IDE?

Answer: On clicking on select, we can add the locator of an element in the page. Click on Select and click on an element in the page, the locator for the element will be added in the target. Find helps us to verify object exists in the page and highlights the object in the page if exists, else error is displayed in the log. 


Understanding Locators in Selenium IDE : Questions and Answers

In this article, we will discuss various locators in Selenium IDE and how to identify the elements on the page using locators.Hope this be useful step in understanding Selenium IDE locators.

Question 1: What is meant by locators in Selenium IDE?

Answer: In the previous Post about Selenium Commands, we get to know that to execute most of the commands, we require target on which to execute commands. The target identifies an element in web application by the locators. Suppose there is an input box with id as username, this element in the page will be located and identified by ‘id=username’ and then we can set value in the input box by executing command ‘type’ on the target object identified by locator ‘id=username’ with required value.

Question 2: What are various locator types in Selenium IDE?

Answer: The various locator types in Selenium IDE are as follows: 
       a.  Locating elements by ID – an element can be identified using ‘id’ attribute if attribute is defined for the object. Since it is assumed that attribute id will be unique for elements if defined, hence element will be uniquely identified in the Page using id attribute in target. E.g. ‘id=gbqfq’.
      b.  Locating elements by name – if id attribute is not available, we can identify the element using name attribute in the target. E.g. ‘name = nickel’. In case of object not identified by name locator, we can use multiple locators like ‘name = nickel value = core’ to uniquely identify the object.
      c.  Locating elements by link text – For link object, we can identify an element using link text in the target. e.g. ‘link =logout’ will identify a link with text as logout.
      d.   Locating elements by XPath – We can also use XPath to identify an element in the page. XPath allows us to query the DOM structure of the page like a XML document. For e.g. //input will find first input box in the page and perform action on the same.
      e.   Locating elements by css – Elements in the webpage can be identified using CSS selectors to find the objects that you need. Selenium is compatible with CSS 1.0, CSS 2.0, and CSS 3.0 selectors. Syntax for identifying an element using css is ‘css = CSS Selector’ for e.g. ‘css=input.gbqfif’ where input is the tag name for element and gbqfif is the classname. Both xpath and css are useful to identify elements with complex identifiers.

Question 3: How can I found the attributes and properties which define an element in the webpage?

Answer: We can identify the element structure using different developer tools in different browsers.
Below are some of the developer tools that help to identify objects in the page.
a.   Firebug: Firebug is a Firefox developer tool used to identify elements on the page by using the find functionality.
b.   Firefinder: It is a Firefox tool and helps in testing XPath and CSS on the page. Highlights all elements on the page that match the selector to your element location.
c.   IE Developer Tools: IE developer tools helps in identifying element. This is inbuilt with IE browser and can be launched by pressing F12.
d.  Google Chrome Developer Tools: This is inbuilt in Google chrome and can be launched by Pressing F12.
Below image shows how to identify object in google chrome browser by pressing F12.
Using developer tool to identify an object

Question 4: Is there any specific feature in selenium IDE by which we can use the best locator to identify an element?

Answer: Yes, when we work on an element in Firefox, selenium IDE identifies an object in various possible ways. To understand this better, consider the google Page and search edit box. When we type in the edit box, Selenium IDE provides various options to uniquely identify an element as shown in the screenshot below. We can also verify if object is correctly identified using Find Button in Selenium IDE tool. This identification can be very useful to identify the element in Selenium Web driver.

Selecting best fit locator for an element in Selenium IDE


Question 5: Explain how to create XPath and CSS with some examples?

Answer: As explained earlier, XPath and CSS can be used to identify element in webpage. Below are some examples that show correlation between css and xpath and how to create the same.
      a.  Element <El> : XPath – //El : CSS – css = El: for e.g. El can be a(for link), img(for image).
      b.  Element <El> with name ‘na’ : XPath – //El[@name =’na’] :  CSS – css = El[name= na]
      c.  Element <El> with id ‘na’: XPath – //El[@id =’na’] :  CSS – css = El#na
      d.  Element <El> with class ‘na’: XPath – //El[@class =’na’] :  CSS – css = El.na