Test Case with Log4j Logging..
Create a new XML file – log4j.xml and place it under the Project root folder and Paste the following code in the log4j.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="fileAppender" class="org.apache.log4j.FileAppender">
<param name="Threshold" value="INFO" />
<param name="File" value="logfile.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{1}] %m %n" />
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="fileAppender"/>
</root>
</log4j:configuration>
Now Write The Code for logging information.

package automationFramework;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Log4j {
private static WebDriver driver;
private static Logger Log = Logger.getLogger(Log4j.class.getName());
public static void main(String[] args) {
DOMConfigurator.configure("log4j.xml");
// Create a new instance of the Firefox driver
        driver = new FirefoxDriver();
        Log.info("New driver instantiated");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Log.info("Implicit wait applied on the driver for 10 seconds");
        //Launch the Website
        driver.get("http://www.qaselenium.blogspot.in/");
        Log.info("Web application launched");
        // Find the element that's ID attribute is 'account'(My Account)
        driver.findElement(By.id("account")).click();
        Log.info("Click action performed on My Account link");
        // Find the element that's ID attribute is 'log' (Username)
        // Enter Username on the element found by above desc.
        driver.findElement(By.id("log")).sendKeys("user_1");
        Log.info("Username entered in the Username text box");
        // Find the element that's ID attribute is 'pwd' (Password)
        // Enter Password on the element found by the above desc.
        driver.findElement(By.id("pwd")).sendKeys("user@123");
        Log.info("Password entered in the Password text box");
        // Now submit the form. WebDriver will find the form for us from the element
        driver.findElement(By.id("login")).click();
        Log.info("Click action performed on Submit button");
        // Print a Log In message to the screen
        System.out.println(" Login Successfully.");
         // Find the element that's ID attribute is 'account_logout' (Log Out)
        driver.findElement(By.id("account_logout"));
        Log.info("Click action performed on Log out link");
        // Close the driver
        driver.quit();
        Log.info("Browser closed");
}
}

we have to place a file called logfile.log in project folder.



The Logs will be generated like below.



81 comments:

  1. Nice one and recommanded.very clear explanation best regards from sbrtrainings

    ETL TESTING online

    ReplyDelete
  2. Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason it is referred to as a Suite. This blog gives great view for selenium beginners. Learn Selenium from the best Selenium Online Training in your locality at CatchExperts.com

    ReplyDelete
  3. very useful content .one of the recommanded blog very appriciated thank you for giving such nice content best regards from sbr

    selenium free training

    ReplyDelete
  4. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  5. I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for newbies. Could you please extend them a little from next time? Thanks for the post..

    Web development company in Chennai

    ReplyDelete
  6. This is really a great post. Thank you for taking time to provide us some of the useful and exclusive information with us. Keep on blogging!!

    Seo Training in Chennai

    ReplyDelete
  7. the best and very useful blogs for learner each and every concept explain in easy way thank you for sharing such a nice content.keep on update latest information all the best
    Selenium Online Training usa|uk|canada|australia

    ReplyDelete
  8. I have own car so now I am back out there trying to show him how to do car repairs. Your blog is an excellent source of info, thanks.

    bike spa services in mumbai
    house cleaning services in mumbai
    car wash services in mumbai

    ReplyDelete

  9. I do believe all of the concepts you’ve introduced in your post. They’re very convincing and will definitely work. Nonetheless, the posts are too short for novices. May you please extend them a bit from subsequent time? Thank you for the post.

    Selenium Training in Chennai

    ReplyDelete
  10. Very informative blog and very useful article thank you for sharing with us , keep posting learn more about selenium training , selenium online training

    ReplyDelete
  11. Appium Training in chennai
    We provides Best Appium Training in Chennai with real time project assistance by our leading Appium mobile App Automation testing architect
    For Free Live Demo @ Call to 8122241286.
    Appium ,Selenium,Mobile Automation Testiing using Android and IOS
    www.thecreatingexperts.com 
    Appium training in chennai

    ReplyDelete
  12. This is a great post. I like this topic.This site has lots of advantage. It helps me in many ways.Thanks for posting this again.
    Back to original

    ReplyDelete
  13. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  14. Hey friends, it was a great experience to learn from selenium.
    Talk to eight one two two two four one two eight six
    www.thecreatingexperts.com

    selenium training in chennai

    ReplyDelete
  15. Hey friends, it was a great experience to learn from selenium.
    Talk to eight one two two two four one two eight six
    www.thecreatingexperts.com

    selenium training in chennai

    ReplyDelete
  16. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India

    ReplyDelete
  17. selenium is a booming course now a days there is a large demand for the selenium developers in IT industry

    suntrainings provide best online and classroom training by the professional experts

    ReplyDelete
  18. Join them for the best selenium training in Chennai and placements.
    Call them at 8122241286.
    www.thecreatingexperts.com
    selenium training in chennai

    ReplyDelete
  19. Nice Blog, Thank you for sharing nice article. It's useful to us.

    Online Selenium Training

    ReplyDelete
  20. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  21. Create HTML, Error and Execution logs using log4j -Create more than 2 log files:
    http://corejavaselenium.blogspot.in/2015/08/create-html-error-and-execution-logs.html

    ReplyDelete
  22. This one is much helpful, Very clear explanation about the topic.

    Latest Update here: Selenium Training in Chennai

    ReplyDelete
  23. The biggest change in Selenium recently has been the inclusion of the WebDriver API. Driving a browser natively as a user would either locally or on a remote machine using the Selenium Server it marks a leap forward in terms of browser automation.

    Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
    Selenium Training Institute in Chennai

    ReplyDelete
  24. LEARN | GET JOB | HAPPY LIFE @ TIT Academy
    Thank you so much for sharing. it’s useful for me.
    Learn a training in Best Institute & get a 100% placement Assistant................
    Selenium Training in Chennai
    Dot Net Training in Chennai

    ReplyDelete
  25. From My search…Creating Experts provides Best SAP MM training (http://thecreatingexperts.com/sap-mm-training-in-chennai/)with real time projects assistance. Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage. They also provide placement assistance in leading MNC companies across the globe according to the current requirements.
    And these are the Best SAP MM training institute which provides Real Time Hands on Training…
    Codedion Technologies-9003085882
    Creating Experts (http://thecreatingexperts.com/)-8122241286
    They also providing both Classroom/Online Training

    ReplyDelete
  26. I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job . If anyone want Java Training in Chennai, Please visit our page Selenium Training in Chennai

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. Mind Q systems is a leading institute in training career successful and job oriented courses, providing <a

    href=http://mindqsystems.com/online-training.php>selenium online training</a> better implementations

    services at affordable prices. You can visit Mind Q systems to know more about <a

    href=http://mindqsystems.com/courses/11/selenium-training.php>selenium online training in

    Bangalore</a>, visit our site

    ReplyDelete
  29. Thanks for sharing this blog.This is very helpfull.Keep posting like this blog.
    Even I have done Selenium course from Seleniumlabs.
    After finishing the course I got job in MNC company.Seleniumlabs helps me a lot
    to learn selenium with Java course.I was new in Java but trainer was very
    knowledgeable,he knows how to explan Java in easy way,he has 15 years of
    experience in automation.I spent very good time with them.If anyone wants
    to learn selenium course specially who don't know Java.http://www.seleniumlabs.in

    ReplyDelete
  30. Looking for best training in SELENIUM, take a glance at http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  31. I was looking for Selenium and Appium training in Chennai and got a link,it was the CREATING EXPERTS awesome training with real-time scenarios,got a good exposure to learn things best.If you are looking for one click the link below and contact 8122241286.

    http://thecreatingexperts.com/appium-training-in-chennai/
    http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  32. The biggest change in Selenium recently has been the inclusion of the WebDriver API. Driving a browser natively as a user would either locally or on a remote machine using the Selenium Server it marks a leap forward in terms of browser automation.

    Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
    Selenium Training Institute in Chennai |
    Selenium Tutorials

    ReplyDelete
  33. Thanks for sharing this blog.Creating Experts provides Best training in selenium

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  34. nice blog...The leading training concern THE CREATING EXPERTS are providing SELENIUM training and here is the link

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286



    ReplyDelete
  35. Thanks for sharing this blog.Creating Experts provides Best training in selenium

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  36. I was looking for Selenium and Appium training in Chennai and got a link,it was the CREATING EXPERTS.

    If you are looking for one click the link below and contact 8122241286.

    http://thecreatingexperts.com/appium-training-in-chennai/
    http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  37. The Creating Experts is the leading trainer in selenium so, if you are looking for one here is the link

    http://thecreatingexperts.com/selenium-in-chennai/

    contact +91-08122241286

    ReplyDelete
  38. THE CREATING EXPERTS is one of the leading training provider in SELENIUM they provide hands on training with real time scenario

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  39. nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    java training in chennai

    ReplyDelete
  40. The Creating Experts provides training in SELENIUM

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  41. Nice tutorial iam reading your article really it is very helpful for providing a lot of information about Selenium …. Thank you Please keep share some more…………

    ReplyDelete
  42. nice blog...Selenium training is offered by THE CREATING EXPERTS in Chennai

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  43. This comment has been removed by the author.

    ReplyDelete
  44. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  45. Nice Blog, Thank you for sharing nice article. It's useful to us.
    Best Oracle Training in Bangalore

    ReplyDelete
  46. I have read your blog its very attractive and impressive. I like your blog selenium Online course Hyderabad

    ReplyDelete
  47. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
    "Java Training in Marathahalli"

    ReplyDelete
  48. The post is very nicely written and it contains many useful facts. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement. Thanks for sharing with us.
    Web Development Services in Bangalore
    BEST web design services in bangalore
    ECommerce Website developers in bangalore
    Outsource magento ecommerce services india

    ReplyDelete
  49. Thanks for sharing your knowledge. It will be helpful for us.

    ReplyDelete
  50. At Coepd - (Center of Excellence for Professional Development) Manual & Selenium testing training program is designed to give participants the skills & knowledge to gain a competitive advantage in starting/enhancing a career in software testing. We provide the attendee's software testing service which is required to ensure that tested applications meet all application requirements. Participants receive up-to-date training in multiple areas in Software Testing and a thorough understanding of real-world projects.

    http://www.coepd.com/TestingTraining.aspx

    ReplyDelete
  51. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Selenium Training Institute in Chennai

    ReplyDelete
  52. I really enjoy the blog.Much thanks again. Really Great selenium Online Training Bangalore

    ReplyDelete
  53. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
    The Best Selenium Training in Chennai Chennai | Selenium Training institutes in Chennai

    ReplyDelete
  54. Thanks for you sharing to spread out your knowledgeSelenium Training in Chennai

    ReplyDelete
  55. It is a great job that you are working and offer our necessary need to your posts. We like your job and wish you all the best.
    digital marketing company in india

    ReplyDelete
  56. Industrial Automation training and Placement program for fresher engineer in Delhi NCR. Those engineer who are interested in Automation sector we can provide a basic platform. We are train you initial level. Contact:- 91-9310096831.

    ReplyDelete
  57. The most popular destination for Hadoop Training in

    Noida
    in NOIDA is CIITNOIDA in Sector-2

    You can Master the various components of Hadoop ecosystem like Hadoop, MapReduce Architecture, Pig, Hive, HBase, Sqoop, Flume by their Senior Experts

    from Industry with good Industrial experience of handling big projects.

    You can even Get hands-on practice with live projects and ORACLE certification at CIITNOIDA.

    This Big Data Hadoop Training in Noida is best

    suited for CS & IT Engineering Students, professionals looking to gain expertise in Big Data and work for Fortune 500 Software Companies.

    Hadoop Training in Noida
    Big Data Hadoop Training in Noida

    ReplyDelete
  58. thanks for sharing the information.
    Indian Cyber Army’s most awaited internship is live now. Summer Internship 2018 on “ Ethical hacking” and book your seats before it runs out.Candidates have to get themselves registered to be a part of this Internship program. Here internship will give you on-the-job experience, help you learn whether you and Cyber security industry are a good match and can provide you with valuable connections and references. Here interns are usually exposed to a wide variety of tasks and responsibilities which allows the intern to showcase their strengths by working on projects for various managers that work on different parts of Indian Cyber Army. Becoming a high performing intern is a fantastic way to improve your employment prospects. This internship can be a great way to get your foot in the door of success with a prestigious or desirable Organization.As career in ethical hacking is most in demand.

    ReplyDelete
  59. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training Bangalore

    ReplyDelete
  60. thanks for sharing the more valuable information.
    Indian Cyber Army credibility in Ethical hacking training & Cybercrime investigation training is acknowledged across nation as we offer hands on practical knowledge and full assistance with basic as well as advanced level ethical hacking & cybercrime investigation courses. The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hacking/ cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure.Ethical hacking training ,
    Ethical hacking course

    ReplyDelete
  61. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training Hyderabad

    ReplyDelete
  62. In the last few months we've seen a lot of Health Care Reform rules and regulations being introduced by the Health and Human Services Department. Every time that happens, the media gets hold of it and all kinds of articles are written in the Wall Street Journal, the New York Times, and the TV network news programs talk about it. All the analysts start talking about the pros and cons, and what it means to businesses and individuals. Health is God

    ReplyDelete
  63. I think this is a real great article post.Really looking forward to read more. Visit at
    Crazy Video Hub

    ReplyDelete
  64. Nutra Trials defines personal characteristics of different health products including skincare, weight loss, muscle and male enhancement. The study presented here is briefly described for reader convenience and to deliver them assurance with health standards. The best possible answers are given here regarding the selection of an ideal supplement or cream or serum that possibly remains to be safe for health and do not cause any side effects.

    ReplyDelete
  65. It is a great job, I like your posts and wish you all the best. and I hope you continue this job well.
    NutraT line

    ReplyDelete
  66. This is a great post ! it was very informative. I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it..
    kim kardashian sex tape
    porn sex video hd
    mia khalifa sex video
    sunny leone sexy movie

    ReplyDelete