Forum Discussion
5 Replies
- irina_lukinaSuper Contributor
Hi Rebecca,
Unfortunately, the latest version of TestComplete (ver. 9) doesn't provide you with such functionality. However, if you could explain why you don't want to add event controls via the Event Control editor, it would be easier for our developers to make a decision about implementing this functionality.
As for now, if you need to track from a script whether the needed event is handled, I have the following workaround for you:
1. Add the needed event control via the Event Control editor manually and specify the script routine that will store its handler.
2. Add the project variable of the Object type to the [url=]Variables[/url] page of the Project editor. In my example, the name of the created variable is OnLogErrorHandler. This variable will indicate whether the OnLogError event is handled.
3. Add the following code to the script unit that must store the handler for the needed event:
function GeneralEvents_OnLogError(Sender, LogParams)
{
if (Project.Variables.OnLogErrorHandler != null)
{
var Handler = Project.Variables.OnLogErrorHandler;
Handler(Sender, LogParams);
}
}
function Main()
{
Log.Error("Error1");
Project.Variables.OnLogErrorHandler = TestHandler;
Log.Error("Error2");
}
function TestHandler(Sender, LogParams)
{
LogParams.Str = "Handled: " + LogParams.Str;
}4. Run the Main function.
5. To command TestComplete not to handle the OnLogError event, you just need to comment the Project.Variables.OnLogErrorHandler = TestHandler; line in the Main function.I hope this information helps :)
- rkargerOccasional ContributorThe reason I would have used the functionality is because the COM object we need to handle events from installs in different places depending on the system. I am building the test framework on a Windows 7 64-bit machine so it's in C:\Program Files (x86)\... but on the Windows XP server that the tests will be running nightly on it's in C:\Program Files\... The server that the tests are going to run on also does not have TestComplete, only TestExecute, so it's not just as simple as readding the control there.
- irina_lukinaSuper Contributor
Hi Rebecca,
If performing different operations depending on the operating system is your problem, then I recommend that you use the OSInfo program object:
var OSInfo = Sys.OSInfo;
// Obtain information on the running operating system
var Info = OSInfo.Name;
if (Info == "Win7")
// Perform operations for the Windows 7 operating system
else
// Perform operations for the Windows XP operating systemDoes this help?
- rkargerOccasional ContributorThat would work just fine if I could change the Event Control file from a script, but I can't. The problem is the source object for the event control is in different places on different OSes and I can't change that on the system where I don't have TestComplete, only TestExecute.
- irina_lukinaSuper Contributor
Hi Rebecca,
I'm really sorry for confusing you. Actually, I haven't created such tests, but I'd recommend that you add the handled control to the test twice: first, on the machine with Windows 7, and then on the machine with Windows XP. Then, attach to this control from your test using the approach described in my previous post.
I hope this information helps :)
Related Content
- 5 years ago
- 5 years ago