1

I am trying to learn selenium.

I get following error message:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

So, I have downloaded the file log4j.properties and I have googled on it and tried to implement the file in different ways in Eclipse but nothing worked out. I see that someone is saying:

Put a file named log4j.properties in the root of your classpath:

log4j.rootLogger = ALL, Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.conversionPattern=%m%n

Nothing else is needed. Log4j will discover it and configure itself.

But what do they mean by "in the root of your classpath"?

I work in Eclipse. So how do I find the root of the classpath in Eclipse?

sazzad
  • 5,740
  • 6
  • 25
  • 42
AndersK
  • 11
  • 1
  • 1
  • 3
  • Have you seen these questions - http://stackoverflow.com/questions/26335815/need-to-remove-log-file-warning-in-selenium? http://stackoverflow.com/questions/25997556/no-appenders-could-be-found-for-logger-org-apache-http-client-protocol-requesta – LittlePanda Apr 08 '15 at 16:14

3 Answers3

5

It looks like you need to add the location of your log4j.properties or log4j.xml file to the Classpath in Eclipse.

Make sure your project is open in Eclipse, then click on the "Run" menu at the top of Eclipse and click on the following:

Run -> Run Configurations -> Classpath (tab) -> User Entries -> Advanced (button on the right) -> Add Folders ->then navigate to the folder that contains your log4j.properties file

Apply -> Run

The error message should no longer appear.

Nimisha
  • 177
  • 1
  • 2
  • 12
0

Did you simply try to put it in your source folder? It should be copied automatically to your deployment folder on build. If you already tried, it may be your deployment rules that skip *.properties files...

Hope that will help you

Yosef-at-Panaya
  • 676
  • 4
  • 13
  • 1
    How doesn't it answer to the question?The "root of your classpath" is precisely the deployment folder, and it should be copied automatically to there from source folder by Eclipse, and then the log4j configuration file should be find by the java VM... – Yosef-at-Panaya Apr 08 '15 at 21:19
  • Thanks for taking your time here. I have put the log4j files in the source folder including the one above but it doesn't help. I also tried to put the code example that I got from Little Panda in my code but it does not help. If I look into the .properties files and compare them with other .properties files that people suggest I see that they differ. I downloaded the log4j files from SourceForge. If you can come up with any more suggestions it would be appreciated. I am reading an excel file and that actually works out fine but I get this annoying error message all the time – AndersK Apr 09 '15 at 09:30
  • @YosefY: You write: it may be your deployment rule that skip *.properties files... How do I check that? – AndersK Apr 09 '15 at 09:50
  • Excuse me, as described here: http://www.toolsqa.com/selenium-webdriver/test-case-with-log4j/ it seems that the log4j configuration file should be put in the project folder (see the picture http://www.toolsqa.com/wp-content/uploads/2014/03/Log4j-FTC.png taken from the link above). You can also find there a valid log4j.xml configuration file. If you want to check that yours is correct you can simply write a simple main in your project, execute it and see if the configuration initialization warning is still there... – Yosef-at-Panaya Apr 09 '15 at 13:23
  • What I see now is that whatever testfile I run I get this error message. This wasn't there at all before. So, there must be something in my Eclipse / Selenium settings that all of a sudden has changed. How do I check that? I have created a new xml file as they suggest on the link that you suggested but it doesn't help. – AndersK Apr 13 '15 at 10:13
0

Delete the log4j.rar from your external Libraries

steps: Right click on src-->BuildPath-->Configure Buildpath-->Libraries-->Select Log4j.rar and Remove it.

For report generation, you need to add log4j for simply executing the script no need to add log4j.

Hope this will solve your problem

Rinash
  • 1
  • 2