I am trying to run my selenium-testng program using log4j.properites. i would like to know how to integrate my testng class with log4j.properties.
- I have create a sample google logintest using testNG
- I have created log4j.properties under src/main/resources
- I have written logger piece for code Logger log = Logger.getLogger(loginTest.class.getName());
I tried running the test, but i couldnt see any log getting generated. Now I am not sure about the next steps - could someone please guide me.
public class loginTest {
WebDriver driver; Logger log = Logger.getLogger(loginTest.class.getName()); @BeforeMethod public void setUp() { System.setProperty("webdriver.chrome.driver" , "C:/Users/User/Desktop/Selenium Drivers/chromedriver.exe"); driver = new ChromeDriver(); driver.get("https://www.google.com/"); driver.manage().window().maximize(); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); } @Test public void titleTest() { String title = driver.getTitle(); System.out.println(title); Assert.assertEquals(title, "Google"); } @Test public void gmailLogoTest() { boolean b = driver.findElement(By.linkText("Gmail")).isDisplayed(); Assert.assertTrue(true); } @AfterMethod public void tearDown() { driver.quit(); }
}
Set level
log4j.rootCategory=debug, console, file
Appender which writes to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{MM-dd-yyyy HH:mm:ss} %F %-5p [%t] %c{2} %L - %m%nAppender which writes to a file
log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=application.log
Defining maximum size of a log file
log4j.appender.file.MaxFileSize=10mb log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p [%t] %c{1}:%L - %m%n log4j.appender.file.Append=true