Code & QA

Event Logging

If you carefully look at the code of Report class you will notice that the report is composed in the very end of the current test session. So during the session, all log data is stored in the computer’s memory. So the question is what if the computer crashes (electricity is switched off occasionally, OS is independently restarted or some system error has occurred and interrupted test execution)? Ok, in that case, no report is composed and saved, moreover it will be disposed out from computer memory and you’ll never know what the result of the test session was. I understand that such kind of crashes is the pretty rare case but there always is such possibility. That’s why I decided to make some improvements to Report class – I added synchronous logging of a current event into a simple text file. So if something goes wrong and a summary report is not saved you will likely be able to see what’s happened in the text file. Sure, it is not so user-friendly as the report but it is for emergency cases only and presumably will be used very seldom.

I put current event logging into a text file named log.txt inside of current test session folder.

So, how to step by step.

1. I added a logFilePath variable to Report class for storing log file local drive path and doEventLogging variable to determine if logging should be provided

[gist id=e8a05f4ca8c9cb6c6867ee0cf3973827]

indicates if event logging must be provided

[gist id=3aa257faceb41ed80b4ede108403411a]

2. Also it is necessary to set a value to logFilePath variable. I do it in StartTestSession() method (see below)

3. Method Log for easier writing to file

[gist id=15ac00865c0957548a10de1f248e5d83]

4. Update of following methods:

[gist id=b8bcf409acdef215239acc932f597968]

By default event logging is turned off (doEventLogging variable is initially False). Set doEventLogging variable to True if you want to switch the functionality on. Pay attention that you may change the variable’s value whenever you like, you may switch it between True and False during the session – it just will make event logging active or not. Obviously that for having full log file doEventLogging variable should be initialized before StartTestSession() method is invoked, i.e. in BaseTest.SetUpAssembly() method.

[gist id=78d78f127745ece95cd3b579a9d00627]

Test Run Summary Report

Table Of Content

Configuration

Leave a Reply