/    Sign up×
Community /Pin to ProfileBookmark

How to rederect method calls from top to iframe?

Hey, guys!

I’m trying to build an app that does the following:

Executes events (such as onclick, onchange, etc) on another web application (that’s on the same server). Basically similating a live person using it. The purpose of doing this is automating testing [B]without[/B] changing anything in the app that’s being tested. The test app (app A), has the app that’s being tested (app ? loaded in an iframe.

I have no problem executing the events, writing to text boxes, etc. The problem is caused by the app that’s being tested:

App B has multiple frames inside it. The documents in those frames call methods on “top”. However, when it’s inside of the app A’s iframe, “top” points to app A, because we’ve added an extra level of frames. So naturally, because the method app B is calling does not exist in the new “top”(app ?, there’s a javascript error like “object does not support property or method” (running it in IE 7).

My original thought was to get alll of the methods programmatically from the inner frame’s window object, create methods w/ the same name in the app A javascript that call those method back in frame.contentWindow. I tried to iterate over contents of (frame.contentWindow), via “for(var blah in window)”, but that never returns the function objects. Did research on google and it seems there is no way to get declared methods programmatically in javascript (similar to java’s object.getClass().getDeclaredMetods()? (if I’m wrong in this, please let me know).

I even made the following desperate attempt:

[code]frame.contentWindow.top = frame.contentWindow;[/code]

Didn’t work ?

Is there any way at all to catch any method call? Like this:

[code]

if something is attempting to call a method
{
if method of that name exists in the current window
{
execute window.methodName
}
else if method of that name exists in the frame.contentWindow
{
execute frame.contentWindow.methodName
}
else
throw exception
}

[/code]

either something like that, or somehow getting all the method names of the document that’s inside the fame. Or changing the reference of frame’s “top” to point to the frame?

Any help would be appreciated. Thanks!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyJan 16.2009 — The problem is caused by the app that's being tested:

App B has multiple frames inside it. The documents in those frames call methods on "top".[/QUOTE]

Then change app B to call those methods by "parent" (not [B]parentNode[/B]) instead of "top." [B]parent[/B] is a valid owning window or frame object reference -- just like [B]top[/B] -- while [B]parentNode[/B] is only an owning HTML element reference.
Copy linkTweet thisAlerts:
@CreatureauthorJan 16.2009 — The whole point of app A is to not have to do that. To not have to change the app that is being tested. The idea is to be able to load ANY app into app A and do the test.

I've been trying to do something similar by doing something like this:

<i>
</i> var scripts = targetDoc.getElementsByTagName("script");
var blah = scripts[0].text;
var newScript = blah.replace("top.", "parent.");

<i> </i>scripts[0].text = newScript;


Kinda dangerous if there is a variable that ends in "top". I have NOT been able to make it work right if app A has onload events that call [b]top[/b]. 'Cause I can't execute scripts that access the iframe's contents before the contents are loaded. But right after its loaded, before I get a chance to do the above the onload gets executed and causes js errors.

Is there any way to go around this?
Copy linkTweet thisAlerts:
@MrNobodyJan 16.2009 — No. Unless you want to load the content of app B via AJAX, make your changes, then load it into your iframe via [B]document.write()[/B].
Copy linkTweet thisAlerts:
@CreatureauthorJan 19.2009 — Ok. Thank you very much!
×

Success!

Help @Creature spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...