/**
* @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;
}
}
Monday, August 29, 2016
GenericActionKewords
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;
}
}
}
Excelutils
/**
* @author:Soumya.D
*
* Contains Code related to excel sheet
*/
package com.hr.generic;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
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;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import com.hr.automation.utilities.ReadExcelFile;
import config.Constants;
public class ExcelUtils extends DriverScript{
private static HSSFRow ExcelRow;
private static HSSFWorkbook ExcelWBook;
private static HSSFSheet ExcelWSheet;
private static org.apache.poi.hssf.usermodel.HSSFCell ExcelCell;
public static void setExcelFile(String Path) throws Exception
{
try
{
FileInputStream ExcelFile = new FileInputStream(Path);
ExcelWBook = new HSSFWorkbook(ExcelFile);
}
catch (Exception e)
{
e.printStackTrace();
Log.error("Class Utils | Method setExcelFile | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
}
public static int getRowCount(String SheetName){
int iNumber=0;
try {
ExcelWSheet = ExcelWBook.getSheet(SheetName);
iNumber=ExcelWSheet.getPhysicalNumberOfRows();
//cell.setCellType(Cell.CELL_TYPE_STRING);
//ExcelWSheet.getRow(iNumber).getCell(0).setCellType(Cell.CELL_TYPE_STRING);
//ExcelWSheet.getRow(iNumber).getCell(0).setCellValue(true);
} catch (Exception e){
e.printStackTrace();
Log.error("Class Utils | Method getRowCount | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
return iNumber;
}
public static String getCellData(int RowNum, int ColNum, String SheetName ) throws Exception{
try{
ExcelWSheet = ExcelWBook.getSheet(SheetName);
ExcelCell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
String CellData = ExcelCell.getStringCellValue();
return CellData;
}catch (Exception e){
e.printStackTrace();
Log.error("Class Utils | Method getCellData | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return"";
}
}
public static int getRowContains(String sTestCaseName, int colNum,String SheetName) throws Exception{
int iRowNum=0;
try {
//ExcelWSheet = ExcelWBook.getSheet(SheetName);
int rowCount = ExcelUtils.getRowCount(SheetName);
for (; iRowNum<rowCount; iRowNum++){
if (ExcelUtils.getCellData(iRowNum,colNum,SheetName).equalsIgnoreCase(sTestCaseName)){
break;
}
}
} catch (Exception e){
e.printStackTrace();
Log.error("Class Utils | Method getRowContains | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
}
return iRowNum;
}
public static int getTestStepsCount(String SheetName, String sTestCaseID, int iTestCaseStart) throws Exception{
try {
for(int i=iTestCaseStart;i<ExcelUtils.getRowCount(SheetName);i++){
if(!sTestCaseID.equals(ExcelUtils.getCellData(i, Constants.Col_TestCaseID, SheetName))){
int number = i;
return number;
}
}
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int number=ExcelWSheet.getLastRowNum()+1;
return number;
} catch (Exception e){
e.printStackTrace();
Log.error("Class Utils | Method getRowContains | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return 0;
}
}
public static boolean fileCopy(String sSource,String sDest)throws Exception
{
try
{
ReadExcelFile readTestCase=new ReadExcelFile();
List<Map<String, String>> testStepsList = new ArrayList<Map<String, String>>();
FileInputStream fileInputStreamSource = new FileInputStream(sSource);
HSSFWorkbook workbookSource = new HSSFWorkbook(fileInputStreamSource);
int iNumOfSheetsDest=workbookSource.getNumberOfSheets();
String sSourceSheetName="";
HSSFWorkbook workbookDest=new HSSFWorkbook();
HSSFSheet sheetDest=null;
for(int iSheets=0;iSheets<iNumOfSheetsDest;iSheets++)
{
sSourceSheetName= workbookSource.getSheetName(iSheets);
// sSourceSheetName= workbookSource.getSheetName(1);
//By Sadguna:Added extra condition to copy only the test cases and steps sheets
if(sSourceSheetName.contains("Cases") || sSourceSheetName.contains("Steps"))
{
FileOutputStream fileOutputStreamDest = new FileOutputStream(new File(sDest));
sheetDest= workbookDest.createSheet(sSourceSheetName);
testStepsList=readTestCase.copyExcelRecords(sSource,sSourceSheetName);
//for header
if(testStepsList.equals(null))
{
Log.error("Class Utils | Method fileCopy | Exception desc : getExcelRecords returns null");
fileOutputStreamDest.close();
DriverScript.bResult = false;
return false;
}
Row row =null;
Map<String, String> rowHeader ; Map<String, String> rowData ;
int coloumnindex=0;
if(sSourceSheetName.contains("Steps"))
{
coloumnindex=0;
rowHeader = testStepsList.get(coloumnindex);
row = sheetDest.createRow(coloumnindex);
/*List<String> keys = new ArrayList<String>(rowHeader.keySet());
for(int i=0;i<keys.size();i++)
{
Cell cell = row.createCell(i);
cell.setCellValue(keys.get(i));
}*///Doesnt work as the order in which values are put in hashmap is not the same as when they are retreived.
int i=0;
while(i<rowHeader.size())
{
Cell cell = row.createCell(i);
switch (i) {
case 0:
cell.setCellValue("Test Case ID");
break;
case 1:
cell.setCellValue("TS_ID");
break;
case 2:
cell.setCellValue("Steps");
break;
case 3:
cell.setCellValue("ActionKeyword");
break;
case 4:
cell.setCellValue("Object");
break;
case 5:
cell.setCellValue("Testdata");
break;
case 6:
cell.setCellValue("RESULT");
break;
case 7:
cell.setCellValue("ScreenShotOnFAILURE");
break;
case 8:
cell.setCellValue("Comments");
break;
case 9:
cell.setCellValue("DynamicValueName");
break;
default:
break;
}
i++;
}
}
else if(sSourceSheetName.contains("Cases"))
{
coloumnindex=0;
rowHeader = testStepsList.get(coloumnindex);
row = sheetDest.createRow(coloumnindex);
int i=0;
while(i<rowHeader.size())
{
Cell cell = row.createCell(i);
switch (i) {
case 0:
cell.setCellValue("Test Case ID");
break;
case 1:
cell.setCellValue("TC_Name");
break;
case 2:
cell.setCellValue("Runmode");
break;
case 3:
cell.setCellValue("Status");
break;
//comment below
//case 4:
//cell.setCellValue("Environment");
//break;
case 4:
cell.setCellValue("StartTime");
break;
case 5:
cell.setCellValue("EndTime");
break;
default:
break;
}
i++;
}
}
coloumnindex=0;
int cellIndex = 0;
for (int index = 0; index < testStepsList.size(); index++)
{
rowData = testStepsList.get(index);
row = sheetDest.createRow(index+1);
for (String columnName : rowData.keySet())
{
//System.out.println("columnName "+columnName);
Cell cell = row.createCell(cellIndex);
try{
String cellText=sheetDest.getRow(0).getCell(cellIndex).getStringCellValue();
cell.setCellValue(rowData.get(cellText));
}
catch(Exception e)
{
e.printStackTrace();
}
//System.out.println("cell "+cell);
cellIndex++;
}
cellIndex=0;
}
workbookDest.write(fileOutputStreamDest);
fileOutputStreamDest.flush();
coloumnindex=0;
}
}
}
catch(Exception e){
e.printStackTrace();
Log.error("Class Utils | Method fileCopy | Exception desc : "+e.getMessage());
DriverScript.bResult = false;
return false;
}
return true;
}
@SuppressWarnings("static-access")
public static void setCellData(String Result, int RowNum, int ColNum, String SheetName) throws Exception {
try{
ExcelWSheet = ExcelWBook.getSheet(SheetName);
ExcelRow = ExcelWSheet.getRow(RowNum);
ExcelCell = ExcelRow.getCell(ColNum, ExcelRow.RETURN_BLANK_AS_NULL);
if (ExcelCell == null) {
ExcelCell = ExcelRow.createCell(ColNum);
ExcelCell.setCellValue(Result);
} else {
ExcelCell.setCellValue(Result);
}
FileOutputStream fileOut = new FileOutputStream(configProps.getProperty("DestPath"));
ExcelWBook.write(fileOut);
fileOut.close();
}catch(Exception e){
e.printStackTrace();
DriverScript.bResult = false;
}
}
}
Wednesday, January 18, 2012
How to close any application without using the object ?
SystemUtil.CloseProcessbyName <.exe name of the application>
What are the options to write the QTP Sccript without using the Object Repository ?
1.Using Description object and using that object in the place of logical name in the script.
2.Writing object property and value pairs directly in the place of logical name in the script.
2.Writing object property and value pairs directly in the place of logical name in the script.
Where can we put the Regular expressions in the QTP Script ?
1.Property Value in Object Repository
2.Property Value in Description object.
3.Property Value in Property,Value pair which is in the logical name of the script.
2.Property Value in Description object.
3.Property Value in Property,Value pair which is in the logical name of the script.
How many ways we can add an object to Object Repository ?
1.New Test Object from Object Repository
2.Add Test Object from Object Repository
3.Add Test Object option from Active Screen
2.Add Test Object from Object Repository
3.Add Test Object option from Active Screen
How to fetch unmatching records from two SQL tables?
Table1
Id Name
1 Prashant
2 Ravi
3 Gaurav
5 Naween
7 Sachin
Table2
Id Name
1 Prashant
2 Ravi
4 Alok
6 Raja
The output I want is
Id Name
3 Gaurav
4 Alok
5 Naween
6 Raja
7 Sachin
select a.Id, a.Name from Table1 a left outer join Table2 b on a.Name = b.Name where b.Id is null
UNION ALL
select a.Id, a.Name from Table2 a left outer join Table1 b on a.Name = b.Name where b.Id is null
Id Name
1 Prashant
2 Ravi
3 Gaurav
5 Naween
7 Sachin
Table2
Id Name
1 Prashant
2 Ravi
4 Alok
6 Raja
The output I want is
Id Name
3 Gaurav
4 Alok
5 Naween
6 Raja
7 Sachin
select a.Id, a.Name from Table1 a left outer join Table2 b on a.Name = b.Name where b.Id is null
UNION ALL
select a.Id, a.Name from Table2 a left outer join Table1 b on a.Name = b.Name where b.Id is null
how to use ADO to read and write data in Excel workbooks?
How to Use a closed workbook as a database (DAO) using VBA in Microsoft Excel ?
Dim db As DAO.Database
Dim rs As DAO.Recordset
strPath = "D:\Gopi\Automation Stuff\"
intColARws = Worksheets(1).UsedRange.Rows.Count
intColBRws = Worksheets(2).UsedRange.Rows.Count
gSheet1 = "[Sheet1$A1:A" & intColARws & "]"
gSheet2 = "[Sheet2$A1:A" & intColBRws & "]"
Set db = OpenDatabase(strPath & "CompareExcel.xlsm", False, True, "Excel 8.0;") ' read
If db Is Nothing Then
MsgBox "Can't find the file!", vbExclamation, ThisWorkbook.Name
Exit Sub
End If
Set rsLeft = db.OpenRecordset("SELECT " & gSheet1 & ".ColA" & " FROM " & gSheet1 & " left outer join " & gSheet2 & " on " & gSheet1 & ".ColA <> " & gSheet2 & ".ColB" & " where " & gSheet2 & ".ColB is null")
i = 1
While Not (rsLeft.EOF)
'MsgBox rs.Fields("ColA")
Worksheets(3).Range("A" & i).Value = rsLeft.Fields("ColA")
rsLeft.MoveNext
i = i + 1
Wend
Dim db As DAO.Database
Dim rs As DAO.Recordset
strPath = "D:\Gopi\Automation Stuff\"
intColARws = Worksheets(1).UsedRange.Rows.Count
intColBRws = Worksheets(2).UsedRange.Rows.Count
gSheet1 = "[Sheet1$A1:A" & intColARws & "]"
gSheet2 = "[Sheet2$A1:A" & intColBRws & "]"
Set db = OpenDatabase(strPath & "CompareExcel.xlsm", False, True, "Excel 8.0;") ' read
If db Is Nothing Then
MsgBox "Can't find the file!", vbExclamation, ThisWorkbook.Name
Exit Sub
End If
Set rsLeft = db.OpenRecordset("SELECT " & gSheet1 & ".ColA" & " FROM " & gSheet1 & " left outer join " & gSheet2 & " on " & gSheet1 & ".ColA <> " & gSheet2 & ".ColB" & " where " & gSheet2 & ".ColB is null")
i = 1
While Not (rsLeft.EOF)
'MsgBox rs.Fields("ColA")
Worksheets(3).Range("A" & i).Value = rsLeft.Fields("ColA")
rsLeft.MoveNext
i = i + 1
Wend
Subscribe to:
Posts (Atom)