In selenium if we create a single ton class, it means we create a single instance of that class and we can use single instance at multiple places, below is the code which you give a brief idea of single ton class. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields
In we use single instance of webdriver it means only one browser would open at a time
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
static WebDriver webDriver=null;
public static WebDriver webDriver(){
if(webDriver==null)
{
webDriver= new FirefoxDriver();
}
return webDriver;
}
2) I created a another class on same or different package and in that class I will create this webdriver.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.interactions.Actions;
import defineelement.elementdetials;
public class Cssfind extends homepageclick{
/**Create single instance of webdriver.**/
static WebDriver driver = elementdetials.webDriver();
public void FirefoxProfile () {
ProfilesIni profile = new ProfilesIni();
org.openqa.selenium.firefox.FirefoxProfile ffprofile =
profile.getProfile("Profiles/1le2ettt.default");
}
/** Open url **/
public void openurl(){
driver.get(elementdetials.baseurl);
}
/** Maximumsize of Windows **/
public void maximumwindows()
{
driver.manage().window().maximize();
System.out.println("Current url of page" + driver.getCurrentUrl());
}
/**Check header or data of applicaiton**/
public void header ()
{
WebElement lockcss = driver.findElement(By.cssSelector(".col-md-3"));
String a = lockcss.getCssValue("color");
String bordercolor = lockcss.getCssValue("font-family");
System.out.println("testing" + a);
System.out.println("testing" + bordercolor);
WebElement a1 = driver.findElement(By.cssSelector(".flexnev_home"));
System.out.println(a1 );
}
}
In we use single instance of webdriver it means only one browser would open at a time
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
1) it is one classpublic class elementdetials {
static WebDriver webDriver=null;
public static WebDriver webDriver(){
if(webDriver==null)
{
webDriver= new FirefoxDriver();
}
return webDriver;
}
2) I created a another class on same or different package and in that class I will create this webdriver.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.interactions.Actions;
import defineelement.elementdetials;
public class Cssfind extends homepageclick{
/**Create single instance of webdriver.**/
static WebDriver driver = elementdetials.webDriver();
public void FirefoxProfile () {
ProfilesIni profile = new ProfilesIni();
org.openqa.selenium.firefox.FirefoxProfile ffprofile =
profile.getProfile("Profiles/1le2ettt.default");
}
/** Open url **/
public void openurl(){
driver.get(elementdetials.baseurl);
}
/** Maximumsize of Windows **/
public void maximumwindows()
{
driver.manage().window().maximize();
System.out.println("Current url of page" + driver.getCurrentUrl());
}
/**Check header or data of applicaiton**/
public void header ()
{
WebElement lockcss = driver.findElement(By.cssSelector(".col-md-3"));
String a = lockcss.getCssValue("color");
String bordercolor = lockcss.getCssValue("font-family");
System.out.println("testing" + a);
System.out.println("testing" + bordercolor);
WebElement a1 = driver.findElement(By.cssSelector(".flexnev_home"));
System.out.println(a1 );
}
}
No comments
Post a Comment