Capturing addEventListener details
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let's see if the Community has suggestions!
Any ideas @ApplePen @anupamchampati @tphillips ?
Sonya Mihaljova
Community and Education Specialist
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your response. Could you expand on this a little for me? Maybe an example?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm, that's giving me a "type mismatch" at position 10 which is the start of .addEventListener
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
Any ideas? @tphillips @sonya_m
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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).
/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
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
