Selenium is a portable software-testing framework for web applications. It provides a playback tool for authoring tests without the need to learn a test scripting language. Selenium is an extremely popular portable framework used to test web applications. It provides the features needed by a user to author automated tests without the need of a test-scripting language. It supports testing of the functional aspects of an application across several platforms and browsers. It is not a single utility or tool, but a package of various testing tools due to which it is called a Suite. Each of these testing tools perform different testing functions.
There are four components of Selenium:
Selenium IDE provides an integrated development environment (IDE) for the tests. It allows the editing, recording and debugging of tests and was initially known as the Selenium Recorder. With the autocomplete support and its ability to make commands move quickly, it provides the ideal environment for the creation of Selenium tests.
Few features of Selenium IDE are:
Selenium WebDriver is a browser automation framework responsible for sending commands to the browser once it receives them. It is achieved by a browser-specific driver which retrieves the results after sending the commands to the browsers. Most drivers launch and then access the browser application (like Chrome, Firefox, Internet Explorer, etc.), thus Selenium is different from the rest in terms of features and functionality. It supports languages like C#, Java, PHP, Ruby, Python and Perl.
SAF refers to a customized framework that has been developed using Selenium. It serves as a widely accepted web application and automation tool for developers. It is responsible for shrinking test cycle times as well as the related costs. This software testing framework is portable in nature and very helpful for testing for web applications. In Selenium tests, the test codes can be written in the form of HTML tables or as codes in different popular programming languages. Selenium IDE is a Selenium test that is in the form of a Firefox add-on; this IDE can be used for the creation of relatively simpler test suites and test cases. Additionally, Selenium 1 or Selenium Remote Control serves as the first Selenium tool that allows developers to work with programming languages involved in creating complex tests.
A framework is a structure that helps to maintain the code in an easier manner. Without this framework, the code and the data would be placed in the same place. This in turn would make them neither readable nor re-usable. Frameworks help to increase code re-usage and readability, increase portability and reduce the maintenance cost of scripts.
There are three types of frameworks which have been created by the Selenium WebDriver in order to automate the manual test cases:
During the instantiation of a WebDriver object, every window is assigned with an alphanumeric id, which is known as the ‘window handle’. The control between windows are switched using these ids and necessary actions are then performed. The ‘SwitchTo’ methods use the window handle values to switch control between different windows.
Screenshots are useful for bug analysis. In Selenium, developers can go for automatic screenshots, even during the time of execution. A WebDriver instance has to be type casted to TakesScreenshot for enabling the process. The steps for taking screenshots in Selenium are:
TakesScreenshot scrShot =((TakesScreenshot)webdriver);
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
The JavaScriptExecutor interface is used for scrolling down in selenium. This interface helps to execute the methods through the WebDriver.
Xpath finds an element when it cannot be found by general locators – id, name, class etc. Xpath consists of the path of an element which is situation on the web page. Here are the two types of xpath:
Xpath can be written in many ways but the basic syntax is as follows:
//tagname[@attrubute=’value’]
The different methods of writing dynamic Xpath in case of selenium comprise of using:
TestNG (in which NG stands for Next Generation) is a testing framework inspired by Junit. It helps generate a detailed report with the details of the tests that have been passed, skipped or failed. It eliminates few limitations showcased by the older frameworks. TestNG provides users with the ability to develop powerful and flexible tests using the features of grouping, easy annotations, parametrizing and sequencing.
As Selenium supports the automation of web browsers only, developers have to take the help of third party APIs of the likes of JExcel, Apache POI, etc. to write and read data from excel files. Apache POI refers to an AP that is scripted in Java. It is a freeware that offers flexible options to read/write files. Packaged with predefined methods, numerous classes, and different interfaces, it is the go to solution for reading data from Excel in Selenium.
In automation, there are instances when multiple windows and popups have to be handled in web applications. The required activity necessitates the switching of controls among several popups and window from one to another with a view of completing different operations. After the popups are handled, the users have to return to the parent or main window. Selenium web driver provides different methods of handling popups and multiple windows.
Driver.getWindowHandles();
In order to handle the open popups / windows by a web driver, developers may want to utilize the "Driver.getWindowHandles()" provided by the web driver. This handle can be used for switching from one window to the other in any web application. The return type of this action is Iterator<String>.
Driver.getWindowHandle();
The main window/ popup is to be handled by driver.getWindowHandle() when any site opens and loads. It handles the current window that’s uniquely identified within the driver instance. The return type of this handle is String.
The ‘maximize()’ method belongs to the ‘Window’ interface of the ‘driver class’, it is called to maximize a window in Selenium.
WebElement refers to an element present in the DOM. Selenium represents a DOM element in terms of a WebElement so that it can be manipulated as per user requirements. A WebElement reference to any given element within the DOM. Selenium represents DOM elements through web elements in order to help developers manipulate the same fitfully. The Selenium Web Driver offers two methods for finding these elements.
findElement() – this method finds a singular web element and returns the same as a WebElement object.
findElements() – this method returns a list of different WebElement objects that match with the locator criteria.
Maven helps manage the entire lifecycle of the test project. It defines project structure, build, dependencies and test-management. By using pom.xml (Maven) one can configure the dependencies required for developing testing as well as the running codes. It is basically a ‘build-management tool’ used to define how a .java file gets compiled to a .class file and can be packaged into a .jar file. It aims to be fully self-contained such that one does not require additional scripts or tools for incorporating various tasks like installing necessary libraries etc. It is quite portable due to which one doesn’t face issues with the working of the same build script on different computers.
Selenium Grid specializes with the running of tests across various browsers, operating systems and machines simultaneously. It basically supports distributed and parallel execution of tests. It reduces the amount of time required for the suite to finish a test pass.
Handling dropdowns are like handling any other elements on a page. A drop-down can be chosen using Id, Name, Xpath etc. However, dropdowns require the ‘Select’ package to be imported to help users perform an action on them. Once the package is installed a new ‘Select’ Object is created which belongs to the class ‘Select’. This is then used to select or deselect an option in the dropdown. The dropdown WebElement is passed as a parameter to the constructor for the initialization of the ‘Select’ object.
The three ways in which an option can be selected are:
The radio button can be chosen by using the ID, Element value or the CssSelector and selected by using the ‘click()’ method.
At times when the need to run a test on various data sets arises, the creation of a new test every time can be cumbersome and time-consuming. Data-driven framework helps us overcome the same. The test data is first created in the form of a spreadsheet and then imported to the testing tools due to which the test data and tests are kept separate. This allows for the same test to be run multiple times on different validation and input values.
There is no need of an extension in chrome now. To find the xpath in chrome, right-click on the element followed by ‘Inspect Element’, once inside the inspector, right-click on the element then go to ‘Copy’ click on ‘Copy Xpath’.
Objects or controls in a webpage are called elements. Different ways of finding elements in webpage include element ID, Name, Tags, etc.
A: As opposed to manual testing, automation testing is the process where the testing is done automatically with a set of tools without manual interference.
A: Selenium supports two types of testing:
1.Functional Testing
2.Regression Testing
Assertion in Seleniun is a verification point to verify whether the applications conform to expectations.
A: Selenese is the programming language to write test scripts for Selenium IDE.
Locators are addresses to uniquely identify a web element within a webpage. The locators used in Selenium include:
A: XML or Extensible Markup Language stores transports and organizes arbitrary data. Data is stored in key value pairs similar to HTML tags, and since both are markup languages, XPath can be used to locate HTML elements of a webpage.
A: The difference in XPath is as follows:
Single Slash (/): Creates an absolute XPath to start the selection from document or start node.
Double Slash (//): Creates a relative XPath to start the selection from anywhere within the document.
A: Selenium Grid is used to execute the testing scripts on many browsers and platforms simultaneously. This allows the testing to be distributed, testing under different environments, and significantly reduced testing time.
A: Yes, HTML name and ID is available and can be used in Selenium.
A: Mobile Testing Drivers supported by WebDriver include AndroidDriver, iPhoneDriver, and OperaMobileDriver.
A: Both Assert and Verify commands check to see whether a give condition is true or false. The difference lies in how the test proceeds with the result. When Assert command is used, the program shall execute the successive testing phases only if the condition is true, and will completely stop test execution if the result is false.
On the other hand, the Verify command will not stop test execution, that is, the test will be completed even if the condition is returned false.
A: The TypeKeyes command triggers a JavaScript event and fills the value attributes using JavaScript, while the Type command does not start JavaScript, but simply emulates typing of an actual user.
A: There are two types of wait in Selenium WebDriver:
1.Implicit Wait: Provides a specific user defined time span during which the test execution is stopped before an element is found in each test conducted throughout the entire program.
2.Explicit wait: Causes execution to be stopped till a custom defined condition is met for a specific instance only.
A: Neither the .close() command nor .quit() command need parameters or return values. The difference is while the .close() command closes the particular browser window being accessed by WebDriver, the .quit() command shuts down all the windows opened by the program
A: Four parameters need to pass in Selenium: Host, Port Number, Browser, and URL.
A: JUnit is a Java based open source unit testing framework introduced by Apache. Annotations are some special types of syntax based meta data that are added to a JAVA Source Code.
A: The find element() command locates the first element in the working page and returns one WebElement, while the find elements() command locates all the elements asked for in the present page and returns the list of these WebWlements.
A: The Module Based Framework separates the complete application being tested into separate individual units or modules, and separate scripts are written for each of these modules. When combined, these separate scripts make up the complete testing program.
A: The common steps of the test are determined and grouped in a library under functions which are called wherever required in the test script.