Monday, 16 September 2013

Selenium Automation Framework Design (Data Driven Framework)

Data Driven  Frame Work 

Data Driven framework  means using a single test to verify many different of possible inputs which is given by the end user.Data-driven testing to separate test logic from test data by replacing hard-coded values in your automated tests with the variable. We can use use Spread sheets or 
Sql for same.
 
How to access excel sheet data by using java code

1.If we need to test  Log in functionality with different 2  user id and password then  we create  xls file and create odbc connection .
2 How to established odbc Connection

-start>>Control pannel>>Administrative tools>>Datasource>>User Dsn>>Add >>Driver>>driver do Microsoft xls>>select your excel file >>save
3.Java Selenium code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Excel {
   
   
    public static void main(String[] argv) throws Exception {
       
        WebDriver driver=new FirefoxDriver();
        String baseUrl = "http://excilysbank.aws.af.cm/";
        driver.get(baseUrl);
       
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:excel");
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("Select * from [Sheet1$]");

           
           
            String UserId,Password;
            while (rs.next()) {
       
           
            UserId=rs.getString("UserId");
            System.out.println(UserId);
           
           
           
             
            Password=rs.getString("Password");
            System.out.println(Password);
       
           
             driver.get(baseUrl + "/public/login.html");
                driver.findElement(By.id("username")).sendKeys(UserId);
                driver.findElement(By.id("password")).sendKeys(Password);
                driver.findElement(By.cssSelector("input.button.blue")).click();
                driver.findElement(By.linkText("PERSONNAL_CHECKING")).click();
                driver.findElement(By.linkText("November")).click();
                driver.findElement(By.linkText("December")).click();
                driver.findElement(By.linkText("January")).click();
                driver.findElement(By.linkText("February")).click();
                driver.findElement(By.linkText("Log out")).click();
           


       

        }
           

            st.close();
            con.close();
            } catch (Exception ex) {
            System.err.print("Exception: ");
            System.err.println(ex.getMessage());
            }
       
       
     
    }
     

  }



No comments:

Post a Comment