package com.hr.generic;
import com.hr.automation.sahi.Button;
import com.hr.automation.sahi.Password;
import com.hr.automation.sahi.TextBox;
public class RecoveryScenarios extends DriverScript {
public boolean environmentDown()
{
return true;
}
public boolean someTechincalError()throws Throwable
{
browser.navigateTo(configProps.getProperty("URL"), true);
System.out.println("In someTechnicalError recovery");
return true;
}
public boolean unableToLoginWithCredentials() throws Throwable
{
Thread.sleep(10000);
browser.button("OK").click();
browser.navigateTo(configProps.getProperty("URL"), true);
if(TextBox.setText("username", configProps.getProperty("UserName"))==false)
{
return false;
}
if(Password.setPassword("password", configProps.getProperty("Password"))==false)
{
DriverScript.bResult = false;
return false;
}
if(Button.click("Submit")==false)
{
DriverScript.bResult = false;
return false;
}
return true;
}
public boolean singleUserLogin()throws Throwable
{
if(Button.click("OK")==false)
{
return false;
}
return true;
}
}
Tuesday, August 30, 2016
RecoveryScenarios
property
package com.hr.automation.utilities;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
public class Property {
Properties props=new Properties();
String strFileName;
String strValue;
public String getProperty(String strKey) {
try{
strValue=props.getProperty(strKey);
}
catch (Exception e) {
System.out.println(e);
}
return strValue;
}
public void setProperty(String strKey,String strValue) throws Throwable {
try{
props.setProperty(strKey, strValue);
props.store(new FileOutputStream(strFileName),null);
}
catch (Exception e) {
System.out.println(e);
}
}
public void removeProperty(String strKey){
try{
props.remove(strKey);
props.store(new FileOutputStream(strFileName),null);
}
catch (Exception e) {
System.out.println(e);
}
}
public Property(String strFileName){
this.strFileName=strFileName;
System.out.println(strFileName);
File f = new File(strFileName);
if(f.exists()){
FileInputStream in = null;
try {
in = new FileInputStream(f);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
props.load(in);
} catch (IOException e) {
e.printStackTrace();
}
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
else
System.out.println("File not found!");
}
// return environmental details
public static String getHostName() throws UnknownHostException{
InetAddress addr = InetAddress.getLocalHost();
//byte[] ipAddr = addr.getAddress();
String hostname = addr.getHostName();
return hostname;
}
}
Accessories
package com.hr.automation.utilities;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Accessories {
// return date
public static String dateStamp(){
DateFormat dateFormat = new SimpleDateFormat();
Date date = new Date();
return dateFormat.format(date).substring(0,7);
}
public static String dateFormate(){
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
return dateFormat.format(date).substring(0,10);
}
//return time and date
public static String timeStamp(){
java.util.Date today = new java.util.Date();
return new java.sql.Timestamp(today.getTime()).toString();
}
// return environmental details
public static String osEnvironment(){
return "Current suit exicuted on : "+System.getProperty("os.name")
+"/version : "+System.getProperty("os.version")
+"/Architecture : "+System.getProperty("os.arch");
}
public static String getHostName() throws UnknownHostException{
InetAddress addr = InetAddress.getLocalHost();
//byte[] ipAddr = addr.getAddress();
String hostname = addr.getHostName();
return hostname;
}
}
Monday, August 29, 2016
ReadExcelFile
/**
* @author:Soumya.D
*
* Contains Code to read excel data
*/
package com.hr.automation.utilities;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ReadExcelFile{
public List<Map<String, String>> getExcelRecords(String filePath,String sheetName)
{
HSSFRow row0=null;
HSSFWorkbook workbook=null;
HSSFSheet worksheet=null;
List<String> filtersinfoheader = new ArrayList<String>();
List<Map<String, String>> recordsList = new ArrayList<Map<String, String>>();
try
{
FileInputStream fileinputstreamobject = new FileInputStream(filePath);
workbook = new HSSFWorkbook(fileinputstreamobject);
worksheet= workbook.getSheet(sheetName);
row0=worksheet.getRow(0);
for(int i=0;row0.getCell(i)!=null;i++)
{
filtersinfoheader.add(i, row0.getCell(i).toString());
}
for(int i=1;worksheet.getRow(i)!=null;i++)
{
HashMap<String, String> recordData=new HashMap<String, String>();
for(int j=0;j<filtersinfoheader.size();j++)
{
try
{
if(worksheet.getRow(i).getCell(j)==null)
recordData.put(filtersinfoheader.get(j), null);
else if(worksheet.getRow(i).getCell(j).toString().trim().isEmpty())
recordData.put(filtersinfoheader.get(j), worksheet.getRow(i).getCell(j).toString().trim());
else
recordData.put(filtersinfoheader.get(j), worksheet.getRow(i).getCell(j).toString().trim());
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
if(recordData.get("Runmode").equalsIgnoreCase("yes"))
{
recordsList.add(recordData);
}
}
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return recordsList;
}
public List<Map<String, String>> copyExcelRecords(String filePath,String sheetName)
{
HSSFRow row0=null;
HSSFWorkbook workbook=null;
HSSFSheet worksheet=null;
List<String> filtersinfoheader = new ArrayList<String>();
List<Map<String, String>> recordsList = new ArrayList<Map<String, String>>();
try
{
FileInputStream fileinputstreamobject = new FileInputStream(filePath);
workbook = new HSSFWorkbook(fileinputstreamobject);
worksheet= workbook.getSheet(sheetName);
row0=worksheet.getRow(0);
for(int i=0;row0.getCell(i)!=null;i++)
{
filtersinfoheader.add(i, row0.getCell(i).toString());
}
for(int i=1;worksheet.getRow(i)!=null;i++)
{
HashMap<String, String> recordData=new HashMap<String, String>();
for(int j=0;j<filtersinfoheader.size();j++)
{
try
{
if(worksheet.getRow(i).getCell(j)==null)
recordData.put(filtersinfoheader.get(j), null);
else if(worksheet.getRow(i).getCell(j).toString().trim().isEmpty())
recordData.put(filtersinfoheader.get(j), worksheet.getRow(i).getCell(j).toString().trim());
else
recordData.put(filtersinfoheader.get(j), worksheet.getRow(i).getCell(j).toString().trim());
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
recordsList.add(recordData);
}
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return recordsList;
}
public List<Map<String, String>> getRunStatusYesTestSteps(String filepath,String TestStepName,List<Map<String, String>> testcases)
{
HSSFRow rowStep0=null;
HSSFWorkbook workbookstep=null;
HSSFSheet worksheetstep=null;
List<String> testStepsHeader = new ArrayList<String>();
List<Map<String, String>> testStepslist = new ArrayList<Map<String, String>>();
HashMap<String,String> map = new HashMap<String, String>();
try
{
FileInputStream fileinputstreamobject = new FileInputStream(filepath);
workbookstep = new HSSFWorkbook(fileinputstreamobject);
worksheetstep= workbookstep.getSheet(TestStepName);
rowStep0=worksheetstep.getRow(0);
for(int i=0;rowStep0.getCell(i)!=null;i++)
{
testStepsHeader.add(i, rowStep0.getCell(i).toString());
}
for (int z=0;z<testcases.size();z++){
map=(HashMap<String, String>) testcases.get(z);
for(int i=1;worksheetstep.getRow(i)!=null;i++)
{
if(worksheetstep.getRow(0).getCell(0).toString().equals("Test Case ID") && map.get("Test Case ID").equals(worksheetstep.getRow(i).getCell(0).toString()))
{
HashMap<String, String> recordsData=new HashMap<String, String>();
for(int j=0;j<testStepsHeader.size();j++)
{
if(worksheetstep.getRow(i).getCell(j)==null)
recordsData.put(testStepsHeader.get(j), null);
else if(worksheetstep.getRow(i).getCell(j).toString().trim().isEmpty())
recordsData.put(testStepsHeader.get(j), worksheetstep.getRow(i).getCell(j).toString().trim());
else
recordsData.put(testStepsHeader.get(j), worksheetstep.getRow(i).getCell(j).toString().trim());
}
testStepslist.add(recordsData);
}
}
}
System.out.println(testStepslist.size());
}catch (Exception e) {
e.printStackTrace();
}
return testStepslist;
}
}
GenericActionKewords
/**
* @author:Soumya.D
*
* Contains Code related sahi actions and methods
*/
package com.hr.generic;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.Map;
import config.Constants;
import net.sf.sahi.client.Browser;
import net.sf.sahi.client.ElementStub;
import com.hr.automation.sahi.Button;
import com.hr.automation.sahi.CheckBox;
import com.hr.automation.sahi.Div;
import com.hr.automation.sahi.Image;
import com.hr.automation.sahi.Password;
/*import com.hr.automation.sahi.SahiSuit;*/
import com.hr.automation.sahi.Span;
import com.hr.automation.sahi.TableCell;
import com.hr.automation.sahi.TextArea;
import com.hr.automation.sahi.TextBox;
import com.hr.automation.utilities.Accessories;
import config.Constants;
public class GenericActionKeywords extends DriverScript {
static SimpleDateFormat dateformat = new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
static Date d = new Date();
public void launchAndNavigate(ArrayList<String> testData) throws Throwable
{
try
{
browser = new Browser(testData.get(0));
configProps.setProperty("BrowserType", testData.get(0));
browser.open();
// writing URL to configprops to use URL for recovery scenarios
//configProps.setProperty("URL", testData.get(1));
// browser.navigateTo(testData.get(1));
CommonKeywords.getURL();
browser.navigateTo(configProps.getProperty("URL"));
}
catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method launchAndNavigate | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return;
}
DriverScript.bResult = true;
}
public void login(ArrayList<String> objectIdentifier,ArrayList<String> testData) throws Throwable
{
try
{
if (browser.heading3("Sahi 5xx Error").exists())
{
DriverScript.bResult = false;
return;
}
configProps.setProperty("UserName", testData.get(0));
configProps.setProperty("Password", testData.get(1));
configProps.setProperty("UserNameIdentifier", objectIdentifier.get(0));
configProps.setProperty("PasswordIdentifier", objectIdentifier.get(1));
if (TextBox.setText(objectIdentifier.get(0), testData.get(0)) == false)
{
DriverScript.bResult = false;
return;
}
if (Password.setPassword(objectIdentifier.get(1), testData.get(1)) == false)
{
DriverScript.bResult = false;
return;
}
if (Button.click("Submit") == false)
{
DriverScript.bResult = false;
return;
}
if (browser.label("Invalid Credentials.").exists())
{
DriverScript.bResult = false;
return;
}
if (browser.heading1("Some Technical error occured").exists())
{
if (recoveryScenario.someTechincalError())
{
DriverScript.bResult = false;
return;
}
}
if (browser.span("Unable to login with the credentials provided. Please login again.").exists())
{
if (recoveryScenario.unableToLoginWithCredentials())
{
DriverScript.bResult = false;
return;
}
}
if (Span.isSpanExist("Confirm"))
{
if (recoveryScenario.singleUserLogin())
{
DriverScript.bResult = false;
return;
}
}
DriverScript.bResult = true;
}
catch (Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method login | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return;
}
}
public static void closeBrowser() throws Throwable
{
try {
Log.info("Closing the browser");
browser.kill();
browser.close();
}
catch (Exception e)
{
Log.error("Class GenericActionKeywords | Method closeBrowser | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
}
public void navigateToSubTab(ArrayList<String> objectIdentifier)throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
if (Span.isSpanExist(objectIdentifier.get(0)))
{
if (Span.click(objectIdentifier.get(0)) == false)
{
DriverScript.bResult = false;
return;
}
}
else
{
DriverScript.bResult = false;
return;
}
browser.setStrictVisibilityCheck(false);
Thread.sleep(2000);
browser.setStrictVisibilityCheck(true);
if (Span.isSpanExist(objectIdentifier.get(1)))
{
if (Span.click(objectIdentifier.get(1)) == false)
{
DriverScript.bResult = false;
return;
}
}
else
{
DriverScript.bResult = false;
return;
}
browser.setStrictVisibilityCheck(false);
}
catch(Exception e)
{
Log.error("Class GenericActionKeywords | Method navigateToSubTab | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
e.printStackTrace();
return;
}
DriverScript.bResult = true;
}
public void buttonClick(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
if (!Button.isButtonDisabled(objectIdentifier.get(0)))
{
browser.button(objectIdentifier.get(0).toString()).click();
}
else
{
DriverScript.bResult = false;
return;
}
Thread.sleep(10000);
browser.setStrictVisibilityCheck(false);
}
catch (Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method buttonClick | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return;
}
DriverScript.bResult = true;
}
public void uploadFile(ArrayList<String> objectIdentifier,ArrayList<String> testData) throws Throwable
{
try
{
String urlToUpload = getUploadUrl(testData.get(0));
String attachFilePath = Constants.Path_Uploads+"\\"+testData.get(1);
if (configProps.getProperty("BrowserType").equalsIgnoreCase("ie")) {
browser.focusWindow();
browser.waitFor(1000);// needed
// focus on the element
browser.focus(browser.file("attachment"));
// click "space" to bring up the browser dialog
Robot r2 = new Robot();
r2.keyPress(java.awt.event.KeyEvent.VK_SPACE);
// java.awt.event.KeyEvent.VK_SPACE
browser.waitFor(1000);
// type the file path
if (!typeNative(attachFilePath)) {
DriverScript.bResult = false;
return;
}
browser.waitFor(1000);
// press enter
r2.keyPress(java.awt.event.KeyEvent.VK_ENTER);
browser.waitFor(1000);
}
else
{
browser.setStrictVisibilityCheck(true);
browser.setFile2(browser.file(objectIdentifier.get(0)),
attachFilePath, urlToUpload);
Thread.sleep(10000);
browser.execute("_sahi._call(_sahi._textbox('"
+ objectIdentifier.get(1) + "').value='"
+ attachFilePath + "');");
browser.waitFor(10000);
browser.setStrictVisibilityCheck(false);
}
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method uploadFile | Exception desc : "+e.getMessage());
return;
}
DriverScript.bResult = true;
}
public boolean typeNative(String str) throws NoSuchFieldException,SecurityException, IllegalArgumentException, IllegalAccessException
{
Robot robot = null;
try
{
robot = new Robot();
}
catch (AWTException e)
{
e.printStackTrace();
return false;
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
int keyCode = Character.codePointAt(str, i);
boolean shiftKey = false;
switch (c) {
case '~': {
shiftKey = true;
keyCode = KeyEvent.VK_BACK_QUOTE;
break;
}
case '`': {
keyCode = KeyEvent.VK_BACK_QUOTE;
break;
}
case '!': {
shiftKey = true;
keyCode = KeyEvent.VK_1;
break;
}
case '@': {
shiftKey = true;
keyCode = KeyEvent.VK_2;
break;
}
case '#': {
shiftKey = true;
keyCode = KeyEvent.VK_3;
break;
}
case '$': {
shiftKey = true;
keyCode = KeyEvent.VK_4;
break;
}
case '%': {
shiftKey = true;
keyCode = KeyEvent.VK_5;
break;
}
case '^': {
shiftKey = true;
keyCode = KeyEvent.VK_6;
break;
}
case '&': {
shiftKey = true;
keyCode = KeyEvent.VK_7;
break;
}
case '*': {
shiftKey = true;
keyCode = KeyEvent.VK_8;
break;
}
case '(': {
shiftKey = true;
keyCode = KeyEvent.VK_9;
break;
}
case ')': {
shiftKey = true;
keyCode = KeyEvent.VK_0;
break;
}
case '_': {
shiftKey = true;
keyCode = KeyEvent.VK_MINUS;
break;
}
case '+': {
shiftKey = true;
keyCode = KeyEvent.VK_EQUALS;
break;
}
case '{': {
shiftKey = true;
keyCode = KeyEvent.VK_OPEN_BRACKET;
break;
}
case '}': {
shiftKey = true;
keyCode = KeyEvent.VK_CLOSE_BRACKET;
break;
}
case ':': {
shiftKey = true;
keyCode = KeyEvent.VK_SEMICOLON;
break;
}
case '\"': {
shiftKey = true;
keyCode = KeyEvent.VK_QUOTE;
break;
}
case '\'': {
keyCode = KeyEvent.VK_QUOTE;
break;
}
case '<': {
shiftKey = true;
keyCode = KeyEvent.VK_COMMA;
break;
}
case '>': {
shiftKey = true;
keyCode = KeyEvent.VK_PERIOD;
break;
}
case '?': {
shiftKey = true;
keyCode = KeyEvent.VK_SLASH;
break;
}
case '\\': {
keyCode = KeyEvent.VK_BACK_SLASH;
break;
}
}
if ((keyCode >= 97 && keyCode <= 122)
|| (keyCode >= 65 && keyCode <= 90)) {
shiftKey = (keyCode >= 65 && keyCode <= 90);
String variableName = "VK_" + ("" + c).toUpperCase();
Class clazz = KeyEvent.class;
Field field = clazz.getField(variableName);
keyCode = field.getInt(null);
}
if (shiftKey)
robot.keyPress(KeyEvent.VK_SHIFT);
try {
robot.keyPress(keyCode);
robot.keyRelease(keyCode);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (shiftKey)
robot.keyRelease(KeyEvent.VK_SHIFT);
}
}
return true;
}
public String getUploadUrl(String uploadURL) {
String uploadUrl = null;
try
{
if (configProps.getProperty("URL").contains("stag")) {
uploadUrl = "https://ondemandstag.receivablesradius.com/RRDMSProject/dms/"
+ uploadURL;
} else if (configProps.getProperty("URL").contains("test")) {
uploadUrl = "https://ondemandtest.receivablesradius.com/RRDMSProject/dms/"
+ uploadURL;
} else {
uploadUrl = "https://ondemand.receivablesradius.com/RRDMSProject/dms/"
+ uploadURL;
}
}
catch(Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method getUploadUrl | Exception desc : "+e.getMessage());
return null;
}
return uploadUrl;
}
public boolean selectDropDownValueByLabel(ArrayList<String> objectIdentifier, ArrayList<String> testData)throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
browser.image("/x-form-trigger x-form-arrow-/")
.near(browser.label(objectIdentifier.get(0).toString()))
.click();
browser.div(testData.get(0).toString())
.in(browser.div("/x-layer x-combo-list/")).click();
browser.setStrictVisibilityCheck(false);
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method selectDropDownValueByLabel | Exception desc : "+e.getMessage());
return false;
}
DriverScript.bResult = true;
return true;
}
public void advancedSearchByMultipleFeilds(ArrayList<String> objectIdentifier, ArrayList<String> testData) throws Throwable
{
// ArrayList<String> elementIdentifier=new ArrayList<>();
// elementIdentifier.add(0, "div_Payment Batches");
if (!advancedSearchStart()) {
DriverScript.bResult = false;
return;
}
if (!setMultipleFieldsDatabyType(objectIdentifier, testData)) {
DriverScript.bResult = false;
return;
}
if (!advancedSearchEnd()) {
DriverScript.bResult = false;
return;
}
DriverScript.bResult = true;
}
public boolean setMultipleFieldsDatabyType( ArrayList<String> objectIdentifier, ArrayList<String> testData) throws Throwable
{
try {
ArrayList<String> identifier = new ArrayList<String>();
ArrayList<String> data = new ArrayList<String>();
if (!(objectIdentifier.size() == testData.size()))
{
System.out.println("objectIdentifier and testdata size is different");
DriverScript.bResult = false;
return false;
}
for (int i = 0; i < objectIdentifier.size(); i++)
{
String a = objectIdentifier.get(i);
identifier.add(0, a);
data.add(0, testData.get(i));
if (!setValueByFieldType(identifier, data))
{
identifier.remove(0);
data.remove(0);
DriverScript.bResult = false;
return false;
}
identifier.remove(0);
data.remove(0);
}
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method setMultipleFieldsDatabyType | Exception desc : "+e.getMessage());
return false;
}
DriverScript.bResult = true;
return true;
}
public enum FieldType {
TEXTBOX, TEXTAREA, DROPDOWN, PICKLIST;
}
public boolean setValueByFieldType(ArrayList<String> objectIdentifier,ArrayList<String> testData) throws Throwable
{
try
{
String[] objectIdentifiers = objectIdentifier.get(0).split("~");
ArrayList<String> identifier = new ArrayList<String>();
browser.setStrictVisibilityCheck(true);
switch (FieldType.valueOf(objectIdentifiers[0])) {
case TEXTBOX:
if (!TextBox.setText(objectIdentifiers[1], testData.get(0))) {
DriverScript.bResult = false;
return false;
}
break;
case TEXTAREA:
if (!TextArea.setText(objectIdentifiers[1], testData.get(0))) {
DriverScript.bResult = false;
return false;
}
break;
case DROPDOWN:
identifier.add(0, objectIdentifiers[1]);
if (!selectDropDownValueByLabel(identifier, testData))
{
DriverScript.bResult = false;
return false;
}
break;
case PICKLIST:
identifier.add(0, objectIdentifiers[1]);
identifier.add(1, objectIdentifiers[2]);
identifier.add(2, objectIdentifiers[3]);
identifier.add(3, objectIdentifiers[4]);
identifier.add(4, objectIdentifiers[5]);
browser.setStrictVisibilityCheck(true);
if (!selectValueFromPickList(identifier, testData))
{
DriverScript.bResult = false;
return false;
}
break;
}
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method setValueByFieldType | Exception desc : "+e.getMessage());
return false;
}
DriverScript.bResult = true;
return true;
}
public boolean selectValueFromPickList(ArrayList<String> objectIdentifier, ArrayList<String> testData)
throws Throwable {
try {
try {
System.out.println(objectIdentifier.size());
System.out.println(objectIdentifier.get(4));
browser.setStrictVisibilityCheck(true);
if(objectIdentifier.get(4).equalsIgnoreCase("textbox"))
{
browser.image(Integer.parseInt(objectIdentifier.get(1))).near(browser.textbox(objectIdentifier.get(0))).click();
}
else if(objectIdentifier.get(4).equalsIgnoreCase("label"))
{
browser.image(Integer.parseInt(objectIdentifier.get(1))).near(browser.label(objectIdentifier.get(0))).click();
}
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method selectValueFromPickList | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return false;
}
browser.setStrictVisibilityCheck(false);
if (browser.div(objectIdentifier.get(2)).exists()) {
browser.textbox(Integer.parseInt(objectIdentifier.get(3)))
.near(browser.div(objectIdentifier.get(2)))
.setValue(testData.get(0));
browser.execute("_sahi._keyPress(_sahi._textbox(1, _sahi._near(_sahi._div('"
+ objectIdentifier.get(2) + "'))),[13,13])");
try {
browser.setStrictVisibilityCheck(true);
browser.div(testData.get(0))
.near(browser.div(objectIdentifier.get(2))).click();
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method selectValueFromPickList | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return false;
}
if (!Button.click("Select")) {
DriverScript.bResult = false;
return false;
}
if (browser.span("Please select a record.").exists()) {
DriverScript.bResult = false;
return false;
}
} else {
DriverScript.bResult = false;
return false;
}
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method selectValueFromPickList | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
return true;
}
public boolean advancedSearchStart() throws Throwable {
try {
browser.setStrictVisibilityCheck(true);
if (Button.click("/Advanced Search/") == false) {
DriverScript.bResult = false;
return false;
}
if (Button.click("/Clear/") == false) {
DriverScript.bResult = false;
return false;
}
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method advancedSearchStart | Exception desc : "+e.getMessage());
return false;
}
DriverScript.bResult = true;
return true;
}
public boolean advancedSearchEnd() throws Throwable {
try
{
browser.setStrictVisibilityCheck(true);
if (Button.click("/^Search/") == false) {
DriverScript.bResult = false;
return false;
}
if (Button.click("/Hide/") == false) {
DriverScript.bResult = false;
return false;
}
browser.setStrictVisibilityCheck(false);
}
catch(Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method advancedSearchEnd | Exception desc : "+e.getMessage());
return false;
}
DriverScript.bResult = true;
return true;
}
public void waitForElement(ArrayList<String> ObjectIdentifiers)
throws Throwable {
try {
ElementStub elem = new ElementStub(ObjectIdentifiers.get(0).split(
"~")[0], browser, ObjectIdentifiers.get(0).split("~")[1]);
int waitCount = 1;
do {
if (waitCount >= 21)
break;
waitCount++;
Thread.sleep(3000);
} while (!elem.exists());
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method waitForElement | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return;
}
DriverScript.bResult = true;
}
public long getTotalRecordsFromTheGrid(ArrayList<String> ObjectIdentifiers)
throws Throwable {
long totalRecordsCount = 0;
Thread.sleep(10000);
refreshGrid();
browser.setStrictVisibilityCheck(true);
if (Div.isDivExist("x-grid-empty") == true) {
totalRecordsCount = 0;
DriverScript.dynamicValue.put(sdynamicValueName,String.valueOf(totalRecordsCount));
return totalRecordsCount;
} else {
try {
browser.setStrictVisibilityCheck(true);
String recordCount = browser
.fetch("_sahi._div({className:'xtb-text',id:'/ext-comp-/',sahiText:'/"
+ ObjectIdentifiers.get(0) + "/'}).innerHTML");
browser.setStrictVisibilityCheck(false);
totalRecordsCount = Long.parseLong(recordCount.split("of")[1]
.trim());
DriverScript.dynamicValue.put("totCountOfRecords",String.valueOf(totalRecordsCount));
DriverScript.dynamicValue.put(sdynamicValueName,String.valueOf(totalRecordsCount));
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method getTotalRecordsFromTheGrid | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return 0;
}
}
browser.setStrictVisibilityCheck(true);
DriverScript.bResult = true;
return totalRecordsCount;
}
public void refreshGrid() throws Throwable {
try {
browser.setStrictVisibilityCheck(true);
if (Button.isButtonVisible("/ x-btn-text x-tbar-loading/")) {
if (!Button.click("/ x-btn-text x-tbar-loading/")) {
DriverScript.bResult = false;
return;
}
} else {
DriverScript.bResult = false;
return;
}
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method refreshGrid | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return;
}
DriverScript.bResult = true;
}
public void validateIfMultupleRecordsExistWithSameField(
ArrayList<String> ObjectIdentifiers) throws Throwable {
long numOfRec = getTotalRecordsFromTheGrid(ObjectIdentifiers);
if (numOfRec != 1 ) {
DriverScript.bResult = false;
return;
} else {
DriverScript.bResult = true;
}
}
public void doubleClickOnFirstRecord(ArrayList<String> ObjectIdentifiers)
throws Throwable {
try {
String randomvalue=browser.div(0)
.under(browser.div(ObjectIdentifiers.get(0).toString())).getText();
browser.div(0)
.under(browser.div(ObjectIdentifiers.get(0).toString()))
.doubleClick();
DriverScript.dynamicValue.put("randomValue", randomvalue);
DriverScript.dynamicValue.put(sdynamicValueName, randomvalue);
} catch (Exception e) {
DriverScript.bResult = false;
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method doubleClickOnFirstRecord | Exception desc : "+e.getMessage());
return;
}
DriverScript.bResult = true;
}
public boolean validateActualValueInDetailsOrGrid(
String typeOfnearByOrUnderEl, String nearByOrUnderEl,
int posNearOrUnderEl, String compareValue, String action,
String gridOrDetails, String scenario) throws Throwable {
browser.setStrictVisibilityCheck(true);
String valueInApp = "";
Thread.sleep(10000);
switch (typeOfnearByOrUnderEl) {
case "LABEL":
valueInApp = browser.div(posNearOrUnderEl)
.near(browser.label(nearByOrUnderEl)).getText();
break;
case "DIV":
valueInApp = browser.div(posNearOrUnderEl)
.under(browser.div(nearByOrUnderEl)).getText();
break;
default:
break;
}
System.out.println("value in app:=>" + valueInApp);
System.out.println("compare value is:=>" + compareValue);
if (valueInApp.equals(compareValue)) {
} else {
return false;
}
browser.setStrictVisibilityCheck(false);
return true;
}
public void verifyCountofRecordsOnGrid(ArrayList<String> ObjectIdentifiers)
throws Throwable {
long totalNumberOfRecords = getTotalRecordsFromTheGrid(ObjectIdentifiers);
if (totalNumberOfRecords == 0 || totalNumberOfRecords == -1) {
Log.info("Total number of records on the Grid:"
+ totalNumberOfRecords);
comments="Records are not available on the grid to edit/delete/unlink/print";
DriverScript.bResult = false;
} else {
Log.info("Total number of records on the Grid:"
+ totalNumberOfRecords);
DriverScript.bResult = true;
}
}
/**
* By Divya on Jun 23 to select the random number from the grid
*/
public void selectRecordRandomlyFromGrid(ArrayList<String> ObjectIdentifiers)
throws Throwable {
try {
int randumNumber = getRandumNumberFromTheGrid(ObjectIdentifiers
.get(0).toString());
Thread.sleep(3000);
configProps.setProperty("RANDUMNUMBER",
String.valueOf(randumNumber));
browser.setStrictVisibilityCheck(true);
String value = browser.div(randumNumber)
.under(browser.div(ObjectIdentifiers.get(1).toString()))
.getText();
Thread.sleep(3000);
browser.div(randumNumber)
.under(browser.div(ObjectIdentifiers.get(1).toString()))
.click();
//DriverScript.dynamicValue.put("randomRecordValue", value);
DriverScript.dynamicValue.put(sdynamicValueName, value);
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
DriverScript.bResult = false;
}
}
/**
* By Divya on Jun 23 to get the random number from the grid
*/
public int getRandumNumberFromTheGrid(String gridrecordCountText)
throws Throwable {
int recRandNum = 0;
try {
browser.setStrictVisibilityCheck(true);
String recCount = browser
.fetch("_sahi._div({className:'xtb-text',sahiText:'/"
+ gridrecordCountText + "/'}).innerHTML");
browser.setStrictVisibilityCheck(false);
String gridRec = recCount.split("-")[1].trim();
int Max = Integer.parseInt(gridRec.split("of")[0].trim());
int Min = 1;
recRandNum = Min + (int) (Math.random() * ((Max - Min) + 1));
recRandNum = recRandNum - 1;
return recRandNum;
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method getRandumNumberFromTheGrid | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
return recRandNum;
}
public void splitButtonClick(ArrayList<String> ObjectIdentifiers)
throws Throwable {
try {
browser.setStrictVisibilityCheck(true);
TableCell.nearByClick(ObjectIdentifiers.get(0).toString(),
browser.emphasis(ObjectIdentifiers.get(1).toString()));
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
Log.error("Class ActionsKeyWord | Method SplitButtonClick | Exception desc : "
+ e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void spanClick(ArrayList<String> ObjectIdentifiers) throws Throwable
{
try
{
if(isSpanExist(ObjectIdentifiers))
{
browser.setStrictVisibilityCheck(true);
browser.span(ObjectIdentifiers.get(0)).click();
browser.setStrictVisibilityCheck(false);
DriverScript.bResult = true;
}
}
catch (Exception e)
{ e.printStackTrace();
Log.error("Class GenericActionKeywords | Method spanClick | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
}
public boolean isSpanExist(ArrayList<String> objectIdentifier)throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
if(Span.isSpanExist(objectIdentifier.get(0)) == true)
{
DriverScript.bResult = true;
browser.setStrictVisibilityCheck(false);
return true;
}
else
{
DriverScript.bResult = false;
browser.setStrictVisibilityCheck(false);
return false;
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method isSpanExist | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
browser.setStrictVisibilityCheck(false);
return false;
}
}
/**By Divya
* To Select the Check Box
* Parameters:Identifier of the checkbox*/
public void selectCheckBox(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
if(CheckBox.isCheckboxExist(objectIdentifier.get(0)))
{
browser.setStrictVisibilityCheck(true);
browser.checkbox(objectIdentifier.get(0)).check();
browser.setStrictVisibilityCheck(false);
}
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult=false;
Log.error("Class GenericActionKeywords | Method selectCheckBox | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void checkRadioButton(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
if(browser.radio(objectIdentifier.get(0)).exists())
{
browser.setStrictVisibilityCheck(true);
browser.radio(objectIdentifier.get(0)).click();
browser.setStrictVisibilityCheck(false);
}
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult=false;
Log.error("Class GenericActionKeywords | Method checkRadioButton | Exception desc : "+e.getMessage());
}
DriverScript.bResult=true;
}
public int getDropDownItems(ArrayList<String> objectIdentifier)
{
int dropdownCount=0;
try
{
browser.setStrictVisibilityCheck(true);
browser.image("/x-form-trigger x-form-arrow-/").
near( browser.textbox(objectIdentifier.get(0))).click();
Thread.sleep(8000);
dropdownCount = browser.div("/x-combo-list-item/").in(browser.div("/x-combo-list-inner/")).countSimilar();
browser.image("/x-form-trigger x-form-arrow-/").near( browser.textbox(objectIdentifier.get(0))).click();
browser.setStrictVisibilityCheck(false);
String CountOfRecords=String.valueOf(dropdownCount);
DriverScript.dynamicValue.put("CountOfRecorsdInDropDown", CountOfRecords);
}catch (Exception e) {
e.printStackTrace();
DriverScript.bResult=false;
Log.error("Class GenericActionKeywords | Method getDropDownItems | Exception desc : "+e.getMessage());
}
DriverScript.bResult=true;
return dropdownCount;
}
public void countOfRecordsInDropDownBeforeOrAfter(ArrayList<String> ObjectIdentifiers,ArrayList<String> testData) throws Throwable
{
try
{
if(testData.contains("before"))
{
int numOfRecBefore = getDropDownItems(ObjectIdentifiers);
DriverScript.dynamicValue.put("numOfRecBefore", String.valueOf(numOfRecBefore));
Log.info("Before Count"+numOfRecBefore);
}
else
{
int numOfRecAfter= getDropDownItems(ObjectIdentifiers);
DriverScript.dynamicValue.put("numOfRecAfter", String.valueOf(numOfRecAfter));
Log.info("Before Count"+numOfRecAfter);
}
}
catch (Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method countOfRecordsInDropDownBeforeOrAfter | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void clickonclosebutton(ArrayList<String> ObjectIdentifiers) throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
browser.div("/x-tool-close/").near(browser.span(ObjectIdentifiers.get(0).toString())).click();
browser.setStrictVisibilityCheck(false);
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method clickonclosebutton | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void countValidationAfterAdvancedSearch(
ArrayList<String> ObjectIdentifiers,ArrayList<String> testData) throws Throwable {
try
{
long noOfRec = Long.parseLong(testData.get(0).toString());
long numOfRec = getTotalRecordsFromTheGrid(ObjectIdentifiers);
if (numOfRec == noOfRec ) {
DriverScript.bResult = true;
} else {
DriverScript.bResult = false;
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method clickonclosebutton | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void countOfRecordsOnGridBeforeAndAfter(ArrayList<String> ObjectIdentifiers, ArrayList<String> testData) throws Throwable
{
try
{
if(testData.get(0).toString().contains("Before"))
{
long numOfRecBefore = getTotalRecordsFromTheGrid(ObjectIdentifiers);
DriverScript.dynamicValue.put("numOfRecBefore", String.valueOf(numOfRecBefore));
Log.info("Before count"+numOfRecBefore);
}
else
{
long numOfRecAfter= getTotalRecordsFromTheGrid(ObjectIdentifiers);
DriverScript.dynamicValue.put("numOfRecAfter", String.valueOf(numOfRecAfter));
Log.info("After count"+numOfRecAfter);
}
DriverScript.bResult = true;
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method countOfRecordsOnGridBeforeAndAfter | Exception desc : "+e.getMessage());
}
}
public void countValidationBeforeAndAfter(ArrayList<String> testData) throws Throwable
{
try
{
long numOfRecBefore=Long.parseLong(testData.get(0).toString());
long numOfRecAfter=Long.parseLong(testData.get(1).toString());
long number=Long.parseLong(testData.get(2));
if (numOfRecBefore+number == numOfRecAfter )
{
DriverScript.bResult = true;
} else
{
DriverScript.bResult = false;
}
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method countValidationBeforeAndAfter | Exception desc : "+e.getMessage());
}
}
public void selectDropDownValue(ArrayList<String> objectIdentifier, ArrayList<String> testData)throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
browser.image("/x-form-trigger x-form-arrow-/").
near( browser.textbox(objectIdentifier.get(0).toString())).click();
browser.div(testData.get(0).toString())
.in(browser.div("/x-layer x-combo-list/")).click();
browser.setStrictVisibilityCheck(false);
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method selectDropDownValue | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void addTimeStampToVariable(ArrayList<String> testData)throws Throwable
{
try
{
DriverScript.dynamicValue.put("timeStopValue",testData.get(0).concat(Accessories.timeStamp()));
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method addTimeStampToVariable | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void closeOtherTabs(ArrayList<String> objectIdentifier){
try
{
browser.setStrictVisibilityCheck(true);
browser.span(objectIdentifier.get(0)).rightClick();
browser.span("Close Other Tabs").click();
browser.setStrictVisibilityCheck(false);
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method closeOtherTabs | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void nearByClickOnImage(ArrayList<String> objectIdentifier) throws Throwable
{
browser.setStrictVisibilityCheck(true);
try
{
if(Image.nearByClick(0, browser.label(objectIdentifier.get(0)))==false)
{
DriverScript.bResult = false;
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
DriverScript.bResult = true;
}
public void nearBySetTextInTextbox(ArrayList<String> objectIdentifier,ArrayList<String> testData) throws Throwable
{
browser.setStrictVisibilityCheck(true);
try
{
if(TextBox.nearBySetText(1, browser.span(objectIdentifier.get(0)), testData.get(0))==false)
{
DriverScript.bResult = false;
}
else
{
browser.execute("_sahi._keyPress(_sahi._textbox(1, _sahi._near(_sahi._div(\""+objectIdentifier.get(0)+"\"))),[13,13])");
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
browser.setStrictVisibilityCheck(false);
}
public void divClick(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
if(Div.click(objectIdentifier.get(0))==false)
{
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void divDoubleClick(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
if(Div.doubleClick(objectIdentifier.get(0))==false)
{
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method divDoubleClick | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void selectMultipleRecordsRandomlyFromGrid(ArrayList<String> ObjectIdentifiers)
throws Throwable {
int randumNumber1;
int randumNumber2;
try {
randumNumber1 = getRandumNumberFromTheGrid(ObjectIdentifiers
.get(0).toString());
randumNumber2 = getRandumNumberFromTheGrid(ObjectIdentifiers
.get(0).toString());
while(randumNumber1==randumNumber2)
{
randumNumber2 = getRandumNumberFromTheGrid(ObjectIdentifiers
.get(0).toString());
}
Thread.sleep(3000);
browser.setStrictVisibilityCheck(true);
String values1 = browser.div(randumNumber1)
.under(browser.div(ObjectIdentifiers.get(1).toString()))
.getText();
String values2 = browser.div(randumNumber2)
.under(browser.div(ObjectIdentifiers.get(1).toString()))
.getText();
Thread.sleep(3000);
browser.div(randumNumber1)
.under(browser.div(ObjectIdentifiers.get(1).toString()))
.click();
Thread.sleep(3000);
browser.click(browser.div(randumNumber2)
.under(browser.div(ObjectIdentifiers.get(1).toString())),"CTRL");
DriverScript.dynamicValue.put("randomRecordValues", values1+","+values2);
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method selectMultipleRecordsRandomlyFromGrid | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public boolean isDivExist(ArrayList<String> objectIdentifier)throws Throwable
{
try
{
if(!Div.isDivExist(objectIdentifier.get(0)))
{
DriverScript.bResult = false;
return false;
}
else
{
DriverScript.bResult = true;
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method isDivExist | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return false;
}
return true;
}
public String appendRandomNumToString(ArrayList<String> testData)throws Throwable
{
String testDataMod;
try
{
int Min=1;
int Max=2000;
int randNum=Min + (int)(Math.random() * ((Max - Min) + 1));
testDataMod=testData.get(0)+randNum;
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method appendRandomNumToString | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return null;
}
DriverScript.bResult = true;
return testDataMod;
}
public void selectNumberFromDropDown(ArrayList<String> objectIdentifier, ArrayList<String> testData)throws Throwable
{
try
{
Thread.sleep(10000);
browser.setStrictVisibilityCheck(true);
/*browser.image("/x-form-trigger x-form-arrow-/")
.near(browser.label(objectIdentifier.get(0).toString()))
.click();*/
BigDecimal bd = new BigDecimal(testData.get(0));
long it=bd.longValue();
String value=String.valueOf(it);
Double num=Double.parseDouble(testData.get(0));
System.out.println("num"+num);
browser.image("/x-form-trigger x-form-arrow-/").
near( browser.textbox(objectIdentifier.get(0).toString())).click();
browser.div(value)
.in(browser.div("/x-layer x-combo-list/")).click();
browser.setStrictVisibilityCheck(false);
}
catch (Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method selectNumberFromDropDown | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void divUnderClick(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
browser.div(objectIdentifier.get(1)).under(browser.div(objectIdentifier.get(0))).click();
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method divUnderClick | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void getDownloadSession() throws Throwable
{
try
{
browser.sendHTMLResponseAfterFileDownload(true);
browser.addToSession(CommonKeywords.addToSessionURL());
}catch (Exception e) {
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method getDownloadSession | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void downloadPopupWindow(ArrayList<String> testData) throws Throwable
{
try
{
//attach path
String attachFilePath;
if(System.getProperty("os.name").contains("Linux"))
{
attachFilePath=baseProjectPath.concat("/Results/");
}else
{
attachFilePath=baseProjectPath.concat("\\Results\\");
}
//download path
String downloadPath=attachFilePath.concat(testData.get(0)+"[" + CommonKeywords.getStartTime() + "].pdf");
String s1=browser.lastDownloadedFileName() ;
int p=1;
while( p==1)
{
browser.execute("_sahi._wait(120000, _sahi._lastDownloadedFileName() != null);");
if(!(browser.lastDownloadedFileName()==null))
{
browser.saveDownloadedAs(downloadPath);
break;
}
}
s1=browser.lastDownloadedFileName();
Log.info("Last downloaded file:");
Log.debug(s1);
browser.clearLastDownloadedFileName();
System.out.println("last downloaded file:"+s1);
browser.popup("/File Downloaded/").link("Close Window").click();
//file check
File f = new File(downloadPath);
if(f.exists())
{
Log.info("File exists");
comments="Sucessfully downloaded the file";
}
else
{
Log.info("File not found!");
comments="Failed to download the file";
DriverScript.bResult = false;
}
}catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method downloadPopupWindow | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void getCurrentDate()throws Throwable
{
try
{
DriverScript.dynamicValue.put("dateValue",Accessories.dateFormate());
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method addTimeStampToVariable | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
public void nearByClick(ArrayList<String> objectIdentifier) throws Throwable
{
browser.setStrictVisibilityCheck(true);
try
{
if(Span.nearByClick(objectIdentifier.get(0), browser.span(objectIdentifier.get(1)))==false)
{
DriverScript.bResult = false;
return;
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
DriverScript.bResult = true;
}
public void selectFirstRecordFromPickList(ArrayList<String> objectIdentifier)
throws Throwable {
try {
browser.setStrictVisibilityCheck(true);
if(TextBox.isTextboxExist(objectIdentifier.get(1)))
{
browser.image(Integer.parseInt(objectIdentifier.get(2))).near(browser.textbox(objectIdentifier.get(1))).click();
long numOfRecords=getTotalRecordsFromTheGrid(objectIdentifier);
System.out.println("No of records"+numOfRecords);
if(numOfRecords >= 1)
{
browser.div(objectIdentifier.get(4))
.under(browser.div(objectIdentifier.get(3))).click();
String value=browser.div(objectIdentifier.get(4))
.under(browser.div(objectIdentifier.get(3))).getText();
dynamicValue.put("recordText", value);
if (!Button.click("Select")) {
DriverScript.bResult = false;
}
if (browser.span("Please select a record.").exists()) {
browser.div(objectIdentifier.get(3))
.under(browser.div(objectIdentifier.get(2))).click();
}
browser.setStrictVisibilityCheck(false);
}
else
{
comments="There are no records to select value from picklist";
DriverScript.bResult = false;
}
}
} catch (Exception e) {
e.printStackTrace();
browser.image(Integer.parseInt(objectIdentifier.get(2)))
.near(browser.textbox(objectIdentifier.get(1))).highlight();
Log.error("Class GenericActionKeywords | Method selectFirstRecordFromPickList | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
DriverScript.bResult = true;
}
public void selectFirstValueFromDropdown(ArrayList<String> objectIdentifier)throws Throwable
{
String Item1;
try
{
browser.setStrictVisibilityCheck(true);
browser.image("/x-form-trigger x-form-arrow-/").
near( browser.textbox(objectIdentifier.get(0).toString())).click();
long dropdownCount = browser.div("/x-combo-list-item/").in(browser.div("/x-combo-list-inner/")).countSimilar();
String Item=browser.div(1)
.in(browser.div("/x-layer x-combo-list/")).getText();
if(!Item.equals(""))
{
browser.div(1)
.in(browser.div("/x-layer x-combo-list/")).click();
dynamicValue.put(sdynamicValueName,Item);
}
else if(dropdownCount > 1)
{
Item1=browser.div(2)
.in(browser.div("/x-layer x-combo-list/")).getText();
browser.div(2)
.in(browser.div("/x-layer x-combo-list/")).click();
dynamicValue.put(sdynamicValueName,Item1);
browser.setStrictVisibilityCheck(false);
}
else
{
Log.info("There are no items under dropdown");
DriverScript.bResult = false;
return;
}
}
catch (Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method selectFirstValueFromDropdown | Exception desc : "+e.getMessage());
return;
}
DriverScript.bResult = true;
}
public boolean isLinkExist(ArrayList<String> objectIdentifier)throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
if(browser.link(objectIdentifier.get(0)).exists()==true)
{
browser.link(objectIdentifier.get(0)).highlight();
}
browser.setStrictVisibilityCheck(false);
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class GenericActionKeywords | Method isLinkExist | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return false;
}
DriverScript.bResult = true;
return true;
}
public void logout()
{
browser.setStrictVisibilityCheck(true);
try
{
if(browser.heading3("Sahi 5xx Error").exists())
{
bResult = false;
return ;
}
if(Button.click(" x-btn-text icon-gear"))
{
bResult = true;
}
else
{
bResult = false;
return ;
}
if(Span.click("Logout"))
{
bResult = true;
}
else
{
bResult = false;
return ;
}
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
bResult = true;
}
public void reLogin() throws Throwable
{
//Logout
try
{
logout();
ArrayList<String> loginIdentifiers = new ArrayList<String>();
ArrayList<String> loginCrendentials= new ArrayList<String>();
loginIdentifiers.add(0,configProps.getProperty("UserNameIdentifier"));
loginIdentifiers.add(1,configProps.getProperty("PasswordIdentifier"));
loginCrendentials.add(0,configProps.getProperty("UserName"));
loginCrendentials.add(1,configProps.getProperty("Password"));
login(loginIdentifiers, loginCrendentials);
bResult = false;
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
bResult = false;
}
}
public void nearByButtonClick(ArrayList<String> objectIdentifier) throws Throwable
{
browser.setStrictVisibilityCheck(true);
try
{
browser.button(objectIdentifier.get(0)).near(browser.span(objectIdentifier.get(1))).click();
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
DriverScript.bResult = true;
}
public void divInByButtonClick(ArrayList<String> objectIdentifier) throws Throwable
{
browser.setStrictVisibilityCheck(true);
try
{
browser.button(objectIdentifier.get(0)).in(browser.div(objectIdentifier.get(1))).click();
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
DriverScript.bResult = true;
}
public void divNearByDivClick(ArrayList<String> objectIdentifier,ArrayList<String> testData) throws Throwable
{
browser.setStrictVisibilityCheck(true);
try
{
browser.div(testData.get(0).toString()).near(browser.div(objectIdentifier.get(0))).click();
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class "+this.getClass().getName()+" | Method "+Thread.currentThread().getStackTrace()[1].getMethodName()+" | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
browser.setStrictVisibilityCheck(false);
DriverScript.bResult = true;
}
public void divUnderClickByIndex(ArrayList<String> objectIdentifier) throws Throwable
{
try
{
browser.setStrictVisibilityCheck(true);
browser.div(Integer.parseInt(objectIdentifier.get(1))).under(browser.div(objectIdentifier.get(0))).click();
browser.setStrictVisibilityCheck(false);
} catch (Exception e) {
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class GenericActionKeywords | Method divUnderClickByIndex | Exception desc : "+e.getMessage());
}
DriverScript.bResult = true;
}
}
Driverscript
/**
* @author:Soumya.D
*
* Contains Code for driving the testcase execution
*/
package com.hr.generic;
import java.io.File;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.sahi.client.Browser;
import org.testng.annotations.Test;
import config.Constants;
import com.hr.automation.utilities.Property;
import com.hr.automation.utilities.ReadExcelFile;
public class DriverScript {
public static GenericActionKeywords genericActionKeywords;
public static DmsActionKeywords dmsactionKeywords;
public static EippActionKeywords eippActionKeywords;
public static DisActionKeywords disActionKeywords;
public static boolean bResult;
public static String sTestCaseID;
public static String sRunMode;
public static String sTestCaseName;
public static int iTestStep;
public static int iTestLastStep;
public static String sActionKeyword;
public static String sData;
public static String sObjIdentifier;
public static String sEnvironment;
public static Method method;
public static HashMap<String,String> dynamicValue = new HashMap<String, String>();
public static String comments ="";
static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
static Date startAt=null,endAt=null;
static String startTime="",endTime="";
public static String baseProjectPath=System.getProperty("user.dir");
public static Property configProps=new Property("config.properties");
public static RecoveryScenarios recoveryScenario=new RecoveryScenarios();
public static Browser browser;
public static String sdynamicValueName;
@Test
public void driverScript() throws Throwable
{
try
{
genericActionKeywords = new GenericActionKeywords();
dmsactionKeywords = new DmsActionKeywords();
disActionKeywords= new DisActionKeywords();
eippActionKeywords = new EippActionKeywords();
//******Code to read list of excels that need to be executed*******
ReadExcelFile readTestCase=new ReadExcelFile();
List<Map<String, String>> sheetsToRunList = new ArrayList<Map<String, String>>();
HashMap<String,String> sheetToRun = new HashMap<String, String>();
sheetsToRunList=readTestCase.getExcelRecords(Constants.Path_TestData+"SheetsToRun.xls",Constants.Sheet_SheetsToRun);
if(sheetsToRunList.equals(null))//TODO EOF
{
Log.error("Class Utils | Method driverScript | Exception desc : getExcelRecords returns null");
return ;
}
String sDestPath="";
for(int iSheetsToRunList=0;iSheetsToRunList<sheetsToRunList.size();iSheetsToRunList++)
{
sheetToRun=(HashMap<String, String>) sheetsToRunList.get(iSheetsToRunList);
sDestPath=Constants.Path_Results+sheetToRun.get("SheetToRun")+"_"+CommonKeywords.getStartTime()+".xls";
ExcelUtils.fileCopy(Constants.Path_TestData+sheetToRun.get("SheetToRun")+".xls",sDestPath);
System.out.println("SheetToRun "+sheetToRun.get("SheetToRun"));
configProps.setProperty("DestPath", sDestPath);
ExcelUtils.setExcelFile(sDestPath);
//to get envi from SheetToRun sheet
sEnvironment=sheetToRun.get("Environment");
configProps.setProperty("ENVIRONMENT",sEnvironment);
System.out.println("env"+sEnvironment);
execute_TestCase();
}
configProps.setProperty("URL", "Null");
dynamicValue.clear();
}
catch(Exception e)
{
e.printStackTrace();
Log.error("Class Utils | Method driverScript | Exception desc : "+e.getMessage());
return;
}
}
private void execute_TestCase() throws Throwable
{
int iTotalTestCases = ExcelUtils.getRowCount(Constants.Sheet_TestCases);
System.out.println("iTotalTestCases "+iTotalTestCases);
for(int iTestcase=1;iTestcase<iTotalTestCases;iTestcase++)
{
bResult = true;
sTestCaseID = ExcelUtils.getCellData(iTestcase, Constants.Col_TestCaseID, Constants.Sheet_TestCases);
sRunMode = ExcelUtils.getCellData(iTestcase, Constants.Col_RunMode,Constants.Sheet_TestCases);
sTestCaseName = ExcelUtils.getCellData(iTestcase, Constants.Col_TestCaseName,Constants.Sheet_TestCases);
//sEnvironment=ExcelUtils.getCellData(iTestcase, Constants.Col_ENVIRONMENT,Constants.Sheet_TestCases);
//configProps.setProperty("ENVIRONMENT",sEnvironment);
if(sRunMode.equalsIgnoreCase("YES"))
{
Log.startTestCase(sTestCaseID);
startAt=new Date();
startTime = dateformat.format(startAt);
configProps.setProperty("TestCaseName", sTestCaseName);
iTestStep = ExcelUtils.getRowContains(sTestCaseID, Constants.Col_TestCaseID, Constants.Sheet_TestSteps);
iTestLastStep = ExcelUtils.getTestStepsCount(Constants.Sheet_TestSteps, sTestCaseID, iTestStep);
bResult=true;
for (;iTestStep<iTestLastStep;iTestStep++)
{
sActionKeyword = ExcelUtils.getCellData(iTestStep, Constants.Col_ActionKeyword,Constants.Sheet_TestSteps);
sData = ExcelUtils.getCellData(iTestStep, Constants.Col_TestData, Constants.Sheet_TestSteps);
sObjIdentifier= ExcelUtils.getCellData(iTestStep, Constants.Col_ObjIdentifier, Constants.Sheet_TestSteps);
sdynamicValueName=ExcelUtils.getCellData(iTestStep, Constants.Col_DynamicValueName, Constants.Sheet_TestSteps);
execute_Actions();
if(bResult==false)
{
endAt=new Date();
endTime = dateformat.format(endAt);
ExcelUtils.setCellData(Constants.KEYWORD_FAIL,iTestcase,Constants.Col_Result,Constants.Sheet_TestCases);
ExcelUtils.setCellData(startTime,iTestcase,Constants.Col_StartTime,Constants.Sheet_TestCases);
ExcelUtils.setCellData(endTime,iTestcase,Constants.Col_EndTime,Constants.Sheet_TestCases);
Log.endTestCase(sTestCaseID);
genericActionKeywords.reLogin();
break;
}
}
if(bResult==true)
{
endAt=new Date();
endTime = dateformat.format(endAt);
ExcelUtils.setCellData(Constants.KEYWORD_PASS,iTestcase,Constants.Col_Result,Constants.Sheet_TestCases);
ExcelUtils.setCellData(startTime,iTestcase,Constants.Col_StartTime,Constants.Sheet_TestCases);
ExcelUtils.setCellData(endTime,iTestcase,Constants.Col_EndTime,Constants.Sheet_TestCases);
Log.endTestCase(sTestCaseID);
}
}
}
}
private static void execute_Actions() throws Throwable
{
try
{
ArrayList<String> ObjectIdentifierList = new ArrayList<String>();
String []objectIdentifiers=null;
ArrayList<String> TestDataList = new ArrayList<String>();
String []testData=null;
Class<?>[] paramTypeArrayLsit=null;
Object[] paramArrayData ;
if(sObjIdentifier.contains(","))
{
objectIdentifiers=sObjIdentifier.split(",");
for(int i=0;i<objectIdentifiers.length;i++)
{
ObjectIdentifierList.add(i, objectIdentifiers[i]);
}
}
else
{
if(sObjIdentifier.equals(""))
{}
else
{
ObjectIdentifierList.add(0, sObjIdentifier);
}
}
if(sData.contains(","))
{
testData=sData.split(",");
for(int i=0;i<testData.length;i++)
{
TestDataList.add(i, testData[i]);
}
//code to read the test data and replace dynamic value
int index=0;
if(sData.contains("dynamicValue") )
{
for(int lCount=0;lCount<TestDataList.size();lCount++)
{
if(TestDataList.get(lCount).contains("dynamicValue") )
{
String dynamicSplitValue[]=TestDataList.get(lCount).split("~");
String data=dynamicSplitValue[1];
TestDataList.set(lCount, dynamicValue.get(data));
}
}
}
}
else
{
if(sData.equals(""))
{}
else
{
TestDataList.add(0, sData);
if(TestDataList.get(0).contains("dynamicValue") )
{
String dynamicSplitValue[]=TestDataList.get(0).split("~");
String data=dynamicSplitValue[1];
TestDataList.set(0, dynamicValue.get(data));
}
}
}
//Removed repeated steps for every product:By Sadguna
if(ObjectIdentifierList.size() ==0 && TestDataList.size()==0)
{
paramTypeArrayLsit =new Class[]{};
paramArrayData= new ArrayList<?>[]{};
}
else if(ObjectIdentifierList.size() >0 && TestDataList.size()>0)
{
paramTypeArrayLsit = new Class[]{ArrayList.class,ArrayList.class};
paramArrayData= new ArrayList<?>[]{ObjectIdentifierList,TestDataList};
}
else if(ObjectIdentifierList.size() >0 && TestDataList.size()==0)
{
paramTypeArrayLsit = new Class[]{ArrayList.class};
paramArrayData=new ArrayList<?>[]{ObjectIdentifierList};
}
else
{
paramTypeArrayLsit = new Class[]{ArrayList.class};
paramArrayData=new ArrayList<?>[]{TestDataList};
}
//Switch to call methods
String []numOfProducts = {"dms","eipp","dis"};
int products;
for(products=0;products<numOfProducts.length;products++)
{
if(sActionKeyword.contains(numOfProducts[products]))
break;
}
switch(products)
{
case 0:
Class<?> dmsActionKeyword_obj = dmsactionKeywords.getClass();
method = dmsActionKeyword_obj.getMethod(sActionKeyword,paramTypeArrayLsit );
method.invoke(dmsactionKeywords,paramArrayData);
break;
case 1:
Class<?> eippActionKeyword_obj = eippActionKeywords.getClass();
method = eippActionKeyword_obj.getMethod(sActionKeyword,paramTypeArrayLsit );
method.invoke(eippActionKeywords,paramArrayData);
break;
case 2:
Class<?> disActionKeyword_obj = disActionKeywords.getClass();
method = disActionKeyword_obj.getMethod(sActionKeyword,paramTypeArrayLsit );
method.invoke(disActionKeywords,paramArrayData);
break;
default:
Class<?> actionKeyword_obj = genericActionKeywords.getClass();
method = actionKeyword_obj.getMethod(sActionKeyword,paramTypeArrayLsit );
method.invoke(genericActionKeywords,paramArrayData);
}
if(bResult==true){
ExcelUtils.setCellData(Constants.KEYWORD_PASS, iTestStep, Constants.Col_TestStepResult, Constants.Sheet_TestSteps);
if(!comments.isEmpty())
{
ExcelUtils.setCellData(comments,iTestStep,Constants.Col_Comments,Constants.Sheet_TestSteps);
}
}
else{
ExcelUtils.setCellData(Constants.KEYWORD_FAIL, iTestStep, Constants.Col_TestStepResult, Constants.Sheet_TestSteps);
if(!comments.isEmpty())
{
ExcelUtils.setCellData(comments,iTestStep,Constants.Col_Comments,Constants.Sheet_TestSteps);
}
//CAll to take screen shot method
takeScreenshot();
//GenericActionKeywords.closeBrowser();
}
comments="";
}
catch(Exception e)
{
e.printStackTrace();
DriverScript.bResult = false;
Log.error("Class Utils | Method execute_Actions | Exception desc : "+e.getMessage());
return ;
}
}
/**By Divya on Jun 23
* To capture the screen shot of the test execution on failure*/
public static void takeScreenshot() throws Throwable {
try {
String filePath = baseProjectPath + "/Screenshots/"
+ DriverScript.sTestCaseName +CommonKeywords.getStartTime()+ ".jpg";
File file = new File(filePath);
if (file.exists())
file.delete();
browser.focusWindow();
browser.takeScreenShot(filePath);
Thread.sleep(1000);
if (file.exists())
ExcelUtils.setCellData(filePath, DriverScript.iTestStep,
Constants.Col_ScreenShotonFAILURE,
Constants.Sheet_TestSteps);
} catch (Exception e) {
e.printStackTrace();
DriverScript.bResult = false;
}
}
}
Subscribe to:
Posts (Atom)