Commit 63d56aa8 authored by Arsam Ali's avatar Arsam Ali

updated log4j.properties file and xml file also updated logs filterizations

parent 91645247
......@@ -18,7 +18,7 @@ public class NisumPage {
By searchBox = By.name("q");
// By nisumFirstLink = By.xpath("//a[@href='https://www.nisum.com/'][normalize-space()='Nisum | A Technology Consulting Partner']");
By nisumFirstLink = By.xpath("//a[@href='https://www.nisum.com/']//h3[@class='LC20lb MBeuO DKV0Md'][normalize-space()='Nisum | A Technology Consulting Partner']");
By nisumFirstLink = By.xpath("//a[@href='https://www.nisum.com/']//h3[@class='LC20lb MBeuO DKV0Md'][normalize-space()='Nisum | A Technology Consulting Partner']");
By globalCareersBtn = By.xpath("//span[@class='mega-drop-4 loaded']");
public void searchForText(String searchText) {
......@@ -29,7 +29,7 @@ public class NisumPage {
public void clickFirstLink() {
// log.error("locator is incorrect of nisum first link click //a[@href='https://www.nisum.com/'][normalize-space()='Nisum | A Technology Consulting Partner']");
// log.error("locator of nisum link is incorrect //a[@href='https://www.nisum.com/'][normalize-space()='Nisum | A Technology Consulting Partner']");
WebElement firstLink = driver.findElement(nisumFirstLink);
firstLink.click();
}
......@@ -42,9 +42,9 @@ public class NisumPage {
Actions actions = new Actions(driver);
actions.moveToElement(globalCareers).perform();
// log.info("Hovered over the Global Careers button.");
log.info("Hovered over the Global Careers button.");
} catch (Exception e) {
// log.severe("Error occurred while attempting to hover over the Global Careers button: " + e.getMessage());
// log.error("Error occurred while attempting to hover over the Global Careers button: " + e.getMessage());
}
}
......
......@@ -7,7 +7,7 @@ import java.util.Map;
public class Main {
public static void main(String[] args) {
String logFilePath = "/Users/arsamali/Documents/IdeaProjects/POC-Arsam/src/main/resources/log4j2-error.log";
String logFilePath = "/Users/arsamali/Documents/IdeaProjects/POC-Arsam/src/main/resources/log4j4-error.log";
LogParser logParser = new LogParser();
List<String> errorLogs = logParser.extractErrors(logFilePath);
......
......@@ -3,48 +3,125 @@ package org.example.SastaTicketPage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class SastaTicketPage {
WebDriver driver;
private static final Logger log = LogManager.getLogger(SastaTicketPage.class);
private WebDriver driver;
public SastaTicketPage(WebDriver driver) {
this.driver = driver;
}
// Open homepage
public void openHomePage() {
log.info("locator of home page");
log.info("Opening SastaTicket homepage.");
driver.get("https://www.sastaticket.pk/");
System.out.println("Opened Sastaticket homepage.");
log.info("SastaTicket homepage opened successfully.");
}
public void IClickOnSearchField()
{
log.info("locator of search field");
driver.findElement(By.xpath("//span[@title='Lahore (LHE)']")).click();
// Correct locator for search field (info), forced error in error logging for testing
public void IClickOnSearchField() {
String correctLocator = "//span[@title='Lahore (LHE)']"; // Correct locator
String incorrectLocator = "//span[@title='NonExistentElement']"; // Forced incorrect locator for error logging
try {
// Attempt to interact with the element using the correct locator
log.info("Clicking on search field with correct locator: " + correctLocator);
WebElement searchField = driver.findElement(By.xpath(correctLocator));
searchField.click();
log.info("Search field clicked successfully.");
// Simulate error condition intentionally for testing
log.info("Simulating error for testing purposes...");
WebElement fakeElement = driver.findElement(By.xpath(incorrectLocator)); // This will trigger an exception
fakeElement.click(); // This line will not be reached
} catch (NoSuchElementException e) {
// Log an error when the forced wrong locator causes an exception
log.error("Error: Could not find search field with locator: " + incorrectLocator);
}
}
public void IClickOnSearchFieldDestination()
{
log.info("locator of Destination field");
driver.findElement(By.xpath("//input[@id='rc_select_1']")).click();
// Correct locator for destination field (info), forced error in error logging for testing
public void IClickOnSearchFieldDestination() {
String correctLocator = "//input[@id='rc_select_1']"; // Correct locator
String incorrectLocator = "//input[@id='NonExistentInput']"; // Forced incorrect locator for error logging
try {
log.info("Clicking on destination field with correct locator: " + correctLocator);
WebElement destinationField = driver.findElement(By.xpath(correctLocator));
destinationField.click();
log.info("Destination field clicked successfully.");
// Simulate error condition intentionally for testing
log.info("Simulating error for testing purposes...");
WebElement fakeElement = driver.findElement(By.xpath(incorrectLocator)); // This will trigger an exception
fakeElement.click(); // This line will not be reached
} catch (NoSuchElementException e) {
log.error("Error: Could not find destination field with locator: " + incorrectLocator);
}
}
// Correct locator for destination city selection, only run error if an exception is caught
public void selectDestinationCity() {
log.info("locator of destination city");
driver.findElement(By.xpath("//h5[normalize-space()='Karachi, Pakistan (KHI)']")).click();
String correctLocator = "//h5[normalize-space()='Karachi, Pakistan (KHI)']"; // Correct locator
String incorrectLocator = "//h5[normalize-space()='NonExistentCity']"; // Forced incorrect locator for error logging
try {
log.info("Selecting destination city with correct locator: " + correctLocator);
WebElement destinationCity = driver.findElement(By.xpath(correctLocator));
destinationCity.click();
log.info("Destination city selected successfully.");
// Simulate error condition intentionally for testing
log.info("Simulating error for testing purposes...");
WebElement fakeElement = driver.findElement(By.xpath(incorrectLocator)); // This will trigger an exception
fakeElement.click(); // This line will not be reached
} catch (NoSuchElementException e) {
log.error("Error: Could not find destination city with locator: " + incorrectLocator);
}
}
// Correct locator for date selection, only run error if an exception is caught
public void clickDate() {
driver.findElement(By.xpath("//div[@id='oneway-return-October 2024']//div[contains(@class,'_2k3ukgGnI_cvavzvhX3w4T')][normalize-space()='11']")).click();
String correctLocator = "//div[@class='ant-col _3xTiXZL3weCRW_cW7BB1TW j18oDGKsHFCUVl6dCIeWr']//div[@class='bMmOjUs6T-Jm0Z_w3DUKj']"; // Correct locator
String incorrectLocator = "//div[@class='NonExistentDate']"; // Forced incorrect locator for error logging
try {
log.info("Clicking on date field with correct locator: " + correctLocator);
WebElement date = driver.findElement(By.xpath(correctLocator));
date.click();
log.info("Date field clicked successfully.");
// Simulate error condition intentionally for testing
log.info("Simulating error for testing purposes...");
WebElement fakeElement = driver.findElement(By.xpath(incorrectLocator)); // This will trigger an exception
fakeElement.click(); // This line will not be reached
} catch (NoSuchElementException e) {
log.error("Error: Could not find date field with locator: " + incorrectLocator);
}
}
// Correct locator for search flight button, only run error if an exception is caught
public void clickSearchFlight() {
driver.findElement(By.xpath("//span[normalize-space()='Search Flights']")).click();
String correctLocator = "//span[normalize-space()='Search Flights']"; // Correct locator
String incorrectLocator = "//span[normalize-space()='NonExistentSearchButton']"; // Forced incorrect locator for error logging
try {
log.info("Clicking on search flight button with correct locator: " + correctLocator);
WebElement searchFlightButton = driver.findElement(By.xpath(correctLocator));
searchFlightButton.click();
log.info("Search flight button clicked successfully.");
// Simulate error condition intentionally for testing
log.info("Simulating error for testing purposes...");
WebElement fakeElement = driver.findElement(By.xpath(incorrectLocator)); // This will trigger an exception
fakeElement.click(); // This line will not be reached
} catch (NoSuchElementException e) {
log.error("Error: Could not find search flight button with locator: " + incorrectLocator);
}
}
}
#name=PropertiesConfig
#property.filename = logs
#appends = console, 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}/logs.log
#appender.file.layout.type=PatternLayout
#appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
#
#rootLogger.level = debug
#rootLogger.appenderRefs = file
#rootLogger.appenderRef.stdout.ref = LOGFILE
name=PropertiesConfig
property.filename = logs
appends = console, file
# Console appender configuration
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
# File appender configuration
appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/logs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
rootLogger.level = debug
rootLogger.appenderRefs = file
rootLogger.appenderRef.stdout.ref = LOGFILE
\ No newline at end of file
# Set the root logger level to 'error' to only log error-level messages
rootLogger.level = error
rootLogger.appenderRefs = file, console
rootLogger.appenderRef.file.ref = LOGFILE
rootLogger.appenderRef.console.ref = STDOUT
......@@ -12,7 +12,7 @@
<Loggers>
<!-- Logger for NisumPage class, can be adjusted as per package -->
<Logger name="com.org.example" level="info" additivity="true">
<Logger name="com.org.example" level="info" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment