Read/Write .xls and .xlsx with one set of code using POI - WorkbookFactory

As we discussed in earlier post Read/Write excel using Apache POI,
we have to use:
For handling .xls fileswe use HSSF (Horrible SpreadSheet Format) related POI classes.
For handling .xlsx files, we use XSSF (XML SpreadSheet Format) related POI classes.


On this post, how we can perform excel operations with one set code for both excel formats .xls and .xlsx.
For this we have a class provided from Apache POI WorkbookFactory, which auto detects appropriate kind of Workbook (HSSFWorkbook or XSSFWorkbook) depending on the excel formats .xls or .xlsx.
Let's jump to the code implementation

Internet Explorer IE11 - F12 (debugging) not working

There is a situation where, you installed IE11 freshly and try to open the debugging window by clicking F12, but shows error instead the HTML content,

here is the fix:

Download and install the below respective patch, restart and click on F12 to get the html content.

For 32bit system:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=45134

For 64bit system:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=45154

Hope this helps!

Download files in Chrome browser using selenium WebDriver

There are situations where we need to download files from browser, and save in a specified folder on hard disk.

Find below code to download files in Chrome browser:

public class DownloadXL {
       public static void main(String[] args) {
       System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
       String downloadFilepath = "c:/download";

  HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
  chromePrefs.put("profile.default_content_settings.popups", 0);
  chromePrefs.put("download.default_directory", downloadFilepath);
  ChromeOptions options = new ChromeOptions();
  HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
  options.setExperimentalOption("prefs", chromePrefs);
  options.addArguments("--test-type");
  DesiredCapabilities cap = DesiredCapabilities.chrome();
  cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
  cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
  cap.setCapability(ChromeOptions.CAPABILITY, options);
  driver = new ChromeDriver(cap);  
                driver.get("http://www.seleniumhq.org/download/");
                driver.findElement(By.linkText("32 bit Windows IE")).click();
        }
} 

Execute JavaScript in selenium to perform operations on HTML elements

Now we know how to identify html elements using only selenium or execute javascript in selenium,

Now let's see how we can perform actions on different web elements like
textbox - how we can enter text
Button - click
How to get attribute of a html element...

For input buttons
//js.executeScript("return document.getElementsByName('commit')[0].click();")
//or
//element = (WebElement) js.executeScript("return document.getElementsByName('commit')[0];");
//((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
//or
//element.click();

Execute javaScript (locators) in selenium to identify HTML element

We have seen how to identify web elements using selenium locators...there are situations where selenium alone can't able to identify web elements, there we can execute javaScript commands in selenium...

JavaScript has it's own locators to identify web elements:

getElementById - Returns single element that matches the ID.

Play with scroll bars on a page in selenium and javaScript

There are some situations in which we want to scroll to a particular element or scroll up or down across the browser.

Selenium do not have it's own methods to perform this action, so we can use javascript to play on scroll lbars.

Let's see some of the ways:

All about JavaScriptExecutor in Selenium

As per the selenium official link on Selenium RC, core selenium is basically a javascript program (set of functions) which interprets and executes selenium commands using browser's built in javascript interpreter.

Sometimes we observe web controls doesn't react well to selenium commands, there we can directly use / execute javascript commands using webdriver,

ways to drag n drop elements using selenium

There are several web applications that provides services for drag an element and drop on certain element on browser.

Some examples:
Can customize menu bar items by drag child elements on parent element.
Drag and drop files/folders in some hierarchy manner.

JSON : basic introduction and references


JavaScript Object Notation


Used as a lightweight data sharing format in between server and web application, and also in between web applications.



which one to use? driver.close() / .quit()

There are different ways to close browser[s] using selenium after tests are run.

Depending on scenarios, if single or multiple browsers are opened, we can close or quit browser.

let's see the usage of close, quit and dispose methods.


Agile development : manifesto


A group of developers together made a decission depending on their individual views and created the methodology called Agile.

In each development life cycle, it's the learning from the previous iteration and implement to improve the process...

There are 4 major compact principles (we call manifesto) to develop software/product in a better way, which talks as:

Selenium v2.47.0 - features added

Selenium framework leaunched it's updated version 2.47.0

Download link:

and here is below some of the main features of this version:

Selenium with Autoit (no installation) for win UIs

 As most of us know, Autoit is a tool to automate basic navigations for non browser / windows applications.

There are situations in selenium automation, we get window dialog or we can say non browser related dialog which can not be automated with selenium. e.g Upload a file, download a file etc..

We will see how we can integrate Autoit with Selenium without installing Autoit.


Selenium HTML result reporting using ExtentReports 2.X

While working with Selenium automation testing, we use different 3rd party frameworks (TestNG, Junit, MBunit, Nunit) in combination with Java or .NET to report the result at the end of the test execution or we use our own dashboard/html kind of reports,

While browsing different ways of reporting, got web links of ExtentReports, most of the links talk about the version 1.x,


Connect to DataBase in Java and Selenium Implementation

For initial understanding on database and SQL queries,
refer MySQL Basics

To automate database testing, we will use selenium with java language.

JDBC (Java DataBase Connectivity) is an API (using Java language) to connect and play with database with SQL queries.


DataBase testing

Database testing: validate the front end data with the database.

Let's take an example of a e-commerce application,
user booked a mobile phone by entering phone model, shipping / billing address, and submits, Data stored into database.

Here we need to validate what the user enters data, should save exactly same to the database, then only correct device can be shipped to user.

In real time automation on database testing, user takes test data from external sources (excel or text file), enters detail on web application (then, data stores into database), then compares the external test data with the stored database data.....


Initial setup of MySQL database and it's basic

MySQL is considered to be most popular open source database,

For more information regarding versions and features, please refer http://dev.mysql.com/


Topics

  • Download and Install.
  • Initial Setup
  • Creating database tables
  • Adding/updating/deleting data to tables

Firefox profile and preferences in selenium

Firefox profile is basically the personal settings of the firefox browser.

Firefox profile contains information like your homepage, bookmarks, browser settings, history, saved passwords.

Profile is basically a specific folder stored locally in your hard drive other than your firefox installation folder.

We will see how we can set Firefox profile manually and then call in code or directly we can set the Firefox profile in code itself.


Selenium - ways to handle dropdown menus

Every web Page has at least one drop down menu bar, the bar may be horizontal or vertical.

Each item in the menu bar is a link corresponds to another page.

Menu bar have root items and in each root items we have one or more sub menus/items.

Actions on Root elements of a menu bar can be done as normal links, but sub elements are ( are hidden) only visible if we mouse hover to their corresponding root element,


selenium implicit + Explicit + fluent waits

Every browser application has it's own delay in loading the elements when we open a web application / navigate from one page to another / perform some action.

Loading depends on different criteria like internet bandwidth, technology used in the application, server capacity, no of users accessing the browser app etc...

While executing tests in different machines/environments, we need to make sure our script or code should wait till the elements load/present on the web page to perform some action upon them...

Selenium provides different ways to wait for an element on web page...

let's see them one by one -