FitNesse Program
Sample FitNesse program,
package com.SamplePackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class FirstClass
{
WebDriver driver;
//Constructor method
public FirstClass(String browser, String baseURL)
{
if (browser.equalsIgnoreCase("*iexplore"))
{
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
else if (browser.equalsIgnoreCase("*firefox"))
{
driver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("*chrome"))
{
driver = new ChromeDriver();
}
}
public boolean open(String URL) {
driver.get(URL);
return true;
}
public boolean type(String locator, String value) {
try{
driver.findElement(ByLocator(locator)).sendKeys(value);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public boolean click(String locator) {
try{
driver.findElement(ByLocator(locator)).click();
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public boolean verifyResultPage(String locator) {
try{
driver.findElement(ByLocator(locator));
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public boolean close() {
driver.quit();
return true;
}
private By ByLocator(String locator) {
// To get By Class value
String[] array = locator.split("~");
if (array[0] == "css" ) {return By.cssSelector(array[1]); }
else if (array[0] == "id" ) {return By.id(array[1]); }
else if (array[0] == "name" ) {return By.name(array[1]); }
else if (array[0] == "link" ) {return By.partialLinkText(array[1]); }
return null;
}
}
package com.SamplePackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class FirstClass
{
WebDriver driver;
//Constructor method
public FirstClass(String browser, String baseURL)
{
if (browser.equalsIgnoreCase("*iexplore"))
{
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
else if (browser.equalsIgnoreCase("*firefox"))
{
driver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("*chrome"))
{
driver = new ChromeDriver();
}
}
public boolean open(String URL) {
driver.get(URL);
return true;
}
public boolean type(String locator, String value) {
try{
driver.findElement(ByLocator(locator)).sendKeys(value);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public boolean click(String locator) {
try{
driver.findElement(ByLocator(locator)).click();
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public boolean verifyResultPage(String locator) {
try{
driver.findElement(ByLocator(locator));
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public boolean close() {
driver.quit();
return true;
}
private By ByLocator(String locator) {
// To get By Class value
String[] array = locator.split("~");
if (array[0] == "css" ) {return By.cssSelector(array[1]); }
else if (array[0] == "id" ) {return By.id(array[1]); }
else if (array[0] == "name" ) {return By.name(array[1]); }
else if (array[0] == "link" ) {return By.partialLinkText(array[1]); }
return null;
}
}