How To Generate And Insert Log In Selenium Webdriver Using log4j Jar

Assume you lot accept prepared evidence instance for your software spider web application evidence scenario (using selenium webdriver alongside eclipse as well as junit) as well as instantly you lot wants generate log file to insert your execution fourth dimension log messages inwards to it. How you lot volition create it? Selenium webdriver software testing tool don't accept whatever built inwards component division or method to generate log file. In this instance you lot tin role apache logging service. Let me depict you lot steps to generate log file inwards selenium webdriver test for software spider web application.

Steps To Generate And Insert Log In Selenium Webdriver

1. Download log4j jounce file from logging.apache.org
  • Click Here to become to log4j jounce file downloading page. (This Link URL may alter inwards future).
  • Click on Zip folder link equally shown inwards bellow image. Current version of log4j jounce file is log4j-1.2.17. Version of log4j jounce file may endure dissimilar inwards time to come due to the frequent version change.
  • When you lot click on zero folder link, it volition exhibit you lot zero mirror links to download folder. Download as well as relieve zero folder yesteryear clicking on mirror link.
  • Now Extract that zero folder as well as await within that extracted folder. You volition find log4j-1.2.17.jar file inwards it.
2. Import log4j-1.2.17.jar file inwards your eclipse projection from 
  • Right click on your projection folder as well as become to Build Path -> Configure Build path. It volition opened upward coffee construct path window equally shown inwards bellow image.
  • Click on Add External JARs push as well as select log4j-1.2.17.jar file. It volition add log4j-1.2.17.jar file inwards your construct path.
  • Click on OK push to unopen coffee construct path window.
3. Create Properties folder nether your projection folder as well as add log4j.properties file inwards it.
  • Create folder alongside refer = Properties nether your projection yesteryear correct clicking on your projection folder.
  • Click Here to download log4j.properties file as well as relieve it in Properties folder which is created nether your projection folder.
  • Now your properties folder nether projection folder volition looks similar bellow.
     
4. Set Run Configuration
This is optional step. You involve to laid your Run configure if log file is non generated as well as display bellow given alert message inwards your console when you lot run your evidence case. 
log4j:WARN No appenders could endure establish for logger (dao.hsqlmanager).
  • Go to Run -> Run Configurations -> Classpath
  • Select User Entries -> Click on 'Advanced' push -> Select Add Folder -> And as well as hence choose Properties folder from your projection as well as click on OK. Now your Class tab volition looks similar bellow.
5. Create example(Sample) evidence instance nether your project.
Create your ain evidence instance or re-create representative evidence instance from here as well as glue it inwards your degree file.

6. Import log4j header file inwards your project
Import bellow given header file inwards your evidence instance degree file.
import org.apache.log4j.*;

7. Replace bellow given syntax inwards your degree file as well as Run your evidence case.
@Test   populace void evidence () throws InterruptedException    {     Logger log;   driver.findElement(By.id("text1")).sendKeys("My First Name");   log = Logger.getLogger(Mytesting.class);   log.info("Type In Text field.");   Select mydrpdwn = novel Select(driver.findElement(By.id("Carlist")));   mydrpdwn.selectByVisibleText("Audi");   log = Logger.getLogger(Mytesting.class);   log.info("Select value from drib down.");   WebDriverWait hold off = novel WebDriverWait(driver, 15);   wait.until(ExpectedConditions.elementToBeClickable(By.id("text2")));   }

When your evidence instance for software spider web application is executed, Go to folder = C:\Logs. log.log file volition endure created over there. Open that file as well as await inwards to it. Log written inwards your software evidence instance volition endure inserted inwards your log file. In to a higher house example, Syntax marked alongside Pink color are written for inserting log. Now you lot tin write log at whatever house inwards your evidence instance of software spider web application equally shown inwards to a higher house example.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post