SarahEdwards
8 years agoContributor
Calling a script from an Event Handler
So, I just learned about Event Handlers. What amazing things!
However, I'd like to send an email from the OnLogError event.
My handler script is as follows:
function GeneralEvents_OnLogError(Sender, LogParams) { Log.Picture(Sys.Desktop.Picture(), "Image of the whole screen", "", pmHigher); PackResults(); //This is the name of my email function. }
When my tests hit an error, I get a javascript error:
ReferenceError PackResults is not defined Error location: Unit: "SmokeTest\SmokeTest\Script\SmokeTestScript" Line: 4 Column: 3.
I'd imagine this is just a syntax and/or scope issue. How do I call my email function, PackResults()?
PackResults I'm assuming is in a different script unit than your event handler. So... this is a two-step thingie
1) Add at the top of the unit for the event handler the following//USEUNIT MyScriptUnit
where "MyScriptUnit" is the code unit containing PackResults
2) Change your code to:
function GeneralEvents_OnLogError(Sender, LogParams) { Log.Picture(Sys.Desktop.Picture(), "Image of the whole screen", "", pmHigher); MyScriptUnit.PackResults(); //This is the name of my email function. }