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?
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.
Its as simple aswe integrate JUnit or TestNG in our Selenium Project. Similar way to use it. Steps are as below:
- I have used log4j for creation of log file. You can add log4j in your project. Need to download log4j.jar first
- 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
- For log4j, we need to add few line of code in log4j.properties file. Ready code you can refer here