Sign in to follow this  
Followers 0
bi0hazrd

Automating An Api Using Javascript

7 posts in this topic

I'm fairly new to AutoIt and my experience has strictly been with automating an application. However, our application also exposes an API that is accessible through, among others, Javascript/VBScript.

I have a test suite already written in Javascript and embedded inside HTML files and I'm looking at leveraging AutoIt's power to make the tests more robust and to better be able to programmatically verify the results of the test (currently I have to manually parse a textarea for the results).

My questions are:

  • Can this be done in an efficient manner through AutoIt or is it easier to use AutoItX inside my HTML files?
  • Is there a way from AutoIT that I can call a Javascript function and pass parameters to it?
  • Can I access information returned by an event generated by the ActiveX control and encapsulated inside a Javascript function?
For example:

function TriggerEvent(Params)
{
    // Call this function from AutoIt, which will trigger an event
    Object.Class.MethodToTriggerEvent()
}

function Object::EventHandler(EventParams)
{
    // Pass EventParams to AutoIt for result verification
}

I am hoping to be able to set up my test suite to run each test area automatically instead of having to manually open each HTML file.

Share this post


Link to post
Share on other sites



Anyone?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well after some more investigation, I'm not what I want is even possible using AutoIt. Unless I were to pop up message boxes all the time or write my results to a textarea, there doesn't appear to be any way to pass information from my ActiveX control to AutoIt, with or without using Javascript, e.g. if my control generates an event, I can capture it using Javascript, and access any information encapsulated in that event through Javascript. But I have no way of passing that off to AutoIt to compared against a set of expected results. I've also been unable to find any method for interfacing AutoIt and the control directly (not that I really expected I could do this in the first place) :)

Edited by bi0hazrd

Share this post


Link to post
Share on other sites

Well after some more investigation, I'm not what I want is even possible using AutoIt. Unless I were to pop up message boxes all the time or write my results to a textarea, there doesn't appear to be any way to pass information from my ActiveX control to AutoIt, with or without using Javascript, e.g. if my control generates an event, I can capture it using Javascript, and access any information encapsulated in that event through Javascript. But I have no way of passing that off to AutoIt to compared against a set of expected results. I've also been unable to find any method for interfacing AutoIt and the control directly (not that I really expected I could do this in the first place) :)

ObjEvent can be used trap events (more precisly, can be asynchronously be notified). Also, I wrote a routine for injecting Javascript event routines and posted it to the forum -- it is intended to be used with IE.au3

In terms of getting data passed from the page... the best Idea I have is using a <DIV> tag and writing data to it from your event routine and then reading that data with AutoIt -- I hane not yet written this code.

I'm not quite certain I follow, but ten are some ideas.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

ObjEvent can be used trap events (more precisly, can be asynchronously be notified). Also, I wrote a routine for injecting Javascript event routines and posted it to the forum -- it is intended to be used with IE.au3

In terms of getting data passed from the page... the best Idea I have is using a <DIV> tag and writing data to it from your event routine and then reading that data with AutoIt -- I hane not yet written this code.

I'm not quite certain I follow, but ten are some ideas.

Dale

I'll try to clarify this some more. I have an ActiveX control that exposes an API for our application. The control is embedded in an HTML page and the API is accessed using Javascript. When certain API properties are set or certain API methods invoked, events are fired in the ActiveX control, which can be caught by Javascript using the following:

function ActiveXObjectName::APIEventHandler(event_params)
{
  // Do something here, such as output the values of the event_params
}

What I would like to do is have AutoIt call a Javascript function (possibly passing parameters) that does something, e.g. triggers an event or changes the value of some property, and then return the results (either through accessing the property value directly or using the event_params for an event that was triggered) to AutoIt for further processing.

Also, I have several HTML files that cover various logical areas and would prefer to have them all run automatically, instead of having to open each HTML file individually to run the tests.

My original questions were:

  • Can this be done in an efficient manner through AutoIt or is it easier to use AutoItX inside my HTML files?
  • Is there a way from AutoIt(X) that I can call a Javascript function and pass parameters to it?
  • Can I access information returned by an event generated by the ActiveX control and encapsulated inside a Javascript function using AutoIt?

Share this post


Link to post
Share on other sites

I'll try to clarify this some more. I have an ActiveX control that exposes an API for our application. The control is embedded in an HTML page and the API is accessed using Javascript. When certain API properties are set or certain API methods invoked, events are fired in the ActiveX control, which can be caught by Javascript using the following:

function ActiveXObjectName::APIEventHandler(event_params)
{
  // Do something here, such as output the values of the event_params
}

What I would like to do is have AutoIt call a Javascript function (possibly passing parameters) that does something, e.g. triggers an event or changes the value of some property, and then return the results (either through accessing the property value directly or using the event_params for an event that was triggered) to AutoIt for further processing.

Also, I have several HTML files that cover various logical areas and would prefer to have them all run automatically, instead of having to open each HTML file individually to run the tests.

My original questions were:

  • Can this be done in an efficient manner through AutoIt or is it easier to use AutoItX inside my HTML files?
  • Is there a way from AutoIt(X) that I can call a Javascript function and pass parameters to it?
  • Can I access information returned by an event generated by the ActiveX control and encapsulated inside a Javascript function using AutoIt?
It isn't clear whether you've looked at the ObjEvent documentation in the helpfile yet -- it is discussed both in the function description section for ObjEvent and in the general COM/Obj section. Please do this.

The DOM window object has an execScript method that allows you to execute arbitrary code, including function execution with parameters. This can be invoked from AutoIt.

There is also a fireEvent method that allows you to raise an event that could result in a function being invoked. This can be invoked from AutoIt.

There is no easy way I know of to directly pass data from client-side script back to AutoIt -- this is why I suggest the <DIV> trick.

It is not clear to me how you would "use AutoItX inside my HTML files" -- perhaps you can expound on this.

BTW, I don't profess to be an expert in this area... I'm just good at digging through the documentation in MSDN and I've played with it all a bit.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

It isn't clear whether you've looked at the ObjEvent documentation in the helpfile yet -- it is discussed both in the function description section for ObjEvent and in the general COM/Obj section. Please do this.

The DOM window object has an execScript method that allows you to execute arbitrary code, including function execution with parameters. This can be invoked from AutoIt.

There is also a fireEvent method that allows you to raise an event that could result in a function being invoked. This can be invoked from AutoIt.

There is no easy way I know of to directly pass data from client-side script back to AutoIt -- this is why I suggest the <DIV> trick.

It is not clear to me how you would "use AutoItX inside my HTML files" -- perhaps you can expound on this.

BTW, I don't profess to be an expert in this area... I'm just good at digging through the documentation in MSDN and I've played with it all a bit.

Dale

Thanks Dale. I believe you have answered my questions. As to what I meant about using AutoItX inside my HTML files, I was under the impression from reading the help that I can use the AutoItX ActiveX control inside a scripting language like VBScript or JS. However, based on what you've said, it looks like I'll be able to use AutoIt and be able to do everything I need to.

Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0