Ask a Question

Capturing addEventListener details

geneticmaterial
Contributor

Capturing addEventListener details

Hi

Can anyone point me in the right direction to capture the event's details that runs on the browser when a specific action occurs?

In one example we trigger an event on our site when we populate a textfield and then navigate away from it.
I have tried using a script and running a script routine immediately after the even should have been triggered on the site at runtime.

function Test()
{
var browser = Sys.Browser("*")
var page = browser.Page("*").contentDocument
page.addEventListener("form_field_complete", function (e) {
Log.Message('Adobe event '.concat(e.type));
Log.Message(e.detail);
});
}

The test does pass but nothing is logged out.

 

Do I need to run this script somehow via events instead of script routine?

 

Any help greatly appreciated.

Dan

10 REPLIES 10
sonya_m
Community Manager

Re: Capturing addEventListener details

Let's see if the Community has suggestions!

Any ideas @ApplePen @anupamchampati @tphillips ?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
tphillips
Frequent Contributor

Re: Capturing addEventListener details

You can't call TestComplete functions from events on web pages. It has to be a function the browser understands (e.g. an Alert), which TestComplete could then capture


--------------------
Senior SQA Automation Engineer
geneticmaterial
Contributor

Re: Capturing addEventListener details

Thanks for your response. Could you expand on this a little for me? Maybe an example?

tphillips
Frequent Contributor

Re: Capturing addEventListener details

Try changing your calls to Log.Message() to alert() calls (which the browser supports)

You can then capture the alert window using TestComplete and check the text in the alert.

function Test()
{
    var browser = Sys.Browser("*");
    var page = browser.Page("*").contentDocument;
    page.addEventListener("form_field_complete", function (e) {
        alert('Adobe event '.concat(e.type));
        alert(e.detail);
    });
}

 If you don't get any alerts, you know that your event isn't firing properly.


--------------------
Senior SQA Automation Engineer
geneticmaterial
Contributor

Re: Capturing addEventListener details

Hmm, that's giving me a "type mismatch" at position 10 which is the start of .addEventListener

tphillips
Frequent Contributor

Re: Capturing addEventListener details

You might need to play around with the page variable, you might have to remove the .contentDocument part when assigning it:

var page = browser.Page("*");

--------------------
Senior SQA Automation Engineer
geneticmaterial
Contributor

Re: Capturing addEventListener details

I have now implemented:

 

function captureEventDetails()
{
  var browser = Sys.Browser("*")
  var page = browser.Page("*")
  page.addEventListener("form_field_complete", function (e)
  {
    Log.Alert('Adobe event '.concat(e.type));
    Log.Alert(e.detail);
  });
}

 

but this now hangs while it looks for it then returns:

"Unable to find the object addEventListener("form_field_complete", null). See Details for additional information..."

 

The event listeners are running on the page and the event has been triggered.

I have tried to run this before and after triggering the event on the page (entering text and moving away from a text box).

for eg:

capturingEventDetails.png

 

Any ideas? @tphillips @sonya_m 

AlexKaras
Community Hero

Re: Capturing addEventListener details

@sonya_m :

Sonya,

 

There was fantastic https://support.smartbear.com/articles/testcomplete/embedding-scripts-into-web-pages/ article on your site that along with the https://support.smartbear.com/testcomplete/docs/app-testing/web/common-tasks/javascript.html documentation should provide solution to Dan.

Unfortunately, this article seems to be renamed or removed from the site. Could you please talk to your guys and ask them to return the article back?

 

P.S. I believe that the mentioned article can be used for another question by Dan asked here: https://community.smartbear.com/t5/TestComplete-Functional-Web/get-elements-from-DOM-not-page-source... (even despite the fact that Dan already found solution with the help of his development team).

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
sonya_m
Community Manager

Re: Capturing addEventListener details

Thank you, @AlexKaras ! Looks like this article is under the revision of the Support Team same as what we talked about here.

I would suggest, that you go to the Support directly, this way you'll get a quicker and direct response, also, feel free to talk to them about things you feel that should be mentioned in these articles - we value your opinion!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: