Selenium Tutorials

Keyword Driven Framework Example

In this framework, keywords are developed which are equal to a unit level functionality. It is an independent framework which perform automation based on the keywords specified in the excel sheet. Based on the type of application, the number of keywords will be increased to handle different functionalities.

The below are the few keywords which are used commonly in the web applications.

Scrolling web page with Selenium Webdriver using java

We can scroll the web page using javaScript Executor in the java code.We have taken the below example with three different scenarios of scrolling a webpage.

1. We may require to scroll to bottom of the page and then perform operations. For this scenario we have created a test 'scrollingToBottomofAPage'/

Read data from Properties file using Java Selenium

In Selenium .properties files are mainly used to store GUI locators / elements, and also Global fields like database configuration details

'.properties' files are mainly used in Java programs to maintain project configuration data, database config or project settings etc. Each parameter in properties file are stored as a pair of strings, in key and value format, where each key is on one line. You can easily read properties from some file using object of type Properties.

Below is a example program which demonstrate to read the data from .properties file using Java.

Uploading a file with sendKeys method

The Easy way of uploading a file is simple case of just finding the element and typing the absolute path of the document into it.

It is mandatory that it works only when the textbox is enabled. So please make sure that the input element is visible. In the below example 'uploadsubmit' is the name of that element and in 'sendKeys()' we have to specify the absolute path of the content that we want to upload (that can be file/image/video etc).

Sample HTML Code should look similar to this :

Upload file using AutoIT

With the help of AutoIt tool (open source tool) we can upload by transferring the control from Selenium webdriver to AutoIt.

We need to explicitly call the AutoIt script from our program.

About AutoIT : AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

We need to call the AutoIt script after clicking on the upload button. Immediately after clicking on Upload button, the control should be transferred to AutoIt by the below statement which takes care of uploading the file.

Test Configuration File / Executable File

In order to create a test suite and run separate test cases, we need framework which drives the automation. Here testng.xml can be called as "driver" which drives several test cases automated using selenium code.

Advantage of using TestNG with Selenium is of running multiple test cases from multiple classes using xml configuration file

Another advantage of testng.xml is for entire teams that need to share their test configuration or to be able to specify different parameters or subsets of their tests in different testng.xml files

Reporting Structure in Selenium Automation Framework

Reports / Executed Results

Test report/results document which contains summary of test activities performed with pass/fail status and the time taken for execution.

After completing the execution, it is very important to communicate the test results and findings to the project manager and with that decisions can be made for the release.

Test Data in automation framework

Data Set / Test Data

Data set stores the data files, Script reads test data from external data sources and executes test based on it.

Typically the data input can be anything:

  • MS Excel files
  • Data base
  • Text files
  • XML files….etc.

External test data must be easily editable by test engineers without any programming skills. Excel files are the ones that used most often and are familiar with it.