Menu

#307 Script Exception

closed
None
5
2012-10-21
2005-09-12
n-space
No

I’ve run into a particularly odd problem with HtmlUnit
throwing up a ScriptException and I’m not sure why.
I’ve tried this with 1.6 and (hoping it would solve the
problem) 1.7, but the problem exists in both.

I’ve attached a small ZIP file which contains two JSP
files that
demonstrate the problem.

You’ll need to drop these files on a server somewhere
and write a
small test that uses WebClient.getPage(…) on the
test.jsp file.

The issue is that HtmlUnit isn't finding the button I'm
changing the style on because it's below the iframe
that contains the jsp which sets the syle. That is
HtmlUnit is only looking at a portion of the page and
not the entire page as a browser normally would.

Discussion

  • n-space

    n-space - 2005-09-12

    Logged In: YES
    user_id=1096090

    Forgot to click checkbox - how annoying.

     
  • n-space

    n-space - 2005-09-12

    Files which can be used to reproduce the bug.

     
  • Marc Guillemot

    Marc Guillemot - 2005-09-13

    Logged In: YES
    user_id=402164

    I would be really easier if you provide your tests as html
    (the jsp use to generate it doesn't matter at all) or best,
    as unit test like the ones of htmlunit

     
  • n-space

    n-space - 2005-09-13

    Logged In: YES
    user_id=1096090

    Apologies for not following HtmlUnit standard. We needed to
    press on. We've taken a look at WebClientTest and followed
    it so that the test contained in the attached ZIP
    (HtmlUnitTest.zip) can be pasted into WebClientTest.

    In order for me to ensure that I could reproduce the
    problem, I had to extend TestCase instead of WebTestCase.

    Side Note: Is HtmlUnit small enough that the tests could be
    included in the JAR so that things like WebTestCase can be
    extended without having to grab and build the source on my own?

    Test attached... thanks for the help Marc.

     
  • n-space

    n-space - 2005-09-13

    Isolated test for the ScriptException issue in WebClient

     
  • Marc Guillemot

    Marc Guillemot - 2005-09-14

    Logged In: YES
    user_id=402164

    Your example is invalid: testing it on Firefox, I get:

    Error: top.document.getElementById("aButton") has no properties

    what is fully normal because the script gets executed before
    the button tag is parsed. Please reopen if you have an
    example that works in "normal" browsers.

    Unit test don't belong to the distribution: patches should
    be generated against the latest CVS state. It doesn't make
    sense to generate them against a particular version.

    Please have a look at
    http://htmlunit.sourceforge.net/submittingPatches.html
    Committers contribute to htmlunit in their free time. All
    improvements are welcome but they are more likely to be
    quickly included if they are in the right format and can be
    quickly applied.

     
  • n-space

    n-space - 2005-09-14

    Logged In: YES
    user_id=1096090

    Please note, my TestCase isnt accurately representing the
    HTML I sent. More on that later.

    Re:

    Your example is invalid: testing it on Firefox, I get:

    Error: top.document.getElementById("aButton") has no properties

    what is fully normal because the script gets executed before
    the button tag is parsed. Please reopen if you have an
    example that works in "normal" browsers.

    Where do you see this error? Im not currently seeing it
    with this version of Firefox:

    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10)
    Gecko/20050716 Firefox/1.0.6

    Or this version of Internet Explorer:

    6.0.2900.2180.xpsp_sp2_gdr.050301-1519

    I realized that perhaps the TestCase I submitted isnt the
    same as the HTML I submitted. I apologize for this.

    That is, Ive inlined the iframe in the TestCase. I wasnt
    sure how to follow this same approach, but actually have it
    reference a separate page. Perhaps you can show me by
    example and Ill update the TestCase and resubmit. If you
    view the HTML I submitted, youll see the error that Ive
    made and how its not exactly the same as the contents of
    the TestCase.

    On browser load order, my understanding is that it is
    primarily browser defined behaviour, but the fact that the
    HTML I submitted works in both browsers is particularly
    frustrating to me. My collegues tend to agree that the
    typical browser behaviour is to load the first page,
    building the DOM tree, then load any iframes, thus changing
    the DOM tree further. References in the parent page would
    then be in memory and accessible.

    Can you try the HTML I submitted, or suggest how I can adapt
    the TestCase I submitted to be more representative of the
    scenario Im trying to create?

    Thanks Marc!

     
  • Marc Guillemot

    Marc Guillemot - 2005-09-15

    Logged In: YES
    user_id=402164

    I think (not sure) that normal browsers start a new thread
    to load frames and that it could happen that your example
    doesn't work in a normal browser, depending on how the
    server flush its responses. To simplify, we could decide
    that htmlunit loads (i)frames contents only after the page
    has been loaded. It should not have any side effects and
    would probably solve some of the other frame related opened
    bugs.

    The 2 tests you've attached differ. Please checkout from CVS
    and have a look for instance at
    com.gargoylesoftware.htmlunit.javascript.host.FrameTest to
    see how to create a unit test that can directly be
    integrated in htmunit.

     
  • n-space

    n-space - 2005-09-20

    Unified Diff Patch for FrameTest.java

     
  • n-space

    n-space - 2005-09-20

    Logged In: YES
    user_id=1096090

    I've updated FrameTest to include a test case which exposes
    the issue. I have taken care to add the "notYetImplemented"
    call in it as Marc suggested.

    The patch for FrameTest is attached.

     
  • Marc Guillemot

    Marc Guillemot - 2005-09-21

    Logged In: YES
    user_id=402164

    Integrated test after simplification.

    Please take care to update from CVS before submitting a
    patch to generate it against the latest version.
    Please generate patch for the whole project even if it
    contains a single file: patch can be easier applied when
    they contain full path names

     
  • Marc Guillemot

    Marc Guillemot - 2005-10-10

    Logged In: YES
    user_id=402164

    Now fixed in CVS.

     

Log in to post a comment.