I need to create a dll log file using Selenium Webdriver with C#. Errors generated while running the C# code need to saved in this text file using that dll. How do I go about achieving this?

  • Voted to close as offtopic, saving text to files is a typical programming issue and not test related. Not even when it is combined with Selenium as they are not related. – Niels van Reijmersdal Feb 7 '17 at 12:41

@NarendaC: original post uses Selenium C# not Java

@admin: Sorry, I cannot put a comment. Please move/remove if needed.

  • You can edit my answer if needed and specific to language. But core idea I shared. Does it really language specific? – NarendraC Aug 11 '16 at 7:10
  • I agree with your core idea and I don't know the answer too, but I think it is not easy for a guy that works on Selenium .NET binding to convert the idea from Java to C# if he does not have any experience on Java :) – Tam Minh Aug 11 '16 at 7:22

Im not sure about the question you are asking but the below lines of codes might help you.

string nomfichiersource = "UITestActionLog.html";
            string nomTest = TestContext.TestName.ToString();
            string sourcefile = System.IO.Path.Combine(TestContext.TestResultsDirectory, nomfichiersource);
            string destfile = System.IO.Path.Combine(@"G:\Projects\", nomTest + ".html");
            System.IO.File.Copy(sourcefile, destfile, true);

This will generate a html file with the logs.

And this works with MSTest.


Solution -

Its as simple aswe integrate JUnit or TestNG in our Selenium Project. Similar way to use it. Steps are as below:

  1. I have used log4j for creation of log file. You can add log4j in your project. Need to download log4j.jar first
  2. To add in your selenium project by
    • Right click on your project
    • Click Configure build path
    • From library section, Add external jar file
    • Select the log4j.jar or provide path & Save
  3. For log4j, we need to add few line of code in log4j.properties file. Ready code you can refer here

Not the answer you're looking for? Browse other questions tagged or ask your own question.