testinganswers.com

Category: Selenium Tutorial

19.2 WebDriver browser methods

19.2.1| getPageSourceReturns the page source of the last loaded page. The page source returned is a representation of the underlying DOM. It may not be formatted or escaped in the same way as the response sent from the server.                                                                                                                              Read More

19.1 WebDriver browser methods

WebDriver provides a variety of methods to simulate user actions on a browser. Some of those methods are described below  19.1.1| get Loads a new page in the current browser window. This is achieved using HTTP GET operation. This method blocks the WebDriver test execution until the page load is complete.                                                                                                   Read More

18 Working with Browsers

A web browser is a software application that allows users to retrieve, present and traverse information resources on the World Wide Web (www). An information resource is identified by a Uniform Resource Identifier (URI). The information may be a web page, image, audio, video, or any other content. There are various browsers available in the market as of now. These include internet explorer, chrome, firefox, safari, opera, etc. This chapter describes how to use the WebDriver method to simulate user actions on a firefox browser.   18.1.1| Introduction Open Firefox Browser: WebDriver provided FirefoxDriver() class to open a new Firefox Read More

17.2 User Interface Map

17.2.1| Creating a UIMap class to read locators from UIMap.properties fileNow we will build a UIMap class to access locator information from a properties file.   UIMap.properties example part-1   UIMap.properties example part-2   UIMap.properties example part-3 17.2.2| Creating a sample TestNow let us create a sample test that would use the UIMap properties file and UIMap class file to locate elements.The following example opens amazon.in the login page and then uses the UIMap file to locate login page elements. Sample Test  

17.1 User Interface Map

Selenium WebDriver API uses locator information to find elements on the page. Defining the locator information in the classes may result in duplication of element location information in various classes. Because of such duplication, it becomes increasingly difficult to maintain tests as the size of the test suite increases. Any change in element locator information requires updating of the element locator information in all the classes wherever it has been defined. Identifying classes which require an update and then updating them is a very time consuming and difficult task. In short, change identification and change implementation become a nightmare.   Read More

16.2 Annotation

16.2 | Custom Annotations Java provides the flexibility to define custom annotations as per need. An annotation is defined with the at-sign (@) preceding the interface keyword. The following steps show how to create and use custom annotations. Open Eclipse Select the package where annotation needs to be created. Right-click and select New → Annotation as shown in figure   Creating a new annotation file Specify annotation name say RegressionTest. The following code shows the annotation code with no annotations and parameters.   RegressionTest Above annotation can be directly used in code as:   Use of Annotation Annotate the annotation as required. Read More

16.1 Annotation

An annotation is a form of metadata that provides data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code which is annotated. The annotation has a number of uses and a few of them are as follows:  Annotation can be used by the compiler to detect errors or suppress warnings. Annotations can be examined at runtime. Software tools can be written that process annotation information to generate code, XML files, etc. An important use of annotation in test automation is to define the test type (functional, regression) Read More

15 Exception Handling

Exceptions in Java are objects. All exceptions are derived from the java.lang.Throwable class. Exceptions can be handled in Java using the try-catch-finally construct. Exceptions thrown by the try block of code are caught (handled) by the catch block. The following code shows an example of the try-catch-finally construct.   The output of the above example Whenever an exception is thrown by try block of code, it looks for catch construct which handles that exception. If no catch construct is found which handles the exception, then the exception is handled by the default exception handler. The catch construct is not executed if Read More

14 Interfaces

An interface is a group of related methods with empty bodies. In other words, it is a collection of abstract methods. An interface is not a class. A class implements an interface to inherit the abstract method of the interface. The following code shows an interface Cars, that has method make() and price().   The following steps show class Nissan which implements the Cars interface and define its abstract method make() and price(). 14.1 | Create a new class in Eclipse   1. Create a new class in Eclipse as defined in the previous post. 2. Provide reference of Cars interface as Read More

13 Abstract class

A class that is declared with the abstract keyword is known as an abstract class in Java. It can have abstract and non-abstract methods. If a class contains any abstract method then the class is declared as an abstract class. An abstract class is never instantiated. It is used to provide abstraction.   abstract class className { }   Before learning the abstract class, let’s understand the abstraction in Java first.     13.1 | Abstraction   Abstraction is a process of hiding the implementation details and showing only functionality to the user.    let’s take an example, We send Read More