NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.S2B_NextGen.Automation.Library;

import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;







import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.internal.Nullable;

import com.S2B_NextGen.Automation.TestSuite.DriverScript;
import com.S2B_NextGen.Automation.Utility.Constant;
import com.S2B_NextGen.Automation.Utility.ExcelOperations;
import com.S2B_NextGen.Automation.Utility.MyException;
import com.google.common.base.Predicate;
import com.sun.jna.StringArray;


public class ActionMethods {

public static WebDriver driver;
private static Logger log = Logger.getLogger("rootLogger");
private static String reference;
private static String BulkImportRef;
int currentInvoiceRecordCount=0;
int currentTaxRecordCount=0;
String[] invoiceReference;
String[] invoiceDescription;
String[] invoiceDate;
String[] invoiceAmount;
String[] tax_TYPE;
String[] tax_SUB_TYPE;
String invoiceType;


HashMap<String,String> hashmapwithreflinks = new HashMap<String, String>();
HashMap<String,String> payeeNameToFilter = new HashMap<String, String>();
String FX_Deal;

public By findByLocator(String locatorTpye, String locatorValue) {
By by;
switch (locatorTpye.toUpperCase()) {
case "ID":
by = By.id(locatorValue);
break;
case "NAME":
by = By.name(locatorValue);
break;
case "XPATH":
by = By.xpath(locatorValue);
break;
case "CSS":
by = By.cssSelector(locatorValue);
break;
case "LINKTEXT":
by = By.linkText(locatorValue);
break;
case "PARTIALLINKTEXT":
by = By.partialLinkText(locatorValue);
break;
case "TAGNAME":
by = By.tagName(locatorValue);
break;
default:
by = null;
break;
}
return by;
}


public void openBrowser(HashMap<String,String> stepDetails, Map<String,String> testData) throws Exception{
if(Constant.browser.toUpperCase().equals("CHROME"))
{
log.info("launching the chrome browser");
System.setProperty("webdriver.chrome.driver",Constant.driverPath_chrome);
ChromeOptions co = new ChromeOptions();
co.addArguments("disable-extensions");
co.addArguments("test-type");
co.addArguments("--start-maximized");

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, co);

//ChromeDriver
driver = new ChromeDriver(capabilities);

captureScreenshot(stepDetails,testData);

}
else if(Constant.browser.equalsIgnoreCase("Firefox"))
{
driver = new FirefoxDriver();
}
else if(Constant.browser.equalsIgnoreCase("InternetExplorer"))
{
System.setProperty("webdriver.ie.driver",Constant.driverPath_ie);

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING,false);
dc.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
dc.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true);
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
dc.setJavascriptEnabled(true);

driver = new InternetExplorerDriver(dc);
captureScreenshot(stepDetails,testData);

//driver= new InternetExplorerDriver();
driver.manage().window().maximize();

}
}

public static void launchURL(HashMap<String,String> stepDetails, Map<String,String> testData) throws MyException,Exception
{
try
{
driver.get(Constant.URL);
}
catch (Exception e) {
e.printStackTrace();
String message="Failed to launch URL";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}
}

public void waitFor(HashMap<String,String> stepDetails, Map<String,String> testData) throws MyException,Exception
{
try
{
String value=stepDetails.get("WaitTime");
if (value.equals("") || value.equalsIgnoreCase("NA") ) {
log.info("'WaitFor' is not applicable for this transaction (as per the testData)");
}
else
{
Thread.sleep(Integer.parseInt(stepDetails.get("WaitTime")));
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
String message="Exception thrown as the thread was interrupted, either before or during waiting.";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}

}

public void clearText(HashMap<String,String> stepDetails, Map<String,String> testData) throws MyException,Exception
{
try
{
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
waitForElementToBeClickable(locator, 30).clear();
}
catch (Exception e) {
e.printStackTrace();
String message="The specified data in "+stepDetails.get("Field Name")+" is not found OR "+stepDetails.get("Field Name")+" is not loaded completely after sufficient wait time. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}

}
public void getPayeeNickName_Or_PaymentRefNum(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try
{
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
reference=waitForElementToBeClickable(locator, 30).getText();
System.out.println("Payment ref:"+reference);
DriverScript.testData.put("ReferenceValue",reference);
}
catch (Exception e) {
String message="The specified data in "+stepDetails.get("Field Name")+" is not found OR "+stepDetails.get("Field Name")+" is not loaded completely after sufficient wait time. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}

}

public void FetchBulkimportRef(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try
{
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
BulkImportRef=waitForElementToBeClickable(locator, 30).getText();
System.out.println("BulkImportRef:"+BulkImportRef);
DriverScript.testData.put("ReferenceValue",BulkImportRef);
ExcelOperations.setCellData(Constant.TestDataSheetName,"ReferenceValue",BulkImportRef,Integer.parseInt(testData.get("RowNum")));
}
catch (Exception e) {
String message="The specified data in "+stepDetails.get("Field Name")+" is not found OR "+stepDetails.get("Field Name")+" is not loaded completely after sufficient wait time. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}

}

public void NoOfTransactionsInBulkFile(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try
{

By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
WebElement dd=waitForElementToBeClickable(locator, 30);
List<WebElement> list=dd.findElements(By.xpath("//div[@class='transaction-reference-grid']/a"));
System.out.println("No of Payment Types in Application"+list.size());
String AllTranx="";

for(WebElement temp:list)
{
String str=temp.getText();
System.out.println("Application Payment Type"+str);
AllTranx=str+","+AllTranx;
//str.equalsIgnoreCase(PaymentTypeList.get(i));

}
AllTranx=AllTranx.substring(0, AllTranx.length()-1);
System.out.println("List of Trnx are processed through bulk File"+AllTranx);
ExcelOperations.setCellData(Constant.TestDataSheetName,"Search Value",AllTranx,Integer.parseInt(testData.get("RowNum")));

}
catch (Exception e) {
String message="The specified data in "+stepDetails.get("Field Name")+" is not found OR "+stepDetails.get("Field Name")+" is not loaded completely after sufficient wait time. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}

}

public void updateTestData(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try
{
testData.put("ReferenceValue",reference);
}
catch (Exception e)
{
String message="The specified data in "+stepDetails.get("Field Name")+" is not found OR "+stepDetails.get("Field Name")+" is not loaded completely after sufficient wait time. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}
}

public void verifyStatusForEdit(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try
{
String status= fetchingthestatus(stepDetails, testData);
System.out.println("Status:"+status);
if(!(status.equalsIgnoreCase("completed")||status.equalsIgnoreCase("draft"))){
String message="We can not perform 'EDIT' on transaction with "+status+" status. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}
else{

}
}
catch (Exception e) {

String message="The specified data in "+stepDetails.get("Field Name")+" is not found OR "+stepDetails.get("Field Name")+" is not loaded completely after sufficient wait time. Please refer "+testData.get("TestCaseName")+".jpg for more details" ;
log.info(message);
log.info(e.getMessage());
DriverScript.bResult="fail";
DriverScript.eMessage=message;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.