Selenium : Properties File [Updated]
Create a properties file
- Open Eclipse
- Inside a package> Rt Clk> New >File
- File Name = OR.properties
- Click OK
----------------------------------------------------------------------------
Google.search_button=//button[@id='gbqfba']
youtube_link=//a[@id='gb_36']/span[2]
--------------------------------------------------------------------------
// [Main Function ]
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