ZGSmarD / flash-selenium

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

Continuing issues with NPMethod #38

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

After discussion with Sachin Sudheendra about continuing issues with
Firefox (FF) 3.5 and NPMethod, this issue is being created.  It is related
to closed issues 17, 27, 31 and perhaps others.

The NPMethod error has also plagued my group. Below is what is currently
working for us.  It uses code from the closed issues.

Note that we are not javascript experts in any sense of the word.  Any
mistakes or uninformed uses of javascript in the attachments are purely our
own.  In particular, we're unaware of the (in)efficiencies of javascript
string methods.

Information on our environment:
  We use Java.
  Our product code is unavailable for direct linking with test libraries
(maybe irrelevant).
  The target node is different than the "test head" node that runs the
browser, Selenium server, Flash Selenium...
  The target node is often in a different domain than the test head.
  The "test head" OS is Windows (many flavors), or Linux (RHEL); however,
we haven't yet tried this on our Linux test heads.

What we are using, in no particular order:
  selenium-remote-control-1.0.1:
      selenium-java-client-driver.jar
      selenium-server.jar
  Selenium's RemoteControlConfiguration class; our automated tests start
the server as needed
  A modified version of user-extensions_20100113.js, which we found in
      Comment 21 of http://code.google.com/p/flash-selenium/issues/detail?id=27
  A modified (com.thoughtworks.selenium.Selenium) FlashSelenium.java file
  Before calling selenium.start(), we call
      selenium.setExtensionJs("our mods of user-extensions_20100113.js");
  FF 3.5.5   [ our initial attempts with FF 3.6 were unsuccessful ]
  A new profile for FF 3.5.5; our older profile for FF 3.0.9 did not work 
  *chrome, NOT *firefoxproxy (which does not work for us):
      e.g., new DefaultSelenium(<host>, <port>, "*chrome", <url>)

Our modifications to user-extensions_20100113.js:
  We reduced it to 3 methods, solely to simplify our work
  The removed methods seem to be convenience methods, easily re-added if
needed.
  The workhorse method, Selenium.prototype.callFlexMethod, was modified
only for FF:
      Fixing it for Internet Explorer is hopefully straightforward.
      It now looks for more arguments (uses 'arguments' instead of just
"args");
          without this change, some of our tests (which used to work) were
failing.
      Apologies for any misinterpretation of the code used for
input.setAttribute().

Our modifications to FlashSelenium.java:
  It references our modified version of user-extensions_20100113.js.
  The PercentLoaded() method returns 0 instead of throwing an exception on
"false,"
      giving containing code a bit more control.  For example:
          while (PercentLoaded() != 100 && !timedOut) {...}

What we'd like to get to, with this posting:
  Something as simple as that listed by bjdelamare in Comment 5 of
      http://code.google.com/p/flash-selenium/issues/detail?id=31.
      [ We're not ASP.NET experts either ]
  Something simpler than having to create a hidden button?
  An open-source supported fix for the NPMethod problem.

From an earlier posting: There is information on
http://www.mozilla.com/en-US/firefox/releases/ about FF releases
3.0.10/11/12.  Kudos to whoever can figure out which security statement
relates to the NPMethod problem.

Original issue reported on code.google.com by stevecbo...@gmail.com on 8 Feb 2010 at 10:41

Attachments:

GoogleCodeExporter commented 9 years ago
I don't think it is possible to get a simpler fix, the solution posted in 
comment 5
of that other posting will work on Mac (and maybe Linux) but not on Windows...

Check out my posting here:

http://code.google.com/p/flash-selenium/issues/detail?id=27#c32

Original comment by barrelld...@gmail.com on 10 Feb 2010 at 4:06

GoogleCodeExporter commented 9 years ago
I looked at the posting from Comment 1.  I was able to get it to work in my
environment, in one simple case, after making some modifications.  The statement
    typeof(window.document[flashId][func])
never behaved as I would have expected, so I commented out the associated 'if' 
block.
 I added in the argument processing per the initial posting for Issue 38 (see the
user-extensions.js file there).

I have very little javascript experience, but it appears to me that Khroliz's 
code
has some advantages:

    1. It recognizes browser differences.  Maybe dylan's code does that inherently? 
Note that I'm using Firefox 3.5, not IE.
    2. Khroliz saves the flash object ID.  dylan's needs it each invocation.  Maybe
this is not a big deal.
    3. When I see BCC in the Khroliz code, for better or worse I think "block check
character."  Maybe I need to update my acronyms.  I have no idea why the 
BCC-related
code exists, or whether dylan's code implicitly handles it.  Is the Khroliz code
handling something that dylan's code does not?

If dylan's code implicitly handles the special cases implied by the Khroliz 
code,
then it certainly seems simpler to me.

Anyway, for whoever is interested, here's what I ended up with after modifying
dylan's code (any errors are mine).  It's very similar to Kholiz's original
user-extensions_20100113.js from:
    http://code.google.com/p/flash-selenium/issues/detail?id=27#c21

function callFlash(flashId, func, id) {
//    if (typeof(window.document[flashId][func]) != 'undefined') {
//        return window.document[flashId][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);
    var attVal = 'window.document.getElementById("ws-sel-bridge").value = ' +
                 'window.document.getElementsByName(\'' + flashId + '\')[0][\'' +
func + '\']';
    if (id == '' || typeof(id) == 'undefined') {
        attVal += '();';
    }
    else {
        attVal += '(\'' + id + '\'';
        for (i=3; i<arguments.length; i++) {
            if (typeof(arguments[i]) == 'undefined') {
                break;
            }
            attVal += ',\'' + arguments[i] + '\'';
        }
        attVal += ')';
    }
    bridge.setAttribute('onClick', attVal);
    var e = selenium.browserbot.getCurrentWindow().document.createEvent('HTMLEvents') ;
    e.initEvent('click', false, false) ;
    bridge.dispatchEvent(e) ;
    return bridge.value;
};

Original comment by stevecbo...@gmail.com on 11 Feb 2010 at 10:53

GoogleCodeExporter commented 9 years ago
Please find below code which I tried today on FF 3.5.7 and still couldn't make 
it 
work

Note I tried with both version of js, one attached in this ticket and one 
attached in 
ticket 27 - comment 21.

Please let me know if I'm doing something wrong here?

thanks in advance.
-------------------

                        File userExtension = new File("user-extensions_20100113.js");
               rcConfig = new RemoteControlConfiguration();
               rcConfig.setUserExtensions(userExtension);

               serverLauncher = new SeleniumServer(false, rcConfig);

               //serverLauncher = new SeleniumServer();
               serverLauncher.start();

               ffbrowser = new 
DefaultSelenium("localhost",4444,"*chrome",URL);
               //ffbrowser.setExtensionJs("user-extension.js");
               ffbrowser.start();

               ffbrowser.open(URL);
               ffbrowser.waitForPageToLoad("30000");
               ffbrowser.windowMaximize();           

System.out.println(ffbrowser.getEval("selenium.browserbot.getCurrentWindow().fra
mes[0
].document.getElementById(\"play_iframe\").contentDocument.getElementById(\"Prel
oader
\").PercentLoaded();"));     

Original comment by vikram.s...@gmail.com on 17 Feb 2010 at 1:49

GoogleCodeExporter commented 9 years ago
Vikram,

You will run into the browser permissions problem. Please read this posting 
here:

http://code.google.com/p/flash-selenium/issues/detail?id=27#c32

--Dylan

Original comment by barrelld...@gmail.com on 17 Feb 2010 at 2:10

GoogleCodeExporter commented 9 years ago
Hi Dylan,

Thanks I went through your comment on Issue 27-32 to understand problem.
Today I downgraded FF 3.5.7 to FF 3.0 , found that issue is no more producible.

Does later version of FF changed the code to avoid XSS?
Now the fix needs to be done on FF / Selenium RC / Javascript / Flash side? any 
concrete solution for this.

My objective is to test functionalities in Flash , for which I'm planning to 
make 
flash wrapper functions as ExternalInterface and call them through javascript.

thanks,
Vikram

Original comment by vikram.s...@gmail.com on 18 Feb 2010 at 6:13

GoogleCodeExporter commented 9 years ago
Hi Vikram,

Re: Comment 3:
   rcConfig.setUserExtensions(userExtension);
might not do what you want.  I believe you want the client browser to access 
the user
extensions.

So,
    //ffbrowser.setExtensionJs("user-extension.js");
is on the right track, but do this instead:
    // Start with the user-extensions.js file from Comment 1, for now.
    // It has the 3 main methods from Khroliz's
    // user-extensions_20100113.js, but handles multiple arguments.
    // (Our code did not work without this, but yours might).
    File userExtension = new File("user-extensions.js");
    String ue = <read the contents of userExtension into a String>;
    ffbrowser.setExtensionJs(ue);

With that done, you should be able to make getEval() calls to the 3 methods.

Good luck,
Steve

Original comment by stevecbo...@gmail.com on 18 Feb 2010 at 6:18

GoogleCodeExporter commented 9 years ago
make sure to call setExtensionJS BEFORE you call start() on the selenium
instance....I have not tested this yet but it might be the reason my attempts 
to use
Khroliz's code were not working...

Original comment by barrelld...@gmail.com on 18 Feb 2010 at 10:36

GoogleCodeExporter commented 9 years ago
I've been using flash-selenium for a little while with some success. I use 
Selenium 
RC 1.0.1 and drive it through a Java app we wrote. Selenium is using IE 8 on 
Windows 
with no trouble.

I now have a requirement to run Selenium on Linux with FF 3.5. I've been 
running 
into all of the problems/solutions that are scattered in the threads here, and 
still 
cannot get the Colors app to work (although it works great on IE/Windows).

Is there any way to get things to work on FF 3.5? I'm getting very confused 
from all 
of the suggestions in this forum, I just want a definitive answer. Is there 
anyone 
working on a "formal" fix to the problem?

Original comment by ssmith3...@rogers.com on 1 Mar 2010 at 9:12

GoogleCodeExporter commented 9 years ago
My goal was to get our test code working with Firefox 3.5.  It now does, using 
the
modifications to Khroliz's code listed at the beginning of this issue.  Given 
comment
8, there are likely further issues with Firefox 3.5 that I have not yet 
encountered.

I'd also like to know if someone is working on a "formal" fix, and what 
open-source
code would most likely incorporate it.

Original comment by stevecbo...@gmail.com on 4 Mar 2010 at 5:49

GoogleCodeExporter commented 9 years ago
Steve,

I'm a little confused now. These issues are scattered over several Issue 
Reports, 
and I seem to remember reading that the Khroliz fix didn't work. I can't find 
the 
reference, so I think that I may have just imagined it in my confusion. Bottom 
line 
is I never tried that fix, so perhaps it works properly, and you don't need to 
worry 
about further problems you've yet to encounter.

Given that, what are the versions of the pieces of the system that you're 
successfully running, and where are the fixes I'll need to apply?

Original comment by ssmith3...@rogers.com on 5 Mar 2010 at 1:16

GoogleCodeExporter commented 9 years ago
The initial posting for Issue 38 tells about my environment, so I
won't repeat that.

At the beginning of Issue 38 are two downloadable files.  Download
user-extensions.js.   It contains the modifications I had to make to
Khroliz's code to work in my environment.

Once you have the file, look at comment #6 for how to use it with Selenium.

Good luck!

Original comment by stevecbo...@gmail.com on 8 Mar 2010 at 6:18

GoogleCodeExporter commented 9 years ago

I still have this issue....

Using MAC OS X 10.6.3
FF 3.6.3

  public static void setUpClass() throws Exception {

     selenium = new DefaultSelenium(
      values.getString("selenium.serverHost"),
      Integer.valueOf(values.getString("selenium.serverPort")),
      values.getString("selenium.browserStartCommand"),
      values.getString("selenium.baseUrl"));

    String userExt = readFileAsString("user-extensions_20100113.js");
    selenium.setExtensionJs(userExt);

    selenium.start();

    flexSelenium = new FlexSelenium(selenium, values.getString("application.name"));

  }

  public void actuallTest(){
   flexSelenium.call("doFlexClick", "logoutButton");
 }

Still throws

com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: NPMethod
called on non-NPObject wrapped JSObject!
    at
com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrE
rror(HttpCommandProcessor.java:97)
    at
com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.ja
va:91)
    at
com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.ja
va:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:443)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:57)

Original comment by anderson...@gmail.com on 7 May 2010 at 4:42

GoogleCodeExporter commented 9 years ago
Checking out the flashselenium project and overridding the Selenium.java file 
with
the one in the first post does seem to resolve the issue.

What is currently being done to incorporate those changes into the project?

Original comment by anderson...@gmail.com on 10 May 2010 at 3:13

GoogleCodeExporter commented 9 years ago
I'm not sure the code from the head posting of Issue 38 is ready for prime 
time.  It
works, much of the time, but random command timeouts and other errors have 
prevented
us from adopting it as "the" solution for our Flex testing needs.

We use Linux test heads running Firefox 3.6, if that makes any difference.

Original comment by stevecbo...@gmail.com on 2 Jun 2010 at 5:58

GoogleCodeExporter commented 9 years ago
I was able to run the test using *firefoxproxy. 
(http://samadesoga.blogspot.com/2009/11/workaround-flash-selenium-test-would.htm
l)
- I am running ff 3.6.3 on windowsxp.

Original comment by mmarcan...@gmail.com on 4 Jun 2010 at 6:56

GoogleCodeExporter commented 9 years ago
 I am very new to Flex-selenium and am facing the same Exception.

com.thoughtworks.selenium.SeleniumException: ERROR: Threw an exception: 
NPMethod called on non-NPObject wrapped JSObject!
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:443)
    at com.thoughtworks.selenium.FlashSelenium.call(FlashSelenium.java:57)
    at com.thoughtworks.selenium.FlashSelenium.PercentLoaded(FlashSelenium.java:97)
    at com.thoughtworks.selenium.FlexUISelenium.waitUntilLoaded(FlexUISelenium.java:26)
    at CalculateSumTest.setUp(CalculateSumTest.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

The following is my source code (compareSum.mxml) that is built with 
SeleniumFlexAPI.swc. (This is the same sample code that is available at one of 
the flexSelenium sites).  
<?xml version="1.0"?>
<!-- usingas/SourceInclude.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
creationComplete="init();">
    <mx:Script>
        <![CDATA[ 
            private function computeSum(a:Number, b:Number):Number {
                return a + b;
            }
        ]]>
    </mx:Script>

    <mx:TextInput id="arg1" text="3" width="40" x="170" y="24" textAlign="right"/>
    <mx:TextInput id="arg2" text="3" width="40" x="170" y="52" textAlign="right"/>

    <mx:TextArea id="result" height="25" width="78" x="132" y="82" textAlign="right"/>

    <mx:Button id="submit" label="Compute Sum" 
               click="result.text=String(computeSum(Number(arg1.text), Number(arg2.text)));" 
               x="105" 
               y="115"
               />

    <mx:Label x="148" y="52" text="+" fontWeight="bold" fontSize="17" width="23"/>
</mx:Application>

My test code is as follows:

public class CalculateSumTest {

        private final static String URL = "file:///Users/syedidha/Documents/Adobe%20Flash%20Builder%204/Sample/bin-debug/compareSum.html";

        private Selenium selenium;
        private FlexUISelenium flexUITester;

        @Before
        public void setUp() throws Exception {        
                selenium = new DefaultSelenium("localhost", 4444, "*firefox",URL);
                selenium.start();
                selenium.open(URL);
                flexUITester = new FlexUISelenium(selenium, "compareSum");
                flexUITester.waitUntilLoaded();
        }

        @After
        public void tearDown() throws Exception {
                selenium.stop();
        }

        @Test
        public void sumForValidNumbers() {
                flexUITester.type("2").at("arg1");
                flexUITester.type("3").at("arg2");
                flexUITester.click("submit");
                assertEquals("5", flexUITester.readFrom("result"));            

                flexUITester.type("-2").at("arg1");
                flexUITester.type("-3").at("arg2");
                flexUITester.click("submit");
                assertEquals("-5", flexUITester.readFrom("result"));            
        }

        @Test
        public void sumForInvalidNumbers() {
                flexUITester.type("Not a Number").at("arg1");
                flexUITester.type("3").at("arg2");
                flexUITester.click("submit");
                assertEquals("NaN", flexUITester.readFrom("result"));          
        }                
}
Please help!
Thanks 

Original comment by siri.p...@gmail.com on 11 Aug 2010 at 2:27

GoogleCodeExporter commented 9 years ago
Is there plan to include this fix in next Flash Selenium version which will 
support firefox 3.6.X ?

Original comment by ybh...@gmail.com on 20 Sep 2010 at 1:11

GoogleCodeExporter commented 9 years ago
Does anyone have a workaround for this issue?
Browsers That I need support for is
Firefox 3.6.10
IE 8
OS Win 7/Win XP

Original comment by harshmtr...@gmail.com on 25 Sep 2010 at 12:27

GoogleCodeExporter commented 9 years ago
I got this working using the *firefoxproxy, however with using *firefoxproxy I 
ran into a permission denied issue. Is anyone else seeing this?

Original comment by harshmtr...@gmail.com on 1 Oct 2010 at 8:25

GoogleCodeExporter commented 9 years ago
I guess using *fireforxproxy means backward compatibility and hence some 
features won't be available. I can get working Firefox 3.6.10 with Flash 
Selenium Revision 55 .NET client using *firefoxproxy as a browser string, but 
some features like capturefullpagescreenshot is not available.

So I am looking for fix in Flash Selenium where I can use *chrome/*firefox as 
Browser String with Firefox 3.6.10

Original comment by ybh...@gmail.com on 7 Oct 2010 at 8:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I saw the permission denied issue too while using *firefoxproxy. The reason is 
that my homepage accesses two different domains, one is its own and the other 
is www.facebook.com. In my selenium scripts I check the is_element_present to 
sign in button. Due to the limitations of *firefoxproxy mode, this situation 
violates the same origin policy. After changing the is_element_present to 
is_text_present, the issue is solved as I don't need locator anymore.

I'm running FF 3.6 on Win 7.

Original comment by qzhja...@gmail.com on 21 Jan 2011 at 6:26