RSS

Selenium: Create New frame work First Phase

04 Jan

In Selenium we have to first assign keyword for that scripts(create common functions which we can use in any classes).

package Test;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class keyword

{

private static final String String = null;

public static WebDriver driver;

public static By Byelement (String Type, String Path)

{

if (Type.equals(“id”))
{
return By.id(Path);
}

else if (Type.equals(“className”))
{
return By.className(Path);
}

else if (Type.equals(“name”))
{
return By.name(Path);
}

kevalshah.in

else if (Type.equals(“xpath”))
{
return By.xpath(Path);
}

else if (Type.equals(“tagName”))
{
return By.tagName(Path);
}

else if (Type.equals(“cssSelector”))
{
return By.cssSelector(Path);
}

else if (Type.equals(“linkText”))
{
return By.linkText(Path);
}

else
{
return By.id(Path);
}

}

public static void clickElement(String Type,String Path)
{
driver.findElement(Byelement(Type, Path)).click();
}

public static void clearElement(String Type,String Path)
{
driver.findElement(Byelement(Type, Path)).clear();
}

public static void insertElement(String Type,String Path,String key)
{
driver.findElement(Byelement(Type, Path)).sendKeys(key);
}

public static WebElement hover(String Type,String String)
{
return driver.findElement(Byelement(Type, String));
}

public static void hoverclick(String Type,String Path)
{
driver.findElement(Byelement(Type, Path)).click();
}

public static void refresh()
{
driver.navigate().refresh();
}

public static void back()
{
driver.navigate().back();
}
public static void forward()
{
driver.navigate().forward();
}

public static Alert alertSwitch()
{
return driver.switchTo().alert();
}

public static String getAtribute(String Type, String Path, String Value)
{
return driver.findElement(Byelement(Type, Path)).getAttribute(Value);
}

public static void submitForm(String Type,String Path)
{
driver.findElement(Byelement(Type, Path)).submit();
}

public static void openURL(String url)
{
driver.get(url);
}

public static java.lang.String currentURL()
{
return driver.getCurrentUrl();
}

public static String getText(String Type,String Path)
{
return driver.findElement(Byelement(Type, Path)).getText();
}

public static WebElement webElementClass(String Type, String Path)
{
return driver.findElement(Byelement(Type, Path));
}

public static void actionClass(WebElement string2)
{
Actions action = new Actions(driver);
action.moveToElement(string2).build().perform();
}

public static void WebDriverWait(String Type, String Path)
{
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(Byelement(Type, Path)));
}

public static void dropdownByIndex(String Type, String path, int Index)
{
Select select = new Select (driver.findElement(Byelement(Type, path)));
select.selectByIndex(Index);
select.getOptions();
//select.selectByValue(arg0);
//select.deselectByVisibleText(arg0);
}

public static void dropdownByText(String Type, String path, String Text)
{
Select select = new Select (driver.findElement(Byelement(Type, path)));
//select.selectByIndex(Index);
select.getOptions();
//select.selectByValue(arg0);
select.selectByVisibleText(Text);
}

public static void dropdownByValue(String Type, String path, String Value)
{
Select select = new Select (driver.findElement(Byelement(Type, path)));
//select.selectByIndex(Index);
select.getOptions();
select.selectByValue(Value);
//select.selectByVisibleText(Value);
}

}

kevalshah.in

Advertisements
 

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: