Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Running Selenium Tests on different browsers using Junit

Many web applications need to be tested on different browsers to check their compatibilities with various browsers.

When using JUnit, we can run a test on different browsers without actually changing the value of browser after one test execution. With the Parameterization option that is available with latest changes of Junit, this can be implemented very easily.

See the example below. With the example, you can execute your automation tests in multiple browsers without actually waiting to finish your tests and then passing the second and third browser value.

Let's test Selenium Master Login Test Case in 3 browsers.

Test Case:

Print

How to use Java Client Driver

When automating test cases with Selenium Java Client Driver, you need to follow the steps below.

  • Extract selenium-java-<version-number>.jar file
  • Open your desired Java IDE (Eclipse, NetBeans, IntelliJ, Netweaver, etc.)
  • Create a java project.
  •  Add the selenium-java-<version-number>.jar files to your project as references.
  •  Add to your project classpath the file selenium-java-<version-number>.jar.
  •  From Selenium-IDE, export a script to a Java file and include it in your Java project, or write your Selenium test in Java using the selenium-java-client API.
  • You can either use JUnit, or TestNg to run your test, or you can write your own simple main() program.
  •  Run Selenium server from the console.
  •  Execute your test from the Java IDE or from the command-line.
Print

Install Selenium Webdriver with Eclipse and Java

To use Selenium WebDriver with Java JUnit or TestNG, you need to install a Java Development IDE. There are many options available like : Eclipse and IntellJ. Here I explain how to download and install Selenium WebDriver with Eclipse and Java step by step.

Step 1: download and install Java in your system.

You need to install JDK (Java development kit) in your system. Java may have been installed on your system. Refer to the article "Test Java for Selenium WebDriver" for more information.

Step 2: download and install Eclipse

download Eclipse for Java developers, extract the zip file, and save it in any drive. Download URL is : http://www.eclipse.org/downloads/index.php

Please remember that depending on the 32 or 64 bit on your PC, you need to install related package.

Print

Test Java for Selenium WebDriver

To setup and configure Selenium WebDriver with Eclipse and Java, user should download and install Java on the computer where the test application will be running.

You need to install JDK (Java development kit) in your system.

Generally speaking, Java is used by many applications, so it may have been installed on the PC. Before installing Java, users can check if Java has been installed on the computer.

Step 1: Navigate to Google site on Firefox and search for "Java Tester".

Step 2: In the search result, click on the test applet - Java link (this is an official Java site to test Java version on your PC).

Step 3: Click on the Verify Java Version button on the page.

Print

Selenium Webdriver Data-Driven Framework

Selenium Webdriver Data-Driven Framework is where test input and output values are from data files (ODBC sources, CVS files, Excel files, and DAO objects) and are loaded into variables in captured or manually coded scripts.

In this framework, variables are used for both the input values and output verification values. The framework should include navigation through the program, reading of the data files, and logging of test status and information. All the processes should be in the test scripts. The framework should have the following features:

  • Well defined architectural design
  • Less time to test large data
  • Script execution in multiple environments
  • Easier, faster, and efficient analysis of result logs
  • Communication of results
  • Easy debugging and scrip tmaintenance
  • Robust and stable due to error and exception handling
  • 100% reliability of utility scripts, online execution and report packages.

Framework Architecture Design

Automation architecture package should include:

Print

Selenium Model View Controller Test Framework Part 4 - Main Script

MySimpleScript.java

package com.seleniummaster.qa.script;

import static org.junit.Assert.*;

import com.seleniummaster.qa.framework.ScriptBase;
import com.seleniummaster.qa.framework.controller.*;
import com.thoughtworks.selenium.*;

import static com.seleniummaster.qa.framework.AppConstant.*;

import org.junit.Test;

public class MySimpleScript extends ScriptBase {

    @Test
    public void Mytest1() {
        //run this test four times
        for(int i=1;i<5;i++)
        {
        CalculateMonthlyPaymentControl paymentCalculate1=new CalculateMonthlyPaymentControl(selenium);
        
        paymentCalculate1.calculatePayment(HOMEVALUE, CREDITPROFILE, DOWNPAYMENT, LOANPURPOSE, INTERESTRATE, LOANTERM, STARTMONTH, STARTYEAR, PROPERTYTAX, PMI);
        
        paymentCalculate1.captureScreen("c:\\finaltestnew"+i+".png");
        paymentCalculate1.calculateNow();
        paymentCalculate1.verifyResult("$2,254.80");
    }
    }

Print

Selenium Model View Controller Test Framework Part 4 - Model

CalculatorMonthlyPaymentModel.java


package com.seleniummaster.qa.model;

public class CalculatorMonthlyPaymentModel {

public String HomeValueTextBox()
    {
        return "id=PurchasePriceTextbox";
    }
public String CreditProfileDropDownList()
{
    return "id=CreditProfileDropdownlist";
}
public String downPaymentInputBox()
{
    return "id=DownPaymentTextBox";
}
public String LoanPurposeDropDownList()
{
    return "id=LoanPurposeDropDownList1";
   
}
public String InterestRateTextBox()
{
    return "id=InterestRateTextbox";
}
public String LoanTermTextBox()
{
    return "id=LoanTermTextBox";
}
public String StartMonthDropDownList()
{
    return "id=StartDateMonthDropdownlist";
}
public String StartYearDropDownList()
{
    return "id=StartDateYearDropdownlist";
}
public String PropertyTaxTextBox()
{
    return "id=PropertyTaxTextbox";
}
public String PMITextBox()
{
    return "id=PropertyInsuranceTextbox";
}
public String CalculateButton()
{
    return "id=CalculateMonthlyPaymentButton";
}
public String resultvalue()
{
    return "id=MonthlyPaymentLabel";
}
}

Print

Selenium Model View Controller Test Framework Part 4 - Controller

CalculateMonthlyPaymentControl.java

package com.seleniummaster.qa.framework.controller;

import junit.framework.Assert;

import com.seleniummaster.qa.model.*;
import com.thoughtworks.selenium.Selenium;

public class CalculateMonthlyPaymentControl {
    
private Selenium selenium=null;
private CalculatorMonthlyPaymentModel model;

public CalculateMonthlyPaymentControl(Selenium selenium)
{
    this.selenium=selenium;
    model=new CalculatorMonthlyPaymentModel();
}