SmeeK153 / flash-selenium

Automatically exported from code.google.com/p/flash-selenium
0 stars 0 forks source link

Flash selenium does not work with Firefox 3.5 #27

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When trying to access methods which are externalized using Flash
ExternalInterface and using Firefox 3.5, following error message is thrown.
Calling methods in flash movies using Firefox 3.0 just works perfect !

-============================================-
Failure:
Selenium.SeleniumException : ERROR: Threw an exception: NPMethod called on
non-NPObject wrapped JSObject!
at Selenium.HttpCommandProcessor.DoCommand(String command, String[] args)
at Selenium.HttpCommandProcessor.GetString(String commandName, String[] args)
at Selenium.DefaultSelenium.GetEval(String script)
at TestFlash.FlashTest.Call(String functionName, String[] parameters)
at TestFlash.FlashTest.PercentLoaded()
-============================================-

Original issue reported on code.google.com by ybh...@gmail.com on 11 Sep 2009 at 10:28

GoogleCodeExporter commented 8 years ago
I used the flash selenium code in a test java program and I noticed that using 
the 
method flashApp.call() after a small pause(Thread.sleep()), does not generate 
any 
errors. It executes successfully in Firefox 3.0.13 and below. 

        browser = new DefaultSelenium("localhost", 4442, "*firefox",URL);
        browser.start(); 
        flashApp = new FlashSelenium(browser, ...); 
        browser.open(URL);
                Thread.sleep(1000);
                String rslt = flashApp.call(..);

However, for higher versions of Firefox, it generates the following error:

com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: 
NPMethod 
called on non-NPObject wrapped JSObject!
    at 
com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrE
rror
(Unknown Source)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(Unknown Source)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(Unknown Source)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(Unknown Source)

Is this a limitation of Flash selenium API? Has this issue been resolved?

Original comment by error.is...@gmail.com on 15 Sep 2009 at 9:26

GoogleCodeExporter commented 8 years ago
I read that the correct way of invoking Firefox 3.5 is using "chrome", instead 
of "firefox", so the called should be: 

browser = new DefaultSelenium("localhost", 4442, "*chrome",URL);

I hope it helps.

Cheers

Original comment by iagomo...@gmail.com on 2 Oct 2009 at 3:06

GoogleCodeExporter commented 8 years ago
using *chrome itself only....but still does not work

Original comment by ybh...@gmail.com on 3 Oct 2009 at 8:31

GoogleCodeExporter commented 8 years ago
http://stackoverflow.com/questions/1484861/calling-a-flex-as3-callback-from-java
script -
I suppose that it can be a solution. But I can't fully implement it in 
SeleniumFlex.

Original comment by Khro...@gmail.com on 22 Oct 2009 at 9:14

GoogleCodeExporter commented 8 years ago
Any workaround for this very much appreciated.

This is definitely a security issue.

Original comment by murali.o...@gmail.com on 13 Nov 2009 at 6:55

GoogleCodeExporter commented 8 years ago
I've added possible workaround here:
http://code.google.com/p/sfapi/issues/detail?id=1 It is not always stable but 
works.

Original comment by Khro...@gmail.com on 13 Nov 2009 at 7:06

GoogleCodeExporter commented 8 years ago
Thanks a ton. Dumb question. Hope user-extensions_modified.js must be moved 
under
selenium-server.jar?

Thanks,
Murali

Original comment by murali.o...@gmail.com on 13 Nov 2009 at 7:59

GoogleCodeExporter commented 8 years ago
Yes. Something like this "java -jar selenium-server.jar -userExtensions
user-extensions.js"

Original comment by Khro...@gmail.com on 13 Nov 2009 at 8:05

GoogleCodeExporter commented 8 years ago
we start selenium server programatically.

I tried setting the rcConfiguration as follows and it didn't work :( 

File userExtension = new File("C:\\selenium\\user-extensions.js");
rcConfig = new RemoteControlConfiguration();
rcConfig.setUserExtensions(userExtension);

SetupSelenium.seleniumServer = new SeleniumServer(slowResources, rcConfig);
SetupSelenium.seleniumServer.start();

Am I missing something? Let me try starting the rc from cmd prompt and check if 
it
works. Your help is greatly appreciated.

Original comment by murali.o...@gmail.com on 13 Nov 2009 at 8:25

GoogleCodeExporter commented 8 years ago
Tried using cmd prompt as well. Didn't work. Same "Threw an exception: NPMethod
called on non-NPObject wrapped JSObject!"

C:\selenium> java -jar selenium-server.jar -userExtensions user-extensions.js
00:30:37.911 INFO - Java: Sun Microsystems Inc. 1.5.0_17-b04
00:30:37.911 INFO - OS: Windows XP 5.1 x86
00:30:37.911 INFO - v1.0.1 [2696], with Core v@VERSION@ [@REVISION@]
00:30:37.990 INFO - Version Jetty/5.1.x
00:30:37.990 INFO - Started HttpContext[/,/]
00:30:37.990 INFO - Started HttpContext[/selenium-server,/selenium-server]
00:30:37.990 INFO - Started 
HttpContext[/selenium-server/driver,/selenium-server/driver]
00:30:38.021 INFO - Started SocketListener on 0.0.0.0:4444
00:30:38.021 INFO - Started org.mortbay.jetty.Server@b1c260
00:30:51.740 INFO - Checking Resource aliases
00:30:51.740 INFO - Checking Resource aliases
00:30:51.755 INFO - Command request: getNewBrowserSession[*firefox,
https://10.00.00.00:8443/my-app/, ] on session null
00:30:51.755 INFO - creating new remote session
00:30:51.974 INFO - Allocated session 82c7e13830a842978a7cd3c4906d2348 for
https://10.00.00.00:8443/my-app/, launching...
00:30:52.083 INFO - Preparing Firefox profile...
00:30:54.443 INFO - Launching Firefox...
00:30:57.411 INFO - Got result: OK,82c7e13830a842978a7cd3c4906d2348 on session
82c7e13830a842978a7cd3c4906d2348
00:30:57.427 INFO - Command request: 
getEval[navigator.appName.indexOf('Microsoft'),
] on session 82c7e13830a842978a7cd3c4906d2348
00:30:57.443 INFO - Got result: OK,-1 on session 
82c7e13830a842978a7cd3c4906d2348
00:30:57.443 INFO - Command request: 
open[https://10.00.00.00:8443/my-app/login.html,
] on session 82c7e13830a842978a7cd3c4906d23
00:31:11.974 INFO - Got result: OK on session 82c7e13830a842978a7cd3c4906d2348
00:31:11.990 INFO - Command request:
getEval[window.document['login'].PercentLoaded();, ] on session
82c7e13830a842978a7cd3c4906d2348
00:31:12.005 INFO - Got result: ERROR: Threw an exception: NPMethod called on
non-NPObject wrapped JSObject! on session 82c7e13830a84297
48
00:31:12.005 INFO - Command request: close[, ] on session
82c7e13830a842978a7cd3c4906d2348
00:31:12.036 INFO - Got result: OK on session 82c7e13830a842978a7cd3c4906d2348
00:31:12.052 INFO - Command request: testComplete[, ] on session
82c7e13830a842978a7cd3c4906d2348
00:31:12.052 INFO - Killing Firefox...
00:31:12.271 INFO - Got result: OK on session 82c7e13830a842978a7cd3c4906d2348

Original comment by murali.o...@gmail.com on 13 Nov 2009 at 8:35

GoogleCodeExporter commented 8 years ago
I assume that this workaround is tuned for my project.
The main idea is not to call flex external interface from selenium javascript 
but:
1. Create control that contains calling of flex method.
2. Fire event of the control to call the method.

Original comment by Khro...@gmail.com on 13 Nov 2009 at 8:36

GoogleCodeExporter commented 8 years ago
Try this one. It should work for PercentLoaded() method too.

Original comment by Khro...@gmail.com on 13 Nov 2009 at 8:41

Attachments:

GoogleCodeExporter commented 8 years ago
This seems like little time taking. Will try it out in the morning..Thanks

Original comment by murali.o...@gmail.com on 13 Nov 2009 at 8:50

GoogleCodeExporter commented 8 years ago
Hi,

I think am missing the part to call doFlexSetFlexObjID from my project to set 
the
flashobj id. Could you pls let me know how to call the js function from java 
code to
set the application id (under test).

What we do is this:

1) start selenium with rc config
2) open browser -> pass the App URL
3) instantiate flashSelenium object using application id (eg: flashSelenium = 
new
FlashSelenium(selenium, loginAppId);
4) flashSelenium.call("doFlexClick", "id")

Wondering if I need to pass the app id to this user extension.js to reach the 
app
under test and then call the selenium flex api methods (ExternalInterface ->
doFlexClick etc)

Original comment by murali.o...@gmail.com on 14 Nov 2009 at 1:07

GoogleCodeExporter commented 8 years ago
Hi,

I'm debugging user-extensions.js via selenium.getEval("") command. I'm using
http://code.google.com/p/sfapi/ but common logic should be the same.
1. To set id:
selenium.getEval("selenium.doFlexSetFlexObjID('my_super_id')")
2. To call command:
selenium.getEval("selenium.callFlexMethod('doFlexClick', 'myButton', '')") or
selenium.getEval("selenium.doFlexClick('myButton', '')")
3. To validate if 'selenium_bridge' button is ok:
selenium.getEval("selenium.browserbot.getCurrentWindow().document.getElementById
('selenium_bridge')")
//shouldn't be null
 or
selenium.getEval("selenium.browserbot.getCurrentWindow().document.getElementById
('selenium_bridge').getAttribute('onClick')")
// should be a command to call from your flash object with correct id
4. See if flash object has external interface:
selenium.getEval("selenium.browserbot.findElement(this.flashObjectLocator)['doFl
exClick']")
//shouldn't be null

Original comment by Khro...@gmail.com on 14 Nov 2009 at 6:43

GoogleCodeExporter commented 8 years ago
The NPObject crap is killin me! I'll 
keep this space updated while I try and fix the NPObject issue. Any help is 
welcome. 

Lotts ppl seem to be facing it. Sorry dudes!

Original comment by sachin.s...@gmail.com on 14 Nov 2009 at 10:32

GoogleCodeExporter commented 8 years ago
I stumbled across a workaround using *firefoxproxy. I have posted a blog about 
this
here: 
http://samadesoga.blogspot.com/2009/11/workaround-flash-selenium-test-would.html

Original comment by samuelad...@gmail.com on 23 Nov 2009 at 12:22

GoogleCodeExporter commented 8 years ago
A workaround has been posted by samueladesoga. Thanks dude!

Original comment by sachin.s...@gmail.com on 23 Nov 2009 at 2:27

GoogleCodeExporter commented 8 years ago
Seems that this workaround is not always working ... :(

I started playing with selenium yesterday and immediately bumped into the 
following
issue:

http://jira.openqa.org/browse/SRC-743

So I started using RC2.0a1 which solved this.
But then I got this NPObject problem, so I tried using *firefoxproxy.
This caused the SQLite problem again!

Any suggestion?  

Original comment by christia...@gmail.com on 17 Dec 2009 at 10:47

GoogleCodeExporter commented 8 years ago
Just to add to the confusion:

I'm using Windows XP SP3, FF 3.5.5. Comment 15  by Khroliz helped me debug 
somewhat
however I could only use "array" syntax to navigate the DOM e.g.

selenium.getEval("this.browserbot.getCurrentWindow()['document']['my_flash_objec
t_id']");

*firefoxproxy doesn't work for me either - just launches an empty browser 
window and
hangs.

Misery...

Original comment by niceman...@gmail.com on 8 Jan 2010 at 10:49

GoogleCodeExporter commented 8 years ago
nicemandan, can you try user-extensions file attached? It works for me with 
*chrome 
option.

Original comment by Khro...@gmail.com on 13 Jan 2010 at 8:12

Attachments:

GoogleCodeExporter commented 8 years ago
I too have failed to get flex-ui testing working. I can get compiled flash apps 
to
work (testing percentloaded/zoom), but my problem lies with flex-ui throwing the
NPMethod error  or the this.browserbot.findelement .doFlexType/.doFlexClick is 
not a
function error (depending on my setup).

I've searched endlessly for a solution to this problem with no success, so 
rather
than attempting to try different browser versions and operating systems - could
somebody who has got flex-ui-selenium WORKING please post their specifications
(OS/browser version, etc) and I'll attempt to recreate that environment.

Regards in advance. :-)

Original comment by phillip...@gmail.com on 19 Jan 2010 at 12:24

GoogleCodeExporter commented 8 years ago
@philliphix

Is the swc included when you compile your flash application? From what I see, 
doFlexType/doFlexClick are the swc's (selenium-flex-api) methods and 
PercentLoaded/Zoom are standard flash methods. The standard flash methods work 
irrespective of what flash application is loaded. But for doFlexType() to work, 
you 
need to compile your swf with the swc which has definitions for doFlexType(). 

Even we have faced problems getting the swc to be included during compilation 
when 
we were spiking it out. Worst case, provide the absolute path of the swc as the 
argument when you compile.

Original comment by sachin.s...@gmail.com on 19 Jan 2010 at 5:26

GoogleCodeExporter commented 8 years ago
Thanks for your speedy reply suchin.

I have just this second got it working!!! :-) I think the cause may have been 
because 
I was testing on a local environment. A bit of fiddling (uploading files, 
*firefoxproxy which was hanging yesterday, but for some lucky reason it's not 
today! 
and thread.sleep) and it's working. 

Current Firefox version: 3.0.17
OS: MS XP (SP 3)
API: user-extensions_20100113.js 
Script key elements: firefoxproxy, thread.sleep, http testing.

Kind regards. :-)

Original comment by phillip...@gmail.com on 19 Jan 2010 at 9:26

GoogleCodeExporter commented 8 years ago
Philliphix, could you try *chrome/*firefox mode with 
user-extensions_20100113.js + 
FF3.5?

It works on my environment but I want to be sure that it is expandable to other 
cases. 
Thanks.

Original comment by Khro...@gmail.com on 19 Jan 2010 at 9:52

GoogleCodeExporter commented 8 years ago
I'm having the same NPMethod issue with PercentLoaded().  The Java code I'm 
working
with starts the selenium server and client on a test head 
(RemoteControlConfiguration
class); the target machine is remote, possibly on a different network and/or 
domain.

I'm tinkering with remoteControlConfiguration.setuserExtensions() as well as
selenium.setExtensionJs().  Not sure if I'm using them correctly, but they're 
not
complaining.  I'd appreciate hints on proper use; the API documentation I have 
isn't
all that helpful.

I can't get https GUI authorizations to work with *firefoxproxy.  The code's
certificate importing seems to work, but ... doesn't.  *chrome is OK in this 
regard.

What I'm gathering from this thread is that FF3.0.12 and beyond are "more 
secure" and
resistant to what might be considered flash-selenium attempts to hack the 
browser. 
Comment 11 seems particularly relevant.

There's quite a bit of information on 
http://www.mozilla.com/en-US/firefox/releases/
around FF 3.0.10/11/12.  I haven't figured out which security statement might 
relate
to this NPMethod problem, or if knowing would be helpful.

sachin.sudheendra, any recent feedback on user-extensions_20100113.js?

Cheers.

Original comment by stevecbo...@gmail.com on 26 Jan 2010 at 1:06

GoogleCodeExporter commented 8 years ago
Hi Sachin,

I have tried using *chrome, *firefoxproxy and *firefox with no success. But 
everythng works fine whenI use *iexplore.

When I use *firefoxproxy, just opens and empty window and hangs there. Please 
help!

OS: MS XP
Firefox version: 3.0.13/3.0.17/3.5

Original comment by gowri.ku...@gmail.com on 27 Jan 2010 at 2:44

GoogleCodeExporter commented 8 years ago
Even I'm seeing this issue , any concrete solution for this?

Thanks,
Vikram

Original comment by vikram.s...@gmail.com on 27 Jan 2010 at 11:24

GoogleCodeExporter commented 8 years ago
Hi Sachin,

I'm still able to reproduce this issue.

In my case swf file is embedded within iframews ,is this could be the reason?

Thanks,
Vikram

Original comment by vikram.s...@gmail.com on 28 Jan 2010 at 10:03

GoogleCodeExporter commented 8 years ago
Anyone found solution for this issue ? please share.

Original comment by vikram.s...@gmail.com on 8 Feb 2010 at 12:18

GoogleCodeExporter commented 8 years ago
Please see Comment 21 by Khroliz, Jan 13, 2010

It works fine for me.

Original comment by Khro...@gmail.com on 9 Feb 2010 at 8:09

GoogleCodeExporter commented 8 years ago
Khroliz is correct that his posting contains the key to the solution. However, 
using
the steps s/he outlined, I was not able to get it to work.

Here is what I did to get it to work for my case:

The problem seems to be (I have not verified this by looking at the Firefox 
source
code) that FF does not like JavaScript calling Flash when the JavaScript comes 
from
another Window.

What FlashSelenium is doing in the background is simply a getEval with some
JavaScript to use the ActionScript-JavaScript bridge to access the Flash object.

FF barfs with a security exception.

In my case, I simply want to call a function inside the Flash that returns a 
string.

I am passing no parameters in...so its a pretty simple case but the solution 
here
should work for more complicated cases too.

A test page with the Flash object on it can be found here:

http://files.deque.com/mars/flash/testdisplayAS3-acnojs.html

The function I am calling is called "callASElements" and it returns the results 
of
validating that all of the UI elements in the Flash object conform to 
Accessibility
standards.

The JavaScript to call that function when executed from within the same Window
context is:

window.document.dqMovieId.callASElements();

You can verify this, by going to that address and typing

    javascript:window.document.dqMovieId.callASElements();

in the FF address bar and you will see the output of the function displayed in 
the
browser.

So the trick is to make FF think that the bot browser is actually executing the
JavaScript. The problem is that the solution to this seems to be different on
different platforms. On Mac, you simply have to insert some JavaScript into the
document eg:

<script>

function callFlash( id, func) {
    return window.document[id][func]() ;
}

</script>

and then call

//groovy
selenium.getEval( "window.callFlash( 'dqMovieId', 'callASElements');") 

Voila, it works...

On Windows, you will be unhappy with this solution. The robust solution which I
cribbed from Khroliz is to create a form in the document and send a mouse click 
event
to the form's submit button which then executes the JavaScript.

The new JavaScript function is:

<script>
function callFlash( id, func) {
    if ( typeof( window.document[id][func]) != 'undefined') {
        return window.document[id][func]() ;
    }
    var bridge = selenium.browserbot.getCurrentWindow().document.createElement( 'input');
    bridge.setAttribute( 'id', 'ws-sel-bridge') ;
    bridge.setAttribute( 'value', 'test') ;
    selenium.browserbot.getCurrentWindow().document.body.appendChild( bridge) ;
    bridge.setAttribute( 'onClick',
'window.document.getElementById("ws-sel-bridge").value =
window.document.getElementsByName( "' + id + '")[0]["' + func + '"]();') ;
    var e = selenium.browserbot.getCurrentWindow().document.createEvent( 'HTMLEvents') ;
    e.initEvent( 'click', false, false) ;
    bridge.dispatchEvent( e) ;
    return bridge.value ;
}
</script>

Now, when you do the same call

//groovy
selenium.getEval( "window.callFlash( 'dqMovieId', 'callASElements');") 

It works no matter what...well, one caveat...you need to make sure that you 
wait for
the page to load and you might need to catch an exception and retry...here is 
some
Groovy code for doing it assuming Selenium is running on localhost:4442

import com.thoughtworks.selenium.DefaultSelenium

def selenium, ourUrl ,ourDomain

ourDomain = "http://files.deque.com"
selenium = new DefaultSelenium( "localhost", 4442, "*firefox", ourDomain)
selenium.start()
ourUrl = "http://files.deque.com/mars/flash/testdisplayAS2-acnojs.html"
selenium.open( ourUrl)
selenium.waitForPageToLoad( "60000")
retry = true
maxRetries = 10
def retVal
while( retry) {
    try {
        retVal = selenium.getEval( "window.callFlash('dqMovieId', 'callASElements');")
        retry = false
    } catch( e) {
        println "got exception, trying again"
        Thread.sleep( 1000)
        if ( maxRetries-- <= 0) retry = false ;
    }
}
println retVal
println "MaxRetries $maxRetries"
selenium.stop()

Now this solution might not be acceptable to you because it creates a form in 
the
document. You could of course modify the function to remove the form after it 
has
been called.

If you have full ocntrol over the pages you are testing and can insert this
JavaScript then you are ok. If, like us, you have to test pages without being 
able to
change their code (our product does Accessibility testing for WCAG 2 and 
Section 508
compliance on production systems as well as development systems), then you 
still need
to be able to get the JavaScript into the document.

selenium.getEval will not help with this problem. What we did is to create a 
Firefox
plugin that gets loaded as part of the selenium profile using the
-firefoxProfileTemplate command line option. This listens to the HTTP events in 
the
browser and at the appropriate time, inserts the function into every document 
so that
it is there for getEval to call. This is a trick that we use for other purposes 
too,
so the code is too big to post as a solution to this problem.

But most of you will be able to modify or inject JavaScript in your test 
environments
so this should not be a big issue for you.

Original comment by barrelld...@gmail.com on 10 Feb 2010 at 3:42

GoogleCodeExporter commented 8 years ago
Issue 38 was added because issues 27, 31 were closed.  Please use issue 38 for
further discussion.

Original comment by stevecbo...@gmail.com on 10 Feb 2010 at 4:30

GoogleCodeExporter commented 8 years ago
Hi All,

Where do i place the user extension.js? i placed the js file in the same folder 
where selenium-server.jar resides and then i tried this command 

java -jar selenium-server.jar -userExtensions user-extensions_20100113.js

i got the error message as follows

User extensions file MUST be called "user-extensions.js": 
/users/ansar/Downloads/selenium-remote-control-1.0.3/selenium-server-1.0.3/user-
extensions_20100113.js

i have no idea how to proceed.

Please help me . 

Original comment by websh...@gmail.com on 21 Mar 2011 at 12:23

GoogleCodeExporter commented 8 years ago
Hi Websh,

Simply rename the file user-extensions_20100113.js to user-extensions.js and 
then try to run the server, it should work.

Thanks,
Saurabh

Original comment by jainsaur...@gmail.com on 29 Dec 2011 at 6:36

GoogleCodeExporter commented 8 years ago
Hi dylan.ba...@gtempaccount.com

http://files.deque.com/mars/flash/testdisplayAS3-acnojs.html

Not Found

The requested URL /mars/flash/testdisplayAS3-acnojs.html was not found on this 
server.

Original comment by esob.321...@gmail.com on 4 Jun 2012 at 7:43