Residing in Same package:
Example :
In the below example Sample1 is using a variable from OR , here there is no need to import any file as both files are residing in the same package , hence can be directly called .
------------------------File Name : Sample1 --------------------File1
public class Sample1
{
public static void main(String[] args)
{
WebDriver oDriver=new FirefoxDriver();
oDriver.get("https://www.google.co.in");
WebElement oTitle=oDriver.findElement(By.xpath(OR.button)); // Directly using the static variable
}
}
===================================================================
------------------------File Name : OR --------------------File2
public class OR {
public static final String button="//button[@id='gbqfba']";
}
===================================================================
Residing in Different package:
One Java file can be imported into another by using "Package" keyword .
To do this a new package has to be created with Java files to be used, residing inside .In the below eg "File_StringCheck.java" is residing inside the package "utilityfunction" .Hence the below code can access the methods from "File_StringCheck.java" by import Utilityfunction.Eg :
import Utilityfunction.File_StringCheck;
package Utilityfunction;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import jxl.*;
import jxl.write.*;
import jxl.write.Number;
import jxl.write.biff.RowsExceededException;
import jxl.read.biff.BiffException;
import jxl.write.*;
import java.util.Date;
public class Test{
{
}
}
package Utilityfunction;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import jxl.*;
import jxl.write.*;
import jxl.write.Number;
import jxl.write.biff.RowsExceededException;
import jxl.read.biff.BiffException;
import jxl.write.*;
import java.util.Date;
public class Test{
{
}
}
No comments:
Post a Comment