Skip to content

Commit eab6573

Browse files
committed
Log4j2
1 parent 374bb42 commit eab6573

File tree

11 files changed

+86
-16
lines changed

11 files changed

+86
-16
lines changed

logs/logs.log

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[INFO ] 2024-03-20 00:07:37.738 [main] WebDriverUtils - TESTING*************
2+
[INFO ] 2024-03-20 00:12:47.581 [main] WebDriverUtils - TESTING*************
3+
[ERROR] 2024-03-20 00:12:47.587 [main] WebDriverUtils - expected [test] but found [Test]

pom.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@
145145
<dependency>
146146
<groupId>org.apache.logging.log4j</groupId>
147147
<artifactId>log4j-core</artifactId>
148-
<version>2.17.0</version>
148+
<version>2.23.1</version>
149+
</dependency>
150+
151+
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
152+
<dependency>
153+
<groupId>org.apache.logging.log4j</groupId>
154+
<artifactId>log4j-api</artifactId>
155+
<version>2.23.1</version>
149156
</dependency>
150157

151158
<!-- phantom-js libraries -->

src/main/java/com/nci/automation/utils/CucumberLogUtils.java

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import com.nci.automation.web.WebDriverUtils;
44
import io.cucumber.java.Scenario;
5+
6+
7+
import org.apache.logging.log4j.LogManager;
8+
import org.apache.logging.log4j.core.Logger;
59
import org.openqa.selenium.OutputType;
610
import org.openqa.selenium.TakesScreenshot;
711
/**
@@ -14,6 +18,8 @@
1418
public class CucumberLogUtils {
1519

1620
public static Scenario scenario;
21+
public static Logger log = (Logger) LogManager.getLogger(CucumberLogUtils.class);
22+
1723

1824
/***
1925
* USE THIS METHOD TO ATTACH SCREENSHOT TO REPORT

src/main/java/com/nci/automation/web/WebDriverUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
public class WebDriverUtils {
2525

26-
private final static Logger logger = LogManager.getLogger(WebDriverUtils.class);
26+
public static Logger log = LogManager.getLogger(WebDriverUtils.class);
2727
public static WebDriver webDriver;
2828
public static Shadow shadowDriver = new Shadow(webDriver);
2929

src/main/resources/log4j.properties

-7
This file was deleted.

src/main/resources/log4j2.properties

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name=PropertiesConfig
2+
property.filename = logs
3+
appenders = console, file
4+
5+
appender.console.type = Console
6+
appender.console.name = STDOUT
7+
appender.console.layout.type = PatternLayout
8+
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
9+
10+
appender.file.type = File
11+
appender.file.name = console
12+
appender.file.fileName=${filename}/logs.log
13+
appender.file.layout.type=PatternLayout
14+
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
15+
16+
rootLogger.level = debug
17+
rootLogger.appenderRefs = file
18+
rootLogger.appenderRef.stdout.ref = STDOUT

src/main/resources/log4j2.xml.orig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Extra logging related to initialization of Log4j. Set to debug or trace if log4j initialization is failing. -->
3+
4+
<?xml version="1.0" encoding="UTF-8"?>
5+
<Configuration status="WARN">
6+
<Appenders>
7+
<Console name="Console" target="SYSTEM_OUT">
8+
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level - %msg%n"/>
9+
</Console>
10+
<File name="File" fileName="src/main/resources/log4j.log" append="true">
11+
<PatternLayout>
12+
<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level - %msg%n</Pattern>
13+
</PatternLayout>
14+
</File>
15+
</Appenders>
16+
<Loggers>
17+
<Logger name="com.cbiit.test.automation" level="info" additivity="true">
18+
<AppenderRef ref="Console"/>
19+
</Logger>
20+
<Root level="info">
21+
<AppenderRef ref="File"/>
22+
</Root>
23+
</Loggers>
24+
</Configuration>

src/test/java/ServiceNow/SSJ/playwright/Features/Applicant Profile.feature

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ Feature: Applicant Profile Scenarios
55
Scenario: Verify the Save application functionality
66
Given User is on SCSS Landing page and user is "Okta Verified Applicant" - PW
77
And User is on Profile tab - PW
8-
And User inputs "<firstName>" into first name field - PW
8+
# And User inputs "<firstName>" into first name field - PW
99
# And User inputs "<middleName>" into middle name field
10-
And User inputs "<lastName>" into last name field - PW
11-
And User inputs "<email>" into email field - PW
12-
And User inputs "<phone>" into phone field - PW
10+
# And User inputs "<lastName>" into last name field - PW
11+
# And User inputs "<email>" into email field - PW
12+
# And User inputs "<phone>" into phone field - PW
1313
# And User inputs "<businessPhone>" into business phone field
14-
And selects highest education "<Masters>"
14+
# And selects highest education "<Masters>"
1515
# And User confirms being a US Citizen - PW
1616
# And User inputs "<address>" into address field
1717
# And User inputs "<appNumber>" into appNumber field

src/test/java/ServiceNow/SSJ/playwright/Playwright_Runners/Run_SSJ_PW_Progression_Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
, features = "src/test/java/ServiceNow/SSJ/playwright/Features"
1010
, glue = "ServiceNow.SSJ.playwright.Steps"
1111
, tags = "@Progression"
12-
, dryRun = true
12+
, dryRun = false
1313
)
1414
public class Run_SSJ_PW_Progression_Test extends AbstractTestNGCucumberTests {
1515
}

src/test/java/ServiceNow/SSJ/playwright/Steps/ApplicantProfileSteps.java

+16
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
import com.microsoft.playwright.Locator;
44
import com.microsoft.playwright.Page;
55
import com.microsoft.playwright.options.AriaRole;
6+
import com.nci.automation.utils.CucumberLogUtils;
67
import com.nci.automation.utils.EncryptionUtils;
78
import com.nci.automation.utils.MiscUtils;
89
import com.nci.automation.web.ConfUtils;
910
import com.nci.automation.web.EnvUtils;
1011
import com.nci.automation.web.PlaywrightUtils;
12+
import com.nci.automation.web.WebDriverUtils;
1113
import io.cucumber.java.en.Given;
14+
import org.testng.Assert;
15+
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
18+
import java.util.List;
1219

1320
public class ApplicantProfileSteps {
1421

@@ -33,6 +40,15 @@ public void user_is_on_scss_landing_page_and_user_is_pw(String string) {
3340
// PlaywrightUtils.page.getByRole(AriaRole.RADIO, new Page.GetByRoleOptions().setName("Abhishek Desai Abhishek Desai")).click();
3441
PlaywrightUtils.page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Impersonate user")).click();
3542
PlaywrightUtils.page.navigate(EnvUtils.getApplicationUrl("AppTracker"));
43+
WebDriverUtils.log.info("TESTING*************");
44+
45+
try{
46+
Assert.assertEquals("Test", "test");
47+
}catch (AssertionError e){
48+
CucumberLogUtils.scenario.log(e.getMessage());
49+
WebDriverUtils.log.error(e.getMessage());
50+
}
51+
3652
}
3753

3854
@Given("User is on Profile tab - PW")

src/test/java/ServiceNow/SSJ/playwright/Steps/PlaywrightHooks.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package ServiceNow.SSJ.playwright.Steps;
22

3+
import com.nci.automation.utils.CucumberLogUtils;
34
import com.nci.automation.web.PlaywrightUtils;
45
import io.cucumber.java.After;
56
import io.cucumber.java.Before;
7+
import io.cucumber.java.Scenario;
68

79
public class PlaywrightHooks extends PlaywrightUtils {
810

911
@Before
10-
public void start(){
12+
public void start(Scenario scenario){
13+
CucumberLogUtils.scenario = scenario;
1114
setUp();
1215
}
1316

0 commit comments

Comments
 (0)