Posts

Showing posts with the label Selenium Webdriver

Handle Multiple Browser Tabs and Alerts with Selenium WebDriver

Image
In this tutorial, we will learn to handle multiple browser tabs within a single Selenium script. Selenium WebDriver does not provide any commands for this task.  But we can make use of the existing Selenium commands in a smarter way to automate this scenario. Although this scenario is quite rare and you will not encounter it usually. 1. Handle Multiple Browser Tabs with Selenium Use Selenium Actions Class to Handle Multiple Browser Tabs Actions Class in Selenium is a special class which provides us very useful commands, which helps us to replicate Keyboard and Mouse events i.e., press/release any Key, move cursor, drag and drop, right click, double click etc. You can learn about Actions Class in detail here .  In our scenario, we'll make use of Key control commands of Actions class to automate open and automate multiple browsers. Let's understand the whole code logic step by step. 1.1. Launch google.com with Selenium WebDriver This is the most common part, we'll launc

How to Find Broken Links on Webpage with Selenium WebDriver

Image
As an Automation Tester you get to play with links present on the website. Links are one of the most important part of the webpage. So, it's always important to not leave any broken link on any website. Testing the links manually could be a tough and time taking task. In this post, we'll learn to automate the URL links testing. 1. What is a Broken Link? A broken link is a URL which is not working or not reachable. There are multiple reasons for it's dis-functioning. There are different http error status codes which the browser shows when the link is broken. These error codes have different meanings. Let's take a look at the different http status codes. 200 - It means success, link is working. 404 - It's the most common one, which mean Page not found. 403 - Authorization is required to access the page.  400 - It has different meanings, bad request, bad host, timeout etc. 500 - Internal server error. 2. Why a link broke? A link might not be working due to many reason

What are Selenium Wait Commands? Implicit, Explicit and Fluent Wait in Selenium

Image
In this post, you will learn about different waits in Selenium. Waits are required to tell Selenium to wait for a specific amount for elements on the web page before throwing "No Such Element Exception". There are three types waits in Selenium WebDriver, out of which first two are the most popular. Implicit Wait Explicit Wait Fluent Wait Implicit Wait in Selenium WebDriver Implicit wait is used to set a default wait time (say 30 secs) in your automation script to wait for an  element on the page. Key Points Implicit wait should be declared in your setup method (at beginning lines of your code). Default wait time for Implicit wait is 0 secs. Once implicit wait is set, it is applicable for the whole automation script. In simple words, you can also say that implicit wait is the maximum time set between two steps/commands of the automation script. Webdriver throws "No Such Element Exception" if element is not found in specified time. Syntax: //

How to take Full and Partial Screenshot with Selenium WebDriver

Image
While performing manual testing we often take screenshots of the broken pages or bugs to use them as evidence and they are very useful in convincing the developers. Similarly, in automation Selenium provides us the commands  to capture screenshots of the webpages. In this tutorial, we will learn to take full screenshot and partial screenshot of the webpage which is currently under test. We can also write some code logic to capture screenshots on every failure screen. That's a bit advance level concept. But in this post we'll learn to take screenshots whenever we want. We also have to do some file handling operations while taking and saving screenshot with Selenium WebDriver. 1. Take Full Screenshot with Selenium WebDriver 'TakeScreenshot' is the interface which is used to capture screenshot in Selenium WebDriver.  Let's discuss the code to take screenshot step by step: 1. File -  It is one of the inbuilt Java class which is used for File handling operations, like

How to Automate Google Search with Selenium WebDriver

Image
+ In this post, you will learn to automate Google Search using Selenium Webdriver with Java. This is a real time example of Explicit wait command. Google search is an ajax call. We will handle this ajax call using Explicit wait command of selenium Webdriver. We can also say that, we'll automate the auto suggestion feature of search in this post. What is Ajax search? Ajax stands for Asynchronous JavaScript and XML. Ajax is a new technology for creating for faster and more interactive web applications. What ajax does is: Update a web page without reloading/refresh it Read data from the server after the page is loaded When you write something into a Search Box say "app" and it shows you similar search options that is ajax. And you can automate that auto suggestion box with the help of Explicit command in Selenium WebDriver . Google search is a best example of ajax. In case of google search, you simply type any keyword in search bar and just below the search bar a su

Implement Code Re-usability in Selenium Automation Framework

Image
In this post, you will learn kind of coding pattern which is very helpful in maintaining our automation code. This post is written insight to help beginners. We'll learn that instead of writing a linear script, we should create page (action) methods which in general contain actions which we are going to perform on our web software. Let's say, we have a login functionality in our software and we have to automate it. In that case we'll create a method named login and write the commands like, entering username, password and click login in that method. Now we can use that method wherever we need it in other test cases as well. Benefits of using action methods are: Code Re-usability Better maintainability of code Sample Program for Re-Usable Action Methods: package com . techlistic . tute ; import org.junit.Assert ; import org.junit.Test ; import org.openqa.selenium.By ; import org.openqa.selenium.WebDriver ; import org.openqa.selenium.WebElement ; import o