Trying to send email on failure using VB.Net

Ask general questions here.
fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

Trying to send email on failure using VB.Net

Post by fester13579 » Wed May 21, 2014 11:11 pm

Hello,

Noob here with 5.x, I am looking for a vb.net solution to notify me when a test has failed.

I have done some searching on the forum and found this link however it is written in C, and when I tried to convert it I ran into all sorts of problems that my noob-fu is not strong enough to fix. :cry:

http://www.ranorex.com/blog/wp-content/ ... ogging.zip


Could someone please post or point me to a working solution written in VB that I could learn from?


Also, I am assuming that some sort of 'event handler' is used so that no matter where a failure occurs the send Mail module would fire. That is to say without having to check in multiple places in the code if any error is raised, call the send mail function.

Thank you

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Trying to send email on failure using VB.Net

Post by Support Team » Fri May 23, 2014 2:03 pm

Hello fester13579,

Please find attached a VisualBasic “report to mail”- solution . It is pretty comprehensive so I guess all your requirements are met within this solution.

Regards,
Robert
Attachments
SendReportAndStatusPerMail.zip
(49.6 KiB) Downloaded 152 times
.
Image

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Trying to send email on failure using VB.Net

Post by krstcs » Fri May 23, 2014 2:51 pm

I would recommend using a continuous integration solution like Jenkins (free) or Bamboo ($$) to do this.

I use Jenkins and have it set to send emails on build failures (there are plugins for this as well as some of the other things I do with it). Basically, Ranorex will throw an exit code of 1 if there was a failure in the test, and Jenkins will pick up any exit code that is NOT 0 as a failure of the build, so it will mark the build failed and send an email to the selected recipients.

There are other valuable things you get with Jenkins as well, such as scheduling, environment control (I use virtual machines and Jenkins will make sure they are setup correctly for the tests), etc.

I have several different test regression suites that each have their own job that I then bundle (plugin) in a REGRESSION job. The REGRESSION job will run each test job in succession until they are all done. It will also re-run the whole thing if any of the jobs fail (another plugin). I have the REGRESSION job set to run at 8pm local time every night.

Bamboo does most of these things out of the box, so you don't need the plugins, but it does cost money for each worker (so for my tests, I would have to pay over $8000 for the whole thing because I have a lot of workers) so it can be expensive.
Shortcuts usually aren't...

fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

Re: Trying to send email on failure using VB.Net

Post by fester13579 » Fri May 23, 2014 7:39 pm

Thank you for the replies,

This pre-converted C to VB file SendReportAndStatusPerMail.zip has some issues for me that do not work as expected.

I can get it to mail me the result but every time it sends the email all I get is PASSED regardless of the actual status and no details in the body of the email other than the header:
Ranorex Test Report
Summary: PASSED
Time Level Category Message

To use this test I disabled all the steps in recording1 other than step6 (close calc) and then kicked off the test with calc not running to simulate a failure.

It seems that the value of 'success' never gets changed which I think is part of the problem but im not sure what to do to fix it. Checksuccess() never gets called, nor do a lot of the other subs/functions but that may be ok.

Also, This project makes references to older versions of ranorex (2.x & 3.x) , could it be that this code does not work with 5.x or something is lost in the C to VB conversion?


Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Trying to send email on failure using VB.Net

Post by Support Team » Mon May 26, 2014 2:08 pm

Hi fester,

The visual basic project was tested using Ranorex 5 so there shouldn’t be any issues related to the transformation. Did you modify following part of the program.vb file?
'select a specific report level for the email body
MailLogger.ReportLevelMail = ReportLevel.Success
Regards,
Robert
.
Image

fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

Re: Trying to send email on failure using VB.Net

Post by fester13579 » Tue May 27, 2014 5:21 pm

I deleted and re-extracted the zip and I am changing only the following 4 lines in the project:

Code: Select all

Program.vb

MailLogger.Host = "smtp.myhost.com"
mailLogger__1 = New MailLogger("[email protected]", "[email protected]", "Message")
MailLogger.ReportLevelMail = ReportLevel[b].failure[/b]
			
Maillogger.vb:
smtpClient.EnableSsl = false 

When I do this I still get PASSED as my state in the email even though the test failed.

Code: Select all

Jump to itemEdit in SpyView Help
Failed to find item 'SendReportAndStatusPerMailRepository.Calculator.Close'.
No element found for path '/form[@title='Calculator']/titlebar/button[@accessiblename='Close']' within 1m. Show/Hide Stacktrace

I have also upgraded to 5.03 with the same result.


Code: Select all



[2014/05/27 11:03:13.670][Debug  ][Logger]: Console logger starting.
[2014/05/27 11:03:13.779][Info   ][Test]: Test Suite 'SendReportAndStatusPerMail
' started.
[2014/05/27 11:03:13.810][Info   ][Test]: Test Case 'TestCase' started.
[2014/05/27 11:03:13.842][Info   ][Test]: Test Module 'Recording1' started.
[2014/05/27 11:03:13.888][Info   ][Mouse]: Mouse Left Click item 'Calculator.Clo
se' at 20;5.
[2014/05/27 11:04:14.260][Error  ][Module]: Failed to find item 'SendReportAndSt
atusPerMailRepository.Calculator.Close'.<br/>No element found for path '/form[@t
itle='Calculator']/titlebar/button[@accessiblename='Close']' within 1m.
[2014/05/27 11:04:14.354][Failure][Test]: Test Module 'Recording1' completed wit
h status 'Failed'.
[2014/05/27 11:04:14.370][Info   ][Test]: Test Module 'Recording2' started.
[2014/05/27 11:04:14.401][Info   ][User]: The test case failed!
[2014/05/27 11:04:14.494][Info   ][Link]: <a href='http://www.ranorex.com/'>Visi
t www.ranorex.com!</a>
[2014/05/27 11:04:14.510][Success][Test]: Test Module 'Recording2' completed wit
h status 'Success'.
[2014/05/27 11:04:14.526][Failure][Test]: Test Case 'TestCase' completed with st
atus 'Failed'.
[2014/05/27 11:04:14.541][Failure][Test]: Test Suite 'SendReportAndStatusPerMail
' completed with status 'Failed'.


If I force success=False right before this line in Maillogger.vb:

Code: Select all

mail.Body = "Summary: " & (If(success, "PASSED", "FAILED")) & vbLf & vbLf & mail.Body
then everything seems to work correctly and i get FAILED.

Thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Trying to send email on failure using VB.Net

Post by Support Team » Wed May 28, 2014 7:57 am

Hi fester,

Unfortunately we were not able to reproduce the issue. If you change the following line in your program.vb
you should just retrieve notification about failed test actions.

Code: Select all

MailLogger.ReportLevelMail = ReportLevel.Failure 
Regards,
Robert
.
Image