Friday, October 4, 2013

Selenium : Properties File [Updated]

Selenium : Properties File [Updated]

 

Create a  properties file
  1. Open Eclipse
  2. Inside a package> Rt Clk> New >File 
  3. File Name = OR.properties
  4. Click OK
 [ Inside OR.properties  ]
----------------------------------------------------------------------------
Google.search_button=//button[@id='gbqfba']
youtube_link=//a[@id='gb_36']/span[2]


 --------------------------------------------------------------------------

 // [Main Function ]


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Sample1
{
    public static void main(String[] args) throws IOException  
    {
      
        Properties oProp=new Properties();    //create properties object
        FileInputStream oFilestream= new FileInputStream("C:\\Selenium\\Sample_Workspace\\Sample\\src\\OR.properties");                                 //Open properties file using Fileinputstream
        oProp.load(oFilestream);                    //Load FileInputStream into properties object
      
        FirefoxDriver oDriver=new FirefoxDriver();
        oDriver.get("http://google.com");
      
        WebElement oSearch=oDriver.findElementByXPath(oProp.getProperty("Google.search_button"));

//Access properties 
 
        Misc_Operations.highlightElement(oDriver, oSearch);
          
    }
  
}

No comments:

Post a Comment