cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed with scripting interface to current test log during test run

SOLVED
Highlighted
Regular Contributor

Help needed with scripting interface to current test log during test run

I've scripted an event handler for OnStopTest to email the project test run results. 



I'd assumed that the log would be compiled before the OnStopTest fires but that does not appear to be the case. Unfortunately I discovered through trial and error and reading documentation that there is no scripting interface to the test log of the current run. 



Am I correct in thinking that we would need to have a second script that runs after our test run is completed (Event Handlers and all)  to email the test results out?



http://support.smartbear.com/viewarticle/55140/?_ga=1.145209844.1554134704.1392816096



I look forward to anyone's suggestions!
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Valued Contributor

RE: Help needed with scripting interface to current test log during test run

I believe you can call a savelogfile method Log.SaveResultsAs() and attach to an email. As a solution to this problem I actually create my own HTML log with just errors/warnings listed by using the onerror and onwarning events (is cleaner than the built in log & I can design it myself this way).

As far as creating the email in JScript you can use something like this:






function sendemail(mfrom,mto,msubject,mbody,mattach){



mconfig = new ActiveXObject('CDO.Configuration');


mconfig.fields.item(schema + 'sendusing') = 2; //cdoSendUsingPort;


mconfig.fields.item(schema + 'smtpserver') = //SMTP server


mconfig.fields.item(schema + 'smtpserverport') = 525; // Port number


//mConfig.Fields.Item(schema + 'sendusername') = ''; // User name (if needed)


//mConfig.Fields.Item(schema + 'sendpassword') = ''; // User password (if needed)


mconfig.fields.update();


message = new ActiveXObject('CDO.Message');


message.configuration = mconfig;


message.from = mfrom;


message.to = mto;


message.subject = msubject;


message.htmlbody = mbody;

message.addattachment mattach;


message.send(); //Send Email


}






''-Praise the sun and Give Kudos.''

View solution in original post

11 REPLIES 11
Highlighted
Valued Contributor

RE: Help needed with scripting interface to current test log during test run

I believe you can call a savelogfile method Log.SaveResultsAs() and attach to an email. As a solution to this problem I actually create my own HTML log with just errors/warnings listed by using the onerror and onwarning events (is cleaner than the built in log & I can design it myself this way).

As far as creating the email in JScript you can use something like this:






function sendemail(mfrom,mto,msubject,mbody,mattach){



mconfig = new ActiveXObject('CDO.Configuration');


mconfig.fields.item(schema + 'sendusing') = 2; //cdoSendUsingPort;


mconfig.fields.item(schema + 'smtpserver') = //SMTP server


mconfig.fields.item(schema + 'smtpserverport') = 525; // Port number


//mConfig.Fields.Item(schema + 'sendusername') = ''; // User name (if needed)


//mConfig.Fields.Item(schema + 'sendpassword') = ''; // User password (if needed)


mconfig.fields.update();


message = new ActiveXObject('CDO.Message');


message.configuration = mconfig;


message.from = mfrom;


message.to = mto;


message.subject = msubject;


message.htmlbody = mbody;

message.addattachment mattach;


message.send(); //Send Email


}






''-Praise the sun and Give Kudos.''

View solution in original post

Regular Contributor

RE: Help needed with scripting interface to current test log during test run

Thanks Ryan. So I used your suggestion of creating my own log. I did the following:



1. Various Event scripts increment different ProjectSuite variables (test passed, warning message, error message).

2. OnStopTest script finds the name of the test currently running and the name of the last test in the test run. If these match then I am at the end of the test run and the remainder of the script is executed and does the following:

2.1  Perform opertations on ProjectSuite.Variables to generate some test metrics (number of tests passed, number of tests failed, total number of tests).

2.2  Format the test metrics nicely into a message body suitable for email and export the test logs (mht format) to local drive. 

2.3  Send an email notification using SendMail method, message body contains test metrics and log is attached to email. 



Seemed like a lot of work and felt like I was working around the TC framework to achieve something that should be available out of the box. Ie. providing a scripting interface to the current test run. 
Highlighted
Valued Contributor

RE: Help needed with scripting interface to current test log during test run

Well they do provide the method out of the box I just prefer to have things my own way that is why I created my own logs. The help file is actually pretty good about explaining how to email log files (as I previously noted) and such which is where I got the idea to begin with, but it seems like everyone uses Test Complete in a lot of very different ways so it's understandable to me that it works the way it does. Glad I could help though!

''-Praise the sun and Give Kudos.''
Highlighted
Regular Contributor

RE: Help needed with scripting interface to current test log during test run

Hi Ryan,



My issue was that I couldnt access the current test run logs data during a test run. For example, getting the number of tests passed and failed by using the Status property of the LogItem object (http://support.smartbear.com/viewarticle/55562/?_ga=1.87424088.1554134704.1392816096)



You can only access current test run data after the test run and the event handlers have all stopped running. When I say 'during a test run' I was trying to get the logs as the final step in my test run by scripting it in the OnStopTest Event. 



I  found this in SmartBear documentation which confirms there is no scripting interface to the current test log during a test run. 





  • TestComplete does not provide a scripting interface to the test log of the current run. TestComplete is compiling the log during the test execution and this process is only finished when the test is complete. Scripts can access the log only after it has been added to the list of project logs that is displayed in the Project Explorer panel.



Assuming I used the scripting interface to acces the logs which is the 'out of box' solution I would have to have a second test run scheduled after the one I want the results for and get the test results using the Log methods. 



Is there a way of getting data from the current test run logs before the test run is terminated other than scripting your own solution, ie. creating your own test log? 

Having a scripting interface that can't access the current run doesnt make a lot of sense to me unless I am not understanding how it can be used. Test complete obviously holds this data somewhere before compiling it at the end of the test run, you'd think there would be a way to access it during or at least as the final step in a test run.

Highlighted
Regular Contributor

RE: Help needed with scripting interface to current test log during test run

Also found this caveat on the same documentation page: 



The LogResults object provides access to project logs listed in the Project Explorer. It does not provide access to the current test log. This is because the test log contents are formed during the test execution and the log is only added to the list of project logs after the test run is finished.





http://support.smartbear.com/viewarticle/55140/?_ga=1.145209844.1554134704.1392816096
Highlighted
Valued Contributor

RE: Help needed with scripting interface to current test log during test run

Add this to your script in the OnStop event handler and I assure you it will actually create log files during test run :).



Log.SaveResultsAs('c:\\testlog',1);



You can then attach the index.html file to your email and send that along.

Like I said it has some issues with the formatting that I don't like but the option does exist.

''-Praise the sun and Give Kudos.''
Highlighted
Regular Contributor

RE: Help needed with scripting interface to current test log during test run

Hey Ryan,



The issue wasn't  saving the test log file during the test run or emailing it. I probably wasn't clear enough in my earlier posts 🙂



The issue was extracting data from the test log of the current test run. Data such as number of error messages, warning messages etc. This cannot be achieved using the scripting interface as I found first hand and is also documented by SmartBear in their documentation (see my posts above).



I found another way to do this by counting  the occurrence of events I am interested in and storing the values in ProjectSuite.Variables. I then have some logic in my OnStopTest script that selects an email subject line dependant on whether the test run passed or failed and also generates a message body containing some high level metrics, ie. total number of tests, tests passing, tests failing, warning messages.

When you are recieveing multiple emails a day from the testing machine its handy to skim the subject line and see if there are failed tests or not. I think its also a non brainer that a user shouldnt have to open up every email they receive and look at the log file to find out if a test run was succesful or not.



Is seems to me that the 'out of box' solution that SmartBear had in mind was to send a generic email that does not indicate the test run status with the log file attached. The recipient should then open each email and examine the test log in IE. For a small team and small number of recipients and or a low number of daily runs that would be fine but it doesnt seem like a good solution to me for larger teams. 



As I said before, I dont understand why the scripting interface cant access the logs data for the current test, it exists, it just isnt compiled into a 'pretty' format. I suspect other users may also have wanted to do seomthing similar and just scripted their own solution rather than request a feature from SmartBear.
Highlighted
Valued Contributor

RE: Help needed with scripting interface to current test log during test run

Chris,

Those properties are actually available for read ("Data such as number of error messages, warning messages etc.") as well. I apologize for not fully understanding the second part of what you were trying to accomplish. Here are some of the log properties you should look for:




Log.MsgCount();


Log.WrnCount();


Log.ErrCount();



This is how my email summary looks:



Scripts run:

[09:58 AM] - [10:06 AM] Infinity_4_VOCTracking.xls

[10:06 AM] - [11:22 AM] Infinity_5_SpecialColors.xls

[11:22 AM] - [11:45 AM] Infinity_7_OrderNet.xls

Total Errors: 34

Total Warnings: 0

Click to view test results.


''-Praise the sun and Give Kudos.''
Highlighted
Regular Contributor

RE: Help needed with scripting interface to current test log during test run

Perfect. I can call those methods rather than count the events in the script. Thanks Ryan.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors