Which is Better : UFT or Selenium

UFT

This Tabular Form will help you understand more clearly

   HP UFT (QTP)                           Selenium
It only supports Visual Basics It supports many languages like Java, Python,C#,Ruby,Perl,PHP
It supports both Browser Based or Non-Browsers Based Applications It supports only Browser Based Applications
It supports Google Chrome(Till version 23) and Internet Explorer,Firefox(version 21) It supports Google Chrome,Internet Explorer,Firefox,Opera,HtmlUnit
It supports only Windows It supports Windows,Linux,Solaris and other OS where JavaScript support exists
It uses commercial Products for Mobiles like HP UFT Mobile It supports Android,iOS, Windows,Blackberry,Headless Web Kit
It has License and Annual Maintenance Cost It is a free tool with zero maintenance cost
Script Creation takes lesser time Script Creation time is comparatively higher
It is a dedicated HP Support product It is a Open Source
It does not require Rich Coding Experience Person Rich Coding Person with technical capabilities of integrating different parts of framework is required to work on Selenium
Integration is possible through QC/ALM or Jenkins Integration is possible through Jenkins/Hudson/Cruise Control
It supports all types of dialog boxes It supports Dialog Boxes Partially
It has high Hardware Resource Consumption(CPU+RAM) It has comparatively low Hardware Consumption(CPU+RAM)
It uses framework that is compatible with HP like HP Quality Center or HP ALM It uses different frameworks like Selenium+Eclipse+Maven+Jenkins/Hudson+TestNG+SVN

 

Standard

Selenium and Its Components

components

Selenium : It is a free ware tool used for automation of Web Based Applications only.

Beauty of Selenium is that it supports OS like Windows,Linux,Macintosh and other OS for mobile applications as well : Android,Windows Mobile, iOS and the main reason for its popularity is that it is freely available.It is the best tool for automation of Web Based applications.

Components of Selenium : There are main four Components of Selenium :

  1. Selenium IDE
  2. Selenium RC
  3. Selenium Webdriver
  4. Selenium Grid

 

  1. Selenium IDE (Integrated Development Environment): It is a Firefox Plugin and is used for “Record and Run” Functionality. User can automate their functionality by adding this plugin in Firefox Browser and then on clicking the “record” button and then start working on your application Example – login to account. Selenium IDE will write its code in back end and then by running the same code, your functionality(login in this case) will work on its own 🙂

IDE

2. Selenium RC(Remote Control) : It is a tool which helps in automating web based application by allowing the user to write program in any language that supports HTTP website

Selenium RC has mainly two parts

a) Server : which automatically launches and kills browsers

b) Client Libraries : Stores Selenium Commands

3-way_handshake_2

3. Selenium Web driver : It  is the extended part of Selenium RC with ,ore flexibility and advantages to end user. Web driver does not need Server for its execution and hence it is more dynamic and more supportive. It has extended support for other browsers and platforms. It overcomes the limitations of Selenium RC and hence is more user-friendly

Selenium 2.0 is a term coined for aggregation of Selenium RC and Selenium Web driver

Webdriver.png

4. Selenium Grid : It is mainly used for running test functionality dynamically on multiple browsers and different operating systems at same time. It thus helps in increasing the efficiency and make Selenium – the mot user friendly tool for automation of web based applications.

grid.jpg

 

 

 

Standard

Selenium Interview Questions Answers

bad_interview_questions

A list of frequently asked Selenium interview questions and answers are given below.

1) What is test automation or automation testing?

Automation testing is used to automate the manual testing. It is a process of automating the manual process to test the application/system under test. It uses separate testing tools which facilitate you to create test scripts which can be executed repeatedly and doesn’t need any manual intervention.


2) What are the advantages of automation testing?

  • It supports execution of repeated test cases.
  • It facilitates parallel execution.
  • It aids in testing a large test matrix.
  • It improves accuracy because there are no chances of human errors.
  • It saves time and money.

3) What is selenium? What are the different components of selenium?

Selenium is one of the most popular automated testing suites. It is browser automation tool which lets you automated operations like click, type and selection from a drop down of a web page. It is designed to support and encourage automation testing of functionalities of web based applications and a wide range of browsers and platforms. It is one of the most accepted tools amongst the testing professional due to its existence in the open source community.

Selenium is not just a single tool rather than it is a package of several testing tools and that?s why it is referred as a suite. Each of these tools is designed to cater different testing and test environment requirement.


4) What is Selenium 1.0?

Selenium 1.0 is popularily known as Selenium Remote Control (Selenium RC). It is a library available in wide variety of languages. The main reason to use Selenium RC was that Selenium IDE was incapable to execute tests in browsers other than Selenium IDE and the limitation of language Selenese used in Selenium IDE.


5) What is Selenium IDE?

Selenium IDE is a firefox plug-in. It is used to record and replay tests in firefox browser. It is used only with firefox browser.


6) What is selenium 2.0?

Selenium 2.0 is a tool which is a combination of web testing tools Selenium RC and WebDriver.


7) What is Selenium 3.0?

Selenium 3.0 is the latest version of Selenium. There are 2 beta version of Selenium released with few changes in the previous versions.

A list of few new features added in Selenium 3.0:

Beta 1 Updates Beta 2 Updates(Only for java)
Minimum requirement is java version 8+ System property webdriver.firefox.marionette now forces the server in marionette or legacy firefox driver mode, ignoring any related desired capability
It will support for Firefox via Mozilla?s GeckoDriver Grid fixes NPE?s on registration when -browser not specified
It now supports safari on MacOS via Apple?s own safari driver Update GeckoDriver ?port argument in all bindings

8) Why is selenium selected as a test tool?

Selenium is used as a testing tool because:

  • It is free and open source.
  • It has a large user base and helping communities.
  • Compatible on different platforms i.e. Windows, Mac OS, Linux etc.
  • Have cross browser compatibility (Chrome, Firefox, IE, Safari etc.)
  • Support multiple programming languages ( Java, C#, Ruby, PERL, Python etc.)
  • Support distributed testing.

9) What are selenium supporting testing types?

Selenium supports two types of testing:

  • Functional Testing
  • Regression Testing

10) What are the limitations of selenium?

Selenium has following limitations:

  • It can be used only to test web based application.
  • Mobile applications can not be tested using selenium.
  • You can not test captcha and bar code by using selenium.
  • The user must have the knowledge of programming language for using selenium.
  • Reports can only be generated using third party tools like TestNG or Junit.

11) What is selenese?

Selenese is a lanuage which is used for writing test script in selenium IDE.


12) Describe the different types of locators in Selenium?

Locator is an address which identifies a web element uniquely within the web page.

There are different types of locators in Selenium to identify web elements accurately and precisely.

These are:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM

13) What is an Xpath?

Xpath is used to locate a web element based on its XML path. It can be used to locate HTML elements.


14) Which is the latest Selenium tool?

The latest Selenium tool is WebDriver.


15) What are the different types of Drivers that WebDriver contains?

These are the different drivers available in WebDriver:

  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver
  • HtmlUnitDriver

16) What are the different types of annotations which are used in Selenium?

JUnit annotations which can be used are:

  • Test
  • Before
  • After
  • Ignore
  • BeforeClass
  • AfterClass
  • RunWith

17) What is Selenium Grid?

Selenium Grid facilitates you to distribute your tests on multiple machines and all of them at the same time. So, you can execute tests on Internet Explorer on Windows and Safari on Mac machine using the same text script. It reduces the time of test execution and provides quick feedback.


18) Where the result is seen of Test Execution in Selenium IDE?

The result of test execution is displayed in a Log Window in Selenium IDE.


19) Can you edit tests in Selenium IDE?

Yes, tests in Selenium IDE can be edited. There are two ways to edit tests in Selenium IDE.

  • By Table views
  • Looking into the source code

20) Can you use html id and name while using Selenium IDE?

Yes, You can use html id and name as it is available in Selenium IDE.


21) What are the WebDriver supported Mobile Testing Drivers?

WebDriver supported “mobile testing drivers” are:

  • AndroidDriver
  • IphoneDriver
  • OperaMobileDriver

22) What are the popular programming languages supported by Selenium WebDriver to write Test Cases?

  • JAVA
  • PHP
  • Python
  • C#
  • Ruby
  • Perl

23) What is the difference between assert and verify commands?

Assert: Assert command checks if the given condition is true or false. If the condition is true, the program control will execute the next phase of testing, and if the condition is false, execution will stop and nothing will be executed.

Verify: Verify command also checks if the given condition is true or false. It doesn’t halts program execution i.e. any failure during verification would not stop the execution and all the test phases would be executed.


24) What is the difference between “/” and “//” in Xpath?

Single Slash “/”: Single slash is used to create Xpath with absolute path.

Double Slash “//”: Double slash is used to create Xpath with relative path.


25) What is the difference between driver.get() and driver.navigate.to()

Both methods can be used to navigate to a url but the driver.get() is a convenient way to navigate to a url. The driver.navigate() does the same function as the driver.navigate().to(?url?) but it also has other functions, such as:

  • driver.navigate().back()
  • driver.navigate().forward()
  • driver.navigate().refresh()

26) What is the difference between implicit wait and explicit wait in selenium webdriver?

Implicit Wait: In Implicit wait, if WebDriver cannot find an element in the Document Object Model (DOM), it will wait for a defined amount of time for the element to appear in the DOM. The Implicit wait may slow down your tests, because once set, the implicit wait is set for the life of the WebDriver object’s instance.

An example of Implicit Wait:

  1. driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit Wait:

Explicit waits are better than implicit wait. Unlike an implicit wait, you can write custom code or conditions for wait before proceeding further in the code.

An explicit wait can be used where synchronization is needed, for example the page is loaded but we are still waiting for a call to complete and an element to appear.

An example of Implicit Wait:

  1. WebDriverWait wait = new WebDriverWait(driver, 10);
  2. wait.until(ExpectedConditions.titleContains(“selenium”));

27) What is the difference between type keys and type commands?

TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t.


28) What is the difference between “type” and “typeAndWait” command?

“type” command is used to type keyboard key values into text box of software web application. It can also be used for selecting values of combo box whereas “typeAndWait” command is used when your typing is completed and software web page start reloading. This command will wait for software application page to reload. If there is not page reload event on typing, you have to use simple “type” command.


29) What is the difference between sleep() and setSleep() method?

Sleep() and setSleep() both methods are used to delay the speed of execution.

Thread.sleep (): It is used to stop the current (java) thread for the specified period of time. It’s done only once.

  • It takes a single argument in integer format.
  • For Example: thread.sleep(5000)- It will wait for 5 seconds.
  • It waits only once at the command given at sleep.

SetSpeed (): It will stop the execution for every selenium command for specific amount of time.

  • It takes a single argument in integer format.
  • For Example: selenium.setSpeed(“5000”)- It will wait for 5 seconds.
  • It runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed.

30) What is the difference between find element () and findElements ()?

find element (): It is used to find the first element within the current page using the given “locating mechanism”. It returns a single WebElement.

findElements () : It uses the given “locating mechanism” to find all the elements within the current page. It returns a list of web elements.


31) How to type in a text box using Selenium?

To type in a text box, we use sendKeys(“String to be entered”) to insert string in the text box.

Syntax:

  1. WebElement username = drv.findElement(By.id(“Email”));
  2. // entering username
  3. username.sendKeys(“sth”);

32) What is JUnit?

JUnit is an open source testing framework for java applications. It is introduced by Apache.


33) What is JUnit Annotation?

Annotation is a process of adding a special form of syntactic meta-data to Java source code. Variables, parameters, packages, methods and classes are annotated some of the JUnit annotations.


34) What are the four parameters that you need to pass in Selenium?

The four parameters that you have to pass in Selenium are:

  1. Host
  2. Port Number
  3. Browser
  4. URL

35) How can you “submit” a form using Selenium ?

  1. WebElement el  =  driver.findElement(By.id(“ElementID”));
  2. el.submit();

36) What is the difference between close() and quit()?

The close() method closes the current browser only whereas quit() method closes all browsers opened by WebDriver.


37) What is wait? How many types of waits in selenium?

The concept of waits is introduced by Selenium Webdriver for AJAX based application. There are two types of waits:

  • Implicit Wait
  • Explicit Wait

38) What is the main disadvantage of implicit wait?

The main disadvantage of implicit wait is that it slows down test performance.

Another disadvantage of implicit wait is:

Suppose, you set the waiting limit to be 10 seconds and the elements appears in the DOM in 11 seconds, your tests will be failed because you told it to wait a maximum of 10 seconds.


39) How would you check if a check-box or radio button is selected?

You can use the isSelected() method to check if a check-box or radio button is selected.

Syntax:

  1. driver.FindElement(By.id(“id_of_checkbox”)).isSelected();

40) How would you do drag and drop in Selenium Webdriver?

You can do drag and drop in Selenium by using the following code:

  1. Actions action = new Actions(driver);
  2. WebElement start = driver.findElement(By.cssSelector(?div.source?));
  3. WebElement end = driver.findElement(By.cssSelector(?div.target?));
  4. action.dragAndDrop(start,end).perform();

41) How would you check if an element is visible on the page?

isDisplayed() method is used to check if an element is visible on the page. The return type of this method is Boolean so, if it returns true, the element is visible otherwise it is not.

  1. driver.findElement(By.id(?id_of_element?)).isDisplayed();

42) How would you check if a button is enabled on a page?

isEnabled() method is used to check if a button is enabled on a page. The return type of this method is Boolean so, if it returns true, the element is visible otherwise it is not.

  1. driver.findElement(By.id(?id_of_element?)).isEnabled();

43) What are the main technical problems occurred with Selenium tools?

Like other automation testing tools, selenium also facilitates you to record, edit and debug test cases. But there are some problems that affect the maintainability of recorded test cases. Sometimes it takes more time to maintain automated test cases than to perform manual testing. Another problem is complex id for an HTML element. If ID is auto generated, the recorder test cases can fail during playback.


44) Which is the post release validation with continuous integration automation tool?

These tools are:

  • Jenkins
  • Hudson
  • Quick Build
  • CruiseCont

45) What are the four parameters that have to be passed in Selenium?

Four parameters that have to be passed in selenium are:

  • Host
  • Port Number
  • Browser
  • URL
Standard

How To Download and Install Selenium Webdriver

automation-animation

  1. Install Java in your Machine
  2. Download and install the Java Software Development Kit (JDK) here.Java
  3. Accept Agreement and Select JDK according to OS installed in your machine

Java2

4. Install Eclipse IDE

Download “Eclipse IDE for Java Developers” here

Eclipse

4. Select Windows Version 32 Bit or 64 Bit as per Windows Installed in your machine

5. Download .exe file and Install Eclipse IDE for Java Developers

Eclipse2

6.After Successful Installation of Eclipse. Launch Eclipse and start coding 🙂

 

 

Standard

Write Your first Automation Script Using Selenium

From Previous Blog, we have learnt how to setup your machine for Selenium Script. Now we will work on Eclipse for writing our First Selenium Script

Steps :

  1. Open Eclipse
  2. Go to File Menu—> New—> Java Project

Eclipse3

3. Enter Project Name as “First_selenium_project” and select Finish Option to save project

Eclipse4

4. After Project is saved, we first need to create Class. To create class go to Project Folder

“First_selenium_project”—>src—>right click—>create class

Class2.png

5. Once class is created, Eclipse will look like this

Class3.png

6. After this,we need to import JAR Files to our Project. For this, go to

Project—>Select Properties Option—>Select Java Build Path—>Libraries Tab—>Click Add External JARs

JARs

7. After clicking on “Add External JARs” select Selenium Java Client Driver and add all JAR Files indise and outside “libs” folder. Click OK to save the changes

JARs2.png

 

8.Now you are ready to write your first Code

Copy paste the below  Code and save it and execute it by selecting “Run” option

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Main_class

{

public static void main(String[] args)

{

WebDriver driver = new FirefoxDriver();

driver.get(“http://google.com”);

System.out.println(driver.getTitle());

driver.close();

}

}

 

Happy Coding Guys 🙂

Standard