otonamcode
otonamcode
package com.intellect.digipay.otonom;
import java.io.FileNotFoundException;
import javax.annotation.PostConstruct;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.intellect.digipay.otonom.handler.OtonomHandler;
import com.itextpdf.text.DocumentException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import io.github.bonigarcia.wdm.WebDriverManager;
@SpringBootApplication
@EnableAutoConfiguration
WebDriver driver;
if ("firefox".equalsIgnoreCase(browser)) {
driver = new FirefoxDriver();
logger.trace("Firefox Driver Run Successfully ");
} else {
driver = new ChromeDriver();
logger.trace("Chrome Driver Run Successfully ");
}
/*@PostConstruct
public void process() throws FileNotFoundException, DocumentException {
String inputFile = "Otonom_Config_Sanity_FTB_Cash_Position00";
ExecutorService executor = Executors.newFixedThreadPool(1);
}
*/
//String inputFile="Otonom_Config_Sanity_FTB_I2I_Sweep_Tran_10St_AWS00";
String inputFile="Otonom_Config_Sanity_FTB_Cash_Position00";
System.exit(1);
otonam handleer:
package com.intellect.digipay.otonom.handler;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Properties;
import org.springframework.aop.target.SimpleBeanTargetSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import com.intellect.digipay.otonom.service.LoadConfigService;
import com.intellect.digipay.otonom.service.OtonomService;
import com.intellect.digipay.otonom.service.ResultService;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.log.SysoCounter;
import Utilities.PropertyUtils;
@Component
public class OtonomHandler {
@Autowired
LoadConfigService config;
@Autowired
ResultService rs;
@Autowired
Environment environment;
@SuppressWarnings("rawtypes")
String fileName;
String filePath;
String browser;
String driverPath;
try {
//driverPath = environment.getProperty("chrome_driver_path");
//filePath = environment.getProperty("otonom_home");
//filePath = (System.getProperty("user.dir")+"\\");
// filePath = "D:\\Otonom_New\\Otonom\\DEV_AUTOMATON_FILE\\";
//filePath = "D:\\Otonom_New\\Otonom\\SIT_Atomation_File\\";
// filePath = "D:\\Automation\\Daily_Sanity_DEV_SIT_UAT\\";
filePath = "D:\\Automation\\Otonom_new\\SANITY\\";
//filePath ="D:\\Otonom_New\\Otonom\\SCRIPT_WRITE\\";
// filePath="D:\\Otonom_New\\Otonom\\TEST_DATA\\";
//filePath = "D:\\Otonom_New\\Otonom\\SANITY\\";
Scanner myObj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter Config sheet");
// fileName = myObj.nextLine(); // Read user input
fileName = inputfile;
System.out.println("fileName is: " + fileName); // Output user
input
// fileName = environment.getProperty("config_file_name");
browser = environment.getProperty("browser");
// browser = (System.getProperty("user.dir")+"\\Driver\\
chromedriver.exe");
driverPath = System.getProperty("user.dir") + "\\Driver\\
chromedriver.exe";
//driverPath = System.getProperty("user.dir") + "\\Driver\\
geckodriver.exe";
//change 26sep
System.setProperty("webdriver.chrome.driver", driverPath);
//System.setProperty("webdriver.gecko.driver", driverPath);
@SuppressWarnings("rawtypes")
@SuppressWarnings("rawtypes")
private HashMap execute(HashMap mapConfig, String filePath, String browser)
throws FileNotFoundException, DocumentException {
HashMap resultMap;
OtonomService os = new OtonomService(mapConfig, filePath, browser);
resultMap = os.executeStories();
return resultMap;
}
@SuppressWarnings("rawtypes")
private void writeResult(HashMap resultMap, String filePath, String fileName)
{
// ResultService rs = new ResultService();
rs.writeResult(resultMap, filePath, fileName);
}
}
branding service:
package com.intellect.digipay.otonom.service;
import java.util.ArrayList;
import java.util.HashMap;
public class BrandingService {
httpsservice:
package com.intellect.digipay.otonom.service;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import com.jayway.jsonpath.JsonPath;
if (parametersList != null) {
for (int i = 0; i < parametersList.size(); i++) {
httpBody = httpBody.replaceAll("##PARAM" + i + "##",
parametersList.get(i).trim());
}
}
httpBody = replaceKeywords(httpBody);
}
}
try {
HttpEntity<String> request = new HttpEntity<>(httpBody, headers);
System.out.println("apiCode: " + apiCode + " : request: " +
request);
if ("POST".equalsIgnoreCase(httpMethod.trim()))
response = restTemplate.exchange(uri, HttpMethod.POST,
request, String.class);
if ("GET".equalsIgnoreCase(httpMethod.trim()))
response = restTemplate.exchange(uri, HttpMethod.GET,
request, String.class);
if (null != response) {
responseStatus = response.getStatusCodeValue();
if (null != responseJsonPath &&
responseJsonPath.trim().length() > 0) {
try {
responseJsonPathValue =
JsonPath.read(response.getBody(), responseJsonPath).toString();
} catch (Exception e) {
responseJsonPathValue = "";
}
System.out.println("--> responseJsonPathValue:" +
responseJsonPathValue);
}
}
} catch (HttpClientErrorException httperr) {
responseStatus = httperr.getRawStatusCode();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("responseStatus:" + responseStatus);
System.out.println("-------------------------------------------------------------")
;
return responseStatus;
}
replacedString = replacedString.replaceAll("##TODAY_YYYYMMDD##",
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
replacedString = replacedString.replaceAll("##TODAY_YYYY-MM-DD##",
LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-
MM-dd")));
replacedString = replacedString.replaceAll("##TODAY_DD-MMM-YYYY##",
LocalDate.now().format(DateTimeFormatter.ofPattern("dd-MMM-
yyyy")));
replacedString = replacedString.replaceAll("##TODAY_DD/MM/YYYY##",
LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
replacedString = replacedString.replaceAll("##TODAY_DATE_TIME##",
LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd
HH:mm:ss.SSS").withZone(ZoneId.systemDefault())));
replacedString = replacedString.replaceAll("##YESTERDAY_YYYYMMDD##",
LocalDate.now().minus(Period.ofDays(1)).format(DateTimeFormatter.ofPattern("yyyyMMd
d")));
replacedString = replacedString.replaceAll("##YESTERDAY_YYYY-MM-DD##",
LocalDate.now().minus(Period.ofDays(1)).format(DateTimeFormatter.ofPattern("yyyy-
MM-dd")));
replacedString = replacedString.replaceAll("##YESTERDAY_DD-MMM-YYYY##",
LocalDate.now().minus(Period.ofDays(1)).format(DateTimeFormatter.ofPattern("dd-MMM-
yyyy")));
replacedString = replacedString.replaceAll("##YESTERDAY_DD/MM/YYYY##",
LocalDate.now().minus(Period.ofDays(1)).format(DateTimeFormatter.ofPattern("dd/MM/
yyyy")));
replacedString = replacedString.replaceAll("##YESTERDAY_DATE_TIME##",
LocalDateTime.now().minus(Period.ofDays(1)).format(
DateTimeFormatter.ofPattern("yyyy-MM-dd
HH:mm:ss.SSS").withZone(ZoneId.systemDefault())));
return replacedString;
}
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMdd-
HHmmss-SSS"))
+ String.format("%06d", number);
}
}
load config:
package com.intellect.digipay.otonom.service;
import org.dhatim.fastexcel.reader.ReadableWorkbook;
import org.dhatim.fastexcel.reader.Row;
import org.dhatim.fastexcel.reader.Sheet;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Optional;
import java.util.stream.Stream;
@Component
public class LoadConfigService {
try {
Optional<Sheet> optSheet = wb.getSheet(sheetIndex);
if (optSheet.isPresent()) {
sheet = optSheet.get();
}
/*@SuppressWarnings("rawtypes")
public void printSingleSheetData(ArrayList sheetData) {
System.out.println(" ** ----------------");
ArrayList li2;
for (int i = 0; i < sheetData.size(); i++) {
System.out.print(" Row " + i + " ----------------");
li2 = (ArrayList) sheetData.get(i);
for (int p = 0; p < li2.size(); p++) {
System.out.print(p + " - " + li2.get(p) + " ::: ");
}
System.out.println(" ");
}
}*/
}
otonam service:
package com.intellect.digipay.otonom.service;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Random;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.env.RandomValuePropertySource;
import com.intellect.digipay.otonom.util.ItextpdfhealperUtil;
import com.itextpdf.text.DocumentException;
import Utilities.PropertyUtils;
@SuppressWarnings("rawtypes")
private HashMap inputConfigMap;
@SuppressWarnings("rawtypes")
private HashMap resultMap;
this.inputConfigMap = configMap;
this.taskMap = new HashMap();
this.selenideService = new SelenideService(brandingList, httpList,
databaseList, filePath, browser);
if ("Labels".equals(innerResultList.get(0))) {
this.labelScope = (String) innerResultList.get(1);
} else {
this.labelScope = "Y";
}
String sketchResult;
ArrayList storyWorkList = new ArrayList();
ArrayList storyData = (ArrayList) inputConfigMap.get("Story");
ArrayList localStoryResultList = null;
if ("Y".equalsIgnoreCase(((String) storyWorkList.get(2)).trim())
|| "YES".equalsIgnoreCase(((String)
storyWorkList.get(2)).trim())) {
sketchResult = executeSketch(((String)
storyWorkList.get(1)).trim()); // sketch
if (!"Pass".equalsIgnoreCase(sketchResult))
storyWorkList.add("Fail");
localStoryResultList.add(sketchResult);
storyResultList.add(localStoryResultList);
}
}
resultMap = inputConfigMap;
resultMap.put("Story", storyResultList);
resultMap.put("Sketch", sketchResultList);
resultMap.put("Routine", routineResultList);
return resultMap;
}
ArrayList<String> sketchWorkList;
ArrayList sketchData = (ArrayList) inputConfigMap.get("Sketch");
ArrayList<String> localSketchResultList = null;
System.out.println(" ");
System.out.println("===> Executing Sketch (" + sketch + ")");
logger.info("inside OtonomService");
System.out.println(" ");
for (int i = 1; i < sketchData.size(); i++) {
sketchWorkList = (ArrayList) sketchData.get(i);
localSketchResultList = (ArrayList) sketchWorkList.clone();
if (sketch.contains(((String) sketchWorkList.get(0)).trim())) {
if ("Y".equalsIgnoreCase(((String)
sketchWorkList.get(3)).trim())
|| "YES".equalsIgnoreCase(((String)
sketchWorkList.get(3)).trim())) {
String Screenshot_path=System.getProperty("user.dir")
+ "\\reports";
// itextpdf.initializePDF(sketchWorkList.get(1),
PropertyUtils.getProperties().getProperty("screenshot_location"));
itextpdf.initializePDF(sketchWorkList.get(1),Screenshot_path);
if (!"Pass".equalsIgnoreCase(routineResult))
sketchAllClear = "Fail";
localSketchResultList.add(routineResult);
sketchResultList.add(localSketchResultList);
}
}
}
if (routine.contains(((String) routineWorkList.get(0)).trim())) {
if (((String) routineWorkList.get(5)).startsWith("##")) {
flavourValue = getFlavourValue(flavour, (String)
routineWorkList.get(5));
} else {
flavourValue = (String) routineWorkList.get(5);
}
taskMap.put("labelScope", labelScope);
taskMap.put("brandingScope", brandingScope);
taskMap.put("routine", routine);
taskMap.put("flavour", flavour);
taskMap.put("sketch", sketch);
taskMap.put("task", (String) routineWorkList.get(1));
taskMap.put("taskType", (String) routineWorkList.get(2));
taskMap.put("xpath", (String) routineWorkList.get(3));
taskMap.put("id", (String) routineWorkList.get(4));
taskMap.put("value", flavourValue);
taskMap.put("timeout", (String) routineWorkList.get(6));
taskMap.put("externalRef", (String)
routineWorkList.get(7));
taskMap.put("externalRef1", (String)
routineWorkList.get(8));
taskMap.put("collectVariables", (String)
routineWorkList.get(9));
if (!"Ignore".equalsIgnoreCase((String)
routineWorkList.get(2))) {
taskResultMap =
this.selenideService.executeTask(taskMap,itextpdf);
taskResult = (String)
taskResultMap.get("Result_Task");
} else {
taskResult = "Pass";
taskResultMap.put("Result_Expected", " ");
taskResultMap.put("Result_Actual", " ");
}
if ("Fail".equalsIgnoreCase(taskResult) ||
"TechFail".equalsIgnoreCase(taskResult)) {
System.out.println(" Task Result Failed- " +
(String) routineWorkList.get(1));
logger.info("inside OtonomService");
routineResult = "Fail";
}
localRoutineResultList.add(taskResult);
localRoutineResultList.add(taskResultMap.get("Result_Expected"));
localRoutineResultList.add(taskResultMap.get("Result_Actual"));
localRoutineResultList.add(sketch);
localRoutineResultList.add(routine);
localRoutineResultList.add(flavour);
localRoutineResultList.add(taskResultMap.get("Result_Timestamp"));
routineResultList.add(localRoutineResultList);
}
} // loop of tasks in a routine
System.out.println(" ");
return routineResult;
@SuppressWarnings("rawtypes")
private String getFlavourValue(String flavour, String value) {
ArrayList dynamicWorkList;
for (int i = 0; i < dynamicValuesList.size(); i++) {
dynamicWorkList = (ArrayList) dynamicValuesList.get(i);
if (value.equalsIgnoreCase(((String)
dynamicWorkList.get(0)).trim())
|| value.equalsIgnoreCase("##" + ((String)
dynamicWorkList.get(0)).trim())) {
if (flavour.equalsIgnoreCase(((String)
dynamicWorkList.get(1)).trim())) {
// return ((String) dynamicWorkList.get(2)).trim();
String val = ((String)
dynamicWorkList.get(2)).trim();
if ("~~RANDOM_NUM~~".equals(val)) // yymmddhhmissmis
+any
// date
// with
// randum
// number
System.out.println(formatter.format(date));
}
// YYMMDD
{
formatter = new SimpleDateFormat("yymmdd");
val = formatter.format(date);
System.out.println(formatter.format(date));
}
if ("~~TODAY_DD-MM-YYYY~~".equals(val)) // generate
date
// with DD-MM-YYYY
{
formatter = new SimpleDateFormat("dd-mm-yyyy");
val = formatter.format(date);
System.out.println(formatter.format(date));
}
if ("~~TODAY_MM/dd/yyyy~~".equals(val)) // generate
date
// with MM/dd/yyyy
{
formatter = new SimpleDateFormat("MM/dd/yyyy");
val = formatter.format(date);
System.out.println(formatter.format(date));
}
if ("~~TODAY_YYYY/MM/DD~~".equals(val)) // generate
date
// with YYYY/MM/DD
{
formatter = new SimpleDateFormat("yyyy/mm/dd");
val = formatter.format(date);
System.out.println(formatter.format(date));
}
if ("~~TOMORROW_MM/dd/yyyy~~".equals(val)) //
generate
// TOMORROW
// date with
// MM/dd/yyyy
{
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, 1);
date = calendar.getTime();
formatter = new SimpleDateFormat("MM/dd/yyyy");
val = formatter.format(date);
System.out.println("Tomorrow : " + val);
}
// YYYY/MM/DD
{
// Define the static prefix
String prefix = "AS";
return val;
}
}
}
return value;
}
@SuppressWarnings("rawtypes")
public void printSingleSheetData(ArrayList sheetData) {
System.out.println("----------------");
System.out.println("---- Result ----");
System.out.println("----------------");
logger.info("inside OtonomService");
ArrayList li2;
for (int i = 0; i < sheetData.size(); i++) {
System.out.print("Row " + i + " ----------------");
li2 = (ArrayList) sheetData.get(i);
for (int p = 0; p < li2.size(); p++) {
System.out.print(p + " - " + li2.get(p) + " ::: ");
}
System.out.println(" ");
logger.info("inside OtonomService");
}
}
}
result service:
package com.intellect.digipay.otonom.service;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import org.dhatim.fastexcel.Color;
import org.dhatim.fastexcel.Workbook;
import org.dhatim.fastexcel.Worksheet;
import org.springframework.stereotype.Component;
@Component
public class ResultService {
@SuppressWarnings("rawtypes")
public void writeResult(HashMap resultMap, String filePath, String fileName)
{
ArrayList dynamicResult = (ArrayList) resultMap.get("Dynamic");
ArrayList scopeResult = (ArrayList) resultMap.get("Scope");
ArrayList storyResult = (ArrayList) resultMap.get("Story");
ArrayList sketchResult = (ArrayList) resultMap.get("Sketch");
ArrayList routineResult = (ArrayList) resultMap.get("Routine");
ArrayList brandingResult = (ArrayList) resultMap.get("Branding");
ArrayList guideResult = (ArrayList) resultMap.get("Guide");
ArrayList readmeResult = (ArrayList) resultMap.get("Readme");
String timeStamp = new SimpleDateFormat("yyyy-MM-dd-HH-
mm").format(Calendar.getInstance().getTime());
File f = new File(filePath + "Result_"+timeStamp+"_"+fileName);
@SuppressWarnings("rawtypes")
private void writeSheet(String sheetName, Workbook wb, ArrayList resultSheet)
{
Worksheet ws = wb.newWorksheet(sheetName);
ArrayList workList = new ArrayList();
int i;
int p = 0;
try {
for (i = 0; i < resultSheet.size(); i++) {
workList = (ArrayList) resultSheet.get(i);
for (p = 0; p < workList.size(); p++) {
ws.value(i, p, workList.get(p).toString());
if ("Pass".equalsIgnoreCase((String)
workList.get(p))) {
ws.style(i,
p).borderStyle("thin").fillColor(Color.LIGHT_GREEN).set();
}
if ("Fail".equalsIgnoreCase((String)
workList.get(p))) {
ws.style(i,
p).borderStyle("thin").fillColor(Color.BABY_PINK).set();
}
if ("TechFail".equalsIgnoreCase((String)
workList.get(p))) {
ws.style(i,
p).borderStyle("thin").fillColor(Color.RED).set();
}
if (workList.get(p).toString().startsWith("ID") ||
workList.get(p).toString().startsWith("Value")
||
workList.get(p).toString().startsWith("X")
||
workList.get(p).toString().startsWith("Param_")
||
workList.get(p).toString().startsWith("Flavour")
||
workList.get(p).toString().startsWith("Result_E")
||
workList.get(p).toString().startsWith("Result_A")) {
ws.width(p, 40);
}
if (i == 0) {
if
(workList.get(p).toString().startsWith("Result")
||
workList.get(p).toString().startsWith("Pass")
||
workList.get(p).toString().startsWith("Fail")
||
workList.get(p).toString().startsWith("TechFail")) {
ws.style(i,
p).borderStyle("thin").bold().fillColor(Color.NAVY_BLUE).fontColor(Color.WHITE)
.set();
} else {
ws.style(i,
p).borderStyle("thin").bold().fillColor(Color.YELLOW).set();
}
} else {
ws.style(i, p).borderStyle("thin").set();
}
}
}
} catch (Exception e) {
ws.value(0, 0, " ");
}
}
}
resubale method:
package com.intellect.digipay.otonom.service;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import Utilities.PropertyUtils;
import Utilities.RunTimeProperties;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
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.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
//import context.RunTimeProperties;
RunTimeProperties.setProperty("YYYY-MM-DD", time.format(date));
}
System.out.println(FinalPath);
File file1 = new File(FinalPath);
Scanner sc = null;
try {
sc = new Scanner(file1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String input;
StringBuffer sb = new StringBuffer();
while (sc.hasNextLine()) {
input = sc.nextLine();
sb.append(input + " ");
}
try {
RequestConfig requestConfig =
RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
HttpClient httpClient =
HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
System.out.println(FinalPath);
File file1 = new File(FinalPath);
Scanner sc = null;
try {
sc = new Scanner(file1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String input;
StringBuffer sb = new StringBuffer();
while (sc.hasNextLine()) {
input = sc.nextLine();
sb.append(input + " ");
}
System.out.println("_________________");
HttpClient httpClient = HttpClientBuilder.create().build();
StringEntity userEntity;
try {
sc = new Scanner(file1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String input;
StringBuffer sb = new StringBuffer();
while (sc.hasNextLine()) {
input = sc.nextLine();
sb.append(input + " ");
}
System.out.println(json);
try{
//RequestConfig requestConfig =
RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
System.out.println("_________________");
HttpClient httpClient = HttpClientBuilder.create().build();
StringEntity userEntity;
try {
sc = new Scanner(file1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String input;
StringBuffer sb = new StringBuffer();
while (sc.hasNextLine()) {
input = sc.nextLine();
sb.append(input + " ");
}
json = json
.replace("VAR_YYY-MM-DD",
RunTimeProperties.getProperty("YYYY-MM-DD"));
System.out.println(json);
try{
//RequestConfig requestConfig =
RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
System.out.println("_________________");
HttpClient httpClient = HttpClientBuilder.create().build();
StringEntity userEntity;
RequestConfig requestConfig =
RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
HttpClient httpClient =
HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
RestAssured.baseURI = "http://tlm-autoresponse-dit-1-
fcl.cluster8.intellectproduct.com/generator/earmarkinput";
RequestSpecification request = RestAssured.given();
try {
sc = new Scanner(file1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String input;
StringBuffer sb = new StringBuffer();
while (sc.hasNextLine()) {
input = sc.nextLine();
sb.append(input + " ");
}
System.out.println(json);
request.body(json);
selenoid service:
package com.intellect.digipay.otonom.service;
import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.Condition.*;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideConfig;
import com.codeborne.selenide.SelenideDriver;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.WebDriverRunner;
import com.deque.html.axecore.results.Results;
import com.deque.html.axecore.results.Rule;
import com.intellect.digipay.otonom.util.ItextpdfhealperUtil;
import com.deque.html.axecore.selenium.AxeBuilder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import Utilities.PropertyUtils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Action;
import static com.codeborne.selenide.Selenide.screenshot;
BrandingService brandingService;
HttpService httpService;
String labelScope;
String brandingScope;
String sketch;
String routine;
String flavour;
String task;
String taskType;
String xpath;
String id;
String value;
Integer timeout;
String externalRef;
String externalRef1;
String taskResult = "Pass";
String expectedResult = " ";
String actualResult = " ";
String holder;
SelenideService hoverElement;
String collectVariables;
HashMap<String, String> resultMap = new HashMap<String, String>();
HashMap<String, String> brandingSpecs;
HashMap<String, String> collectVariablesMap = new HashMap<String, String>();
String filePath;
SelenideConfig con;
SelenideDriver sd;
org.openqa.selenium.WebDriver dri; //
System.setProperty("java.awt.headless", "false");
if ("ie".equalsIgnoreCase(browser))
config.pageLoadStrategy = "none";
con = new SelenideConfig();
sd = new SelenideDriver(con);
dri = sd.getAndCheckWebDriver();
WebDriverRunner.setWebDriver(dri);
expectedResult = "";
actualResult = "";
int rowAffected = 0;
try {
timeout = Integer.parseInt(taskMap.get("timeout").trim());
} catch (Exception e) {
timeout = 20;
}
if (Optional.ofNullable(timeout).orElse(0) < 5) {
timeout = 20;
}
try {
switch (taskType.toLowerCase()) {
case "http_fcr":
System.out.println("-----------------------Start
post1------------");
String val1[] = value.split("\\|");
System.out.println(value);
ReusableMethods.PostFCR(val1[0], val1[1]);
collectVariablesMap.put(collectVariables, value);
break;
case "http_rtb":
System.out.println("-----------------------Start
post2------------");
System.out.println(value);
String val2[] = value.split("\\|");
ReusableMethods.PostRTB(val2[0], val2[1]);
collectVariablesMap.put(collectVariables, value);
break;
case "http_ecr":
System.out.println("-----------------------Start
post3------------");
System.out.println(value);
String val3[] = value.split("\\|");
ReusableMethods.PostEarMark(val3[0], val3[1]);
collectVariablesMap.put(collectVariables, value);
break;
case "delete_structure":
System.out.println("-----------------------Start
post4------------");
System.out.println(value);
ReusableMethods.DeleteStrct(value);
collectVariablesMap.put(collectVariables, value);
break;
case "open":
open(value);
taskResult = "Pass";
break;
case "tab":
int go;
try {
go = Integer.parseInt(value);
} catch (Exception e) {
go = 100;
}
for (int i = 0; i < go; i++) {
actions().sendKeys(Keys.TAB).build().perform();
if (getFocusedElement().getText().trim().length() ==
0) {
actualResult = actualResult + ", " + i;
}
}
break;
case "press_tab":
actions().sendKeys(Keys.TAB).build().perform();
break;
case "enter":
actions().sendKeys(Keys.ENTER).build().perform();
break;
case "disable":
try {
$(By.xpath(value)).shouldBe(enabled);
System.out.println("disabled");
taskResult = "Fail";
} catch (Exception e) {
System.out.println("Enabled");
taskResult = "Pass";
}
break;
case "enable":
try {
$(By.xpath(value)).shouldBe(disabled);
System.out.println("enabled");
taskResult = "Fail";
} catch (Exception e) {
System.out.println("disabled");
taskResult = "Pass";
}
break;
case "visible":
try {
$(By.xpath(value)).shouldBe(visible);
System.out.println("visible");
taskResult = "Pass";
} catch (Exception e) {
System.out.println("not visible");
taskResult = "Pass";
}
break;
case "http_api_call":
int httpResponse = this.httpService.makeHttpCall(value);
expectedResult = "Http Response 2XX";
actualResult = "Http Response " + httpResponse;
case "keydown":
int go1;
try {
go1 = Integer.parseInt(value);
} catch (Exception e) {
go1 = 100;
}
for (int i = 0; i < go1; i++) {
actions().sendKeys(Keys.DOWN).build().perform();
if (getFocusedElement().getText().trim().length() ==
0) {
actualResult = actualResult + ", " + i;
}
}
break;
case "keydown_one_time":
actions().sendKeys(Keys.DOWN).build().perform();
break;
case "click":
if (id != null && !id.trim().isEmpty()) {
$$(id).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$(id).first().click();
} else {
$$x(xpath).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$x(xpath).first().click();
}
taskResult = "Pass";
break;
case"set_reference_currency":
if(value.equals("AUD")) {
System.out.println(currency[1]);
}
else if(value.equals("CAD")) {
System.out.println(currency[2]);
}else{
System.out.println(currency[0]);
}
case "doubleclick":
if (id != null && !id.trim().isEmpty()) {
$$(id).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$(id).first().doubleClick();
} else {
$$x(xpath).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$x(xpath).first().doubleClick();
}
taskResult = "Pass";
break;
// case "close":
//
// Selenide.closeWindow();
// taskResult = "Pass";
// break;
case "close":
System.out.println("Attempting to close the current
window...");
try {
Selenide.closeWindow();
System.out.println("Window closed successfully.");
taskResult = "Pass";
} catch (Exception e) {
System.out.println("Failed to close the window: " +
e.getMessage());
taskResult = "Fail";
}
break;
case "clear_field":
if (id != null && !id.trim().isEmpty()) {
$$(id).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$(id).first().clear();
} else {
$$x(xpath).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$x(xpath).first().clear();
}
taskResult = "Pass";
break;
case "update_query":
rowAffected = updateQuery(value);
String s = Integer.toString(rowAffected);
collectVariablesMap.put(collectVariables, s);
taskResult = "Pass";
break;
case "select_query":
taskResult = selectQuery(value);
collectVariablesMap.put(collectVariables, taskResult);
taskResult = "Pass";
break;
case "delete_query":
rowAffected = deleteQuery(value);
String r = Integer.toString(rowAffected);
collectVariablesMap.put(collectVariables, r);
taskResult = "Pass";
break;
case "sleep":
sleep(1000 * Integer.parseInt(value));
taskResult = "Pass";
break;
case "back_space":
actions().sendKeys(Keys.BACK_SPACE).build().perform();
taskResult = "Pass";
break;
case "set_value":
if (id != null && !id.trim().isEmpty()) {
$$(id).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$(id).first().click();
} else {
$$x(xpath).first().shouldHave(enabled,
Duration.ofSeconds(timeout));
$$x(xpath).first().click();
}
actions().sendKeys(value).build().perform();
collectVariablesMap.put(collectVariables, value);
taskResult = "Pass";
break;
case "check_value":
case "check_value_exact":
case "check_value_ignore":
holder = extractText();
expectedResult = value;
actualResult = holder;
collectVariablesMap.put(collectVariables, actualResult);
System.out.println("collectVariablesMap");
for (String name : collectVariablesMap.keySet()) {
String key = name.toString();
String value =
collectVariablesMap.get(name).toString();
System.out.println(key + "--" + value);
if (value.equals(holder))
taskResult = "Pass";
else
taskResult = "Fail";
if (taskType.equalsIgnoreCase("check_value_ignore"))
taskResult = "Pass";
break;
case "check_value_disabled":
System.out.println("getText----------" + text2);
holder = text2;
expectedResult = value;
actualResult = holder;
collectVariablesMap.put(collectVariables, actualResult);
System.out.println("collectVariablesMap");
for (String name : collectVariablesMap.keySet()) {
String key = name.toString();
String value =
collectVariablesMap.get(name).toString();
System.out.println(key + "--" + value);
if (value.equals(holder))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "placeholder":
expectedResult = value;
if (id != null && !id.trim().isEmpty()) {
$(id).shouldHave(Condition.attribute("placeholder",
value));
actualResult = $(id).getAttribute("placeholder");
} else {
$x(xpath).shouldHave(Condition.attribute("placeholder", value));
actualResult = $x(xpath).getAttribute("placeholder");
}
if (expectedResult.equals(actualResult))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "check_value_begins_with":
holder = extractText();
expectedResult = value;
actualResult = holder;
if (holder.startsWith(value))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "check_value_ends_with":
holder = extractText();
expectedResult = value;
actualResult = holder;
if (holder.endsWith(value))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "check_value_contains":
holder = extractText();
expectedResult = value;
actualResult = holder;
if (holder.contains(value))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "refresh_screen":
// Refresh the screen or reload the page
if (id != null && !id.trim().isEmpty()) {
((SelenideDriver) $$
(id).first()).getWebDriver().navigate().refresh();
} else {
((SelenideDriver) $$
(xpath).first()).getWebDriver().navigate().refresh();
}
case "check_branding_self":
case "check_branding_ignore":
if (id != null && !id.trim().isEmpty()) {
$$(id).first().shouldHave(exist,
Duration.ofSeconds(timeout));
} else {
$$x(xpath).first().shouldHave(exist,
Duration.ofSeconds(timeout));
}
brandingSpecs =
this.brandingService.getBrandingSpecs(value, taskType.toLowerCase());
boolean brandingcheck = true;
if ("font-
family".equalsIgnoreCase(entry.getKey())) {
if (!$$
(id).first().getCssValue(entry.getKey()).contains(entry.getValue())) {
brandingcheck = false;
}
} else {
if (!entry.getValue().equals($$
(id).first().getCssValue(entry.getKey()))
&& !($$
(id).first().getCssValue(entry.getKey())).contains("auto")
&& !
entry.getValue().contains("auto")) {
brandingcheck = false;
}
}
} else {
actualResult = actualResult +
System.lineSeparator() + entry.getKey() + ":"
+ $
$x(xpath).first().getCssValue(entry.getKey());
if ("font-
family".equalsIgnoreCase(entry.getKey())) {
if (!$
$x(xpath).first().getCssValue(entry.getKey()).contains(entry.getValue())) {
brandingcheck = false;
}
} else {
try {
if (!entry.getValue().equals($
$x(xpath).first().getCssValue(entry.getKey()))
&& !($
$x(xpath).first().getCssValue(entry.getKey())).contains("auto")
&& !
entry.getValue().contains("auto")) {
brandingcheck = false;
}
} catch (Exception e) {
}
}
}
}
if (brandingcheck)
taskResult = "Pass";
else
taskResult = "Fail";
if (taskType.equalsIgnoreCase("check_branding_ignore"))
taskResult = "Pass";
break;
case "screenshot":
String screenshot2 = screenshot(sketch + "___" + routine + "___" +
flavour + "___" + task);
System.out.println("DDDDDDDD>>>>>>"+screenshot2);
//task
//itextpdf.writePDF(task);0000
itextpdf.writePDF(getScreenShotNameDetails(task), 2);
itextpdf.writePDF(getScreenShotTimeStamp(), 2);
itextpdf.insertImageInPDF(screenshot2.substring(6));
itextpdf.writePDFNewPage();
actualResult = sketch + "___" + routine + "___" + flavour + "___" +
task;
taskResult = "Pass";
break;
case "check_branding_hover":
if (id != null && !id.trim().isEmpty()) {
$$(id).first().shouldHave(exist,
Duration.ofSeconds(timeout)).hover();
} else {
$$x(xpath).first().shouldHave(exist,
Duration.ofSeconds(timeout)).hover();
}
brandingSpecs =
this.brandingService.getBrandingSpecs(value, taskType.toLowerCase());
for (Map.Entry<String, String> entry :
brandingSpecs.entrySet()) {
expectedResult = expectedResult +
System.getProperty("line.separator") + entry.getKey() + ":"
+ entry.getValue();
} else {
actualResult = actualResult +
System.lineSeparator() + entry.getKey() + ":"
+ $
$x(xpath).first().getCssValue(entry.getKey());
}
}
if (expectedResult.equals(actualResult))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "check_branding_active":
System.out.println($
(element).getCssValue("background-color"));
System.out.println("after clickAndhold%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%");
} else {
$$x(xpath).first().shouldHave(exist,
Duration.ofSeconds(timeout));
}
System.out.println("1##############################################################
#####");
brandingSpecs =
this.brandingService.getBrandingSpecs(value, taskType.toLowerCase());
System.out.println("brandingSpecs :" + brandingSpecs);
for (Map.Entry<String, String> entry :
brandingSpecs.entrySet()) {
System.out.println("2##############################################################
#####");
expectedResult = expectedResult +
System.getProperty("line.separator") + entry.getKey() + ":"
+ entry.getValue();
} else {
actualResult = actualResult +
System.lineSeparator() + entry.getKey() + ":"
+ $
$x(xpath).first().getCssValue(entry.getKey());
}
}
if (expectedResult.equals(actualResult))
taskResult = "Pass";
else
taskResult = "Fail";
break;
holder = extractText();
expectedResult = value;
actualResult = holder;
collectVariablesMap.put(collectVariables, actualResult);
System.out.println("collectVariablesMap");
for (String name : collectVariablesMap.keySet()) {
String key = name.toString();
String value =
collectVariablesMap.get(name).toString();
System.out.println(key + "--" + value);
}
if (expectedResult.equals(actualResult))
taskResult = "Pass";
else
taskResult = "Fail";
break;
case "scroll_up":
actions().sendKeys(Keys.PAGE_UP).build().perform();
break;
case "scroll_down":
actions().sendKeys(Keys.PAGE_DOWN).build().perform();
break;
case "target_new_tab":
int tab_val = Integer.parseInt(value);
switchTo().window(tab_val);
break;
case "check_a11y":
AxeBuilder builder = new AxeBuilder();
builder.withTags(tags);
//Results results = builder.analyze((WebDriver) driver);
Results results = builder.analyze(dri);
System.out.println("results a11y");
List<Rule> violations = results.getViolations();
System.out.println("violations.size() -
"+violations.size());
if (violations.size() == 0) {
actualResult = "No violations found";
taskResult = "Pass";
} else {
//AxeReporter.getReadableAxeResults("no-passes", dri,
violations);
//actualResult = AxeReporter.getAxeResultString();
Iterator<Rule> iterator = violations.iterator();
Rule rule;
String findings = " ";
/*
JSONArray ja = new JSONArray();
JSONObject jo = new JSONObject();
List nodes;
while (iterator.hasNext()) {
rule = iterator.next();
jo.clear();
jo.put("impact", rule.getImpact());
jo.put("tags", rule.getTags().toString());
jo.put("description", rule.getDescription());
jo.put("node-count", rule.getNodes().size());
jo.put("node-sample",
rule.getNodes().get(0).getFailureSummary()
+ " ~ " +
rule.getNodes().get(0).getHtml());
System.out.println("finding --" +
jo.toString());
//findings = findings + "~" + jo.toString();
ja.put(jo);
}
*/
JsonArray ja = new JsonArray();
JsonObject jo;
List nodes;
while (iterator.hasNext()) {
rule = iterator.next();
jo = new JsonObject();
jo.addProperty("impact", rule.getImpact());
jo.addProperty("node-count",
rule.getNodes().size());
jo.addProperty("tags",
rule.getTags().toString());
jo.addProperty("description",
rule.getDescription());
jo.addProperty("node-sample",
rule.getNodes().get(0).getFailureSummary()
+ " ~ " +
rule.getNodes().get(0).getHtml());
ja.add(jo);
}
break;
default:
System.out.println("Incorrect Task_Type is configured.
Please refer Guide_Task sheet.");
logger.info("inside selenideservice");
break;
}
resultMap.put("Result_Task", taskResult);
resultMap.put("Result_Expected", expectedResult);
resultMap.put("Result_Actual", actualResult);
resultMap.put("Result_Timestamp", "" + new Timestamp(date.getTime()));
return resultMap;
}
PropertyUtils.getProperties().getProperty("POSTGRES_dBUsername"),
PropertyUtils.getProperties().getProperty("POSTGRES_dBUserPass"));
String schemaName =
PropertyUtils.getProperties().getProperty("STUB_SCHEMA_NAME");
connection.setSchema(schemaName);
System.out.println(query);
rowsAffected = statement.executeUpdate(query);
return rowsAffected;
} catch (SQLException ex) {
System.out.println(ex.getMessage());
return 0;
} finally {
connection.close();
}
PropertyUtils.getProperties().getProperty("POSTGRES_dBUsername"),
PropertyUtils.getProperties().getProperty("POSTGRES_dBUserPass"));
String schemaName =
PropertyUtils.getProperties().getProperty("STUB_SCHEMA_NAME");
connection.setSchema(schemaName);
rowsAffected = statement.execute(query);
if (rowsAffected) {
rslt = statement.getResultSet();
if (rslt.next()) {
value = rslt.getString(1);
}
}
return value;
} catch (SQLException ex) {
System.out.println(ex.getMessage());
} finally {
connection.close();
}
return value;
return row1;
// writePDF(row1, 2);
return row2;
System.out.println(query);
rowsAffected = statement.executeUpdate(query);
return rowsAffected;
} catch (SQLException ex) {
System.out.println(ex.getMessage());
return 0;
} finally {
connection.close();
}
}
}
helper utility:
package com.intellect.digipay.otonom.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.text.BadElementException;
//import com.intellect.iso.automation.constant.ISOConstant;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.itextpdf.*;
@Service
public class ItextpdfhealperUtil {
// @Autowired
// PostgresDBUtils postgresDBUtils;
// @Value("${OUTPUT_FILE_NAME_PREFIX}")
// String OUTPUT_FILE_NAME_PREFIX;
//
// @Value("${OUTPUT_FILE_EXTENSION}")
// String OUTPUT_FILE_EXTENSION;
/* @Value("${POSTGRES_REMREP_SCHEMA_PROP}")
String POSTGRES_REMREP_SCHEMA_PROP;
@Value("${POSTGRES_ISO_SCHEMA_PROP}")
String POSTGRES_ISO_SCHEMA_PROP;
@Value("${DB_CONNECTION_DATABASE}")
String DB_CONNECTION_DATABASE;
@Value("${DB_CONNECTION_SCHEMA}")
String DB_CONNECTION_SCHEMA;*/
// @Value("${OUTPUT_FILE_PATH}")
// String OUTPUT_FILE_PATH;
System.err.println("initializePDF called");
if (gPDFDocument == null || !gPDFDocumentName.equals(pTestCaseName)) {
gPDFDocument = new Document(PageSize.A4.rotate());
//gPDFDocument.setMargins(20, -40, 30, 30);
gPDFDocument.setMargins(-60, -60, 30, 30);
//gPDFDocument.setMargins(marginLeft, marginRight, marginTop,
marginBottom)
gPDFDocumentName = pTestCaseName;
}
LocalDateTime curDateTime = LocalDateTime.now();
/*PdfWriter lPdfWriter = PdfWriter.getInstance(gPDFDocument,
new
FileOutputStream(OUTPUT_FILE_PATH+OUTPUT_FILE_NAME_PREFIX + pTestCaseName + "_"
+curDateTime.toString().substring(0, 19).replace("T", "").replace(":",
"").replace("-", "") + OUTPUT_FILE_EXTENSION ));
*/
System.err.println("Creating PDF a path {}"+ path);
PdfWriter lPdfWriter = PdfWriter.getInstance(gPDFDocument,
new FileOutputStream(path+"//"+ pTestCaseName + "_"
+curDateTime.toString().substring(0, 19).replace("T", "").replace(":",
"").replace("-", "") + ".pdf" ));
gPDFDocument.open();
// document.add(new Paragraph("lScriptOutput"+lScriptOutput));
}
if(valueToReplace!=null)pQuery = pQuery.replace(columnToReplace,
valueToReplace); // lDetails
// pQuery = postgresDBUtils.cleanSchemaName(pQuery);
writePDF(printDetails, 1);
int lRowCounter = 0;
ResultSetMetaData lRsMetaData = lRs.getMetaData();
int lColumnCount = lRsMetaData.getColumnCount();
List<List<String>> lFinalResult = new ArrayList<List<String>>();
if (true) {
while (lRs.next()) {
lRowCounter++;
lTempRecord = new ArrayList<String>();
lColumnCount = lRsMetaData.getColumnCount();
while (lColumnCount > 0) {
lTempRecord.add(lRs.getString(lColumnCount--));
}
lFinalResult.add(lTempRecord);
// lColumnCount = lRsMetaData.getColumnCount();
}
// logger.info("-----lFinalResult------{}", lFinalResult);
if (lRowCounter > 0) {
writePDF(lFinalResult, lRsMetaData.getColumnCount());
} else {
List<List<String>> lNoResult = new
ArrayList<List<String>>();
List<String> lNoRecord = new ArrayList<String>();
lNoRecord.add("No Result Found..!!");
lNoResult.add(lNoRecord);
// writePDF("", BaseColor.RED, true);
writePDF(lNoResult, 1);
}
}
else {
}
/*
* if (lRs != null) lRs.close();
*/
//row1.add(row2Details);
row1.add(row3Details);
row1.add(row4Details);
writePDF(row1, 2);
//gPDFDocument.add(linebreak);
/*writePDF(row2, 2);
gPDFDocument.add(linebreak);
writePDF(row3, 2);
gPDFDocument.add(linebreak);
writePDF(row4, 2);
gPDFDocument.add(linebreak);
gPDFDocument.add(linebreak);*/
table.setTotalWidth(40f * pColumnCounter);
table.setWidths(lColumnWidths);
gPDFDocument.add(table);
}
gPDFDocument.close();
//lPdfWriter.close();
image1.setAlignment(Element.ALIGN_CENTER);
image1.setBorderColor(BaseColor.BLACK);
image1.scaleAbsolute(500, 375);
gPDFDocument.add(image1);
propertyutils:
package Utilities;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
static {
properties = new Properties();
try {
ClassLoader classLoader = PropertyUtils.class.getClassLoader();
InputStream applicationPropertiesStream =
classLoader.getResourceAsStream("application.properties");
properties.load(applicationPropertiesStream);
} catch (Exception e) {
e.printStackTrace();
}
filepath = "D:\\Otonom\\Config\\config.properties";
try {
fileread = new FileReader(filepath);
return propertyvalue;
import java.util.HashMap;
import java.util.Map;
static {
propertyMap = new HashMap<String, String>();
}
application.property
#-----------------------------------------------------------------------
PostgresCofig------------------------
#----------------------Integration-------------
STUB_SCHEMA_NAME=iso_dev1
POSTGRES_URL=jdbc:postgresql://10.197.12.130:5432/cibciso
POSTGRES_dBUsername=cibciso
POSTGRES_dBUserPass=ISOdit@2022
#chrome_driver_path=D:\\MYDATAA\\Softwares\\chromedriver\\chromedriver.exe
#otonom_home=D:\\MYDATAA\\ISO_AUTOMATION\\Otonom\\
#config_file_name=shakedown.xlsx
config_file_name=Otonom_sanity_sheet.xlsx
browser=chrome
browser=firefox
#screenshot_location=D:\\MYDATAA\\ISO_AUTOMATION\\Otonom\\reports
config.property
##chrome_driver_path=D:\\project_workspace\\ISO_automation_3_sept\\
chromedriver_win32\\chromedriver.exe
##otonom_home=D:\\Otonom\\
##config_file_name=Otonom_sanity_sheet.xlsx
##browser=chrome
#
##-----------------------------------------------------------------------
PostgresCofig------------------------
##----------------------Integration-------------
##STUB_SCHEMA_NAME=digipay
##POSTGRES_URL=jdbc:postgresql://18.222.93.56:5432/igtb_k1_irel_fo
##POSTGRES_dBUsername=igtbk1irel_ro
##POSTGRES_dBUserPass=igtbk1irel_ro
#
#
#
#STUB_SCHEMA_NAME=digipay_iso
#POSTGRES_URL=jdbc:postgresql://10.197.12.75:5432/testdb
#POSTGRES_dBUsername=testdb
#POSTGRES_dBUserPass=testdb
log4j.property
name=PropertiesConfig
property.filename = logs
appenders = file
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1}
- %msg%n
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/logResult.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} -
%msg%n
appender.file.append=true
loggers=file
logger.file.name=com.intellect.digipay.otonom
logger.file.level = trace
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE
rootLogger.level = trace
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT