Simple Webdriver program to open Browser,print browser info and close Browser
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WebDriverDemo {
public static WebDriver oBrowser;
public static String sUrl="http://www.bing.com";
public static void main(String[] args)
{
boolean bIsBrowserOpened;
bIsBrowserOpened=OpenBrowser();
if(bIsBrowserOpened)
{
Get_BrowserInfo();
CloseBrowser();
}
}
public static boolean OpenBrowser()
{
try
{
oBrowser=new FirefoxDriver();
oBrowser.get(sUrl);
try
{
Thread.sleep(5000L);
}
catch(Exception e)
{
e.printStackTrace();
}
return true;
}
catch(Exception e)
{
System.err.println(e.getMessage());
return false;
}
}
public static void Get_BrowserInfo()
{
String sTitle,sSource;
sTitle=oBrowser.getTitle();
sSource=oBrowser.getPageSource();
System.out.println("Page Title =" + sTitle);
System.out.println("****************************************");
System.out.println("Page Source.......");
System.out.println(sSource);
}
public static void CloseBrowser()
{
oBrowser.close();
}
}
import org.openqa.selenium.firefox.FirefoxDriver;
public class WebDriverDemo {
public static WebDriver oBrowser;
public static String sUrl="http://www.bing.com";
public static void main(String[] args)
{
boolean bIsBrowserOpened;
bIsBrowserOpened=OpenBrowser();
if(bIsBrowserOpened)
{
Get_BrowserInfo();
CloseBrowser();
}
}
public static boolean OpenBrowser()
{
try
{
oBrowser=new FirefoxDriver();
oBrowser.get(sUrl);
try
{
Thread.sleep(5000L);
}
catch(Exception e)
{
e.printStackTrace();
}
return true;
}
catch(Exception e)
{
System.err.println(e.getMessage());
return false;
}
}
public static void Get_BrowserInfo()
{
String sTitle,sSource;
sTitle=oBrowser.getTitle();
sSource=oBrowser.getPageSource();
System.out.println("Page Title =" + sTitle);
System.out.println("****************************************");
System.out.println("Page Source.......");
System.out.println(sSource);
}
public static void CloseBrowser()
{
oBrowser.close();
}
}
No comments:
Post a Comment