(I have switched to the DEV list)
Sound good to me. Don't forget to update the WebClient if it is already
initialized:
public void setRefreshHandler(RefreshHandler refreshHandler) {
this.refreshHanlder = refreshHandler;
//In case user wants to change RH in the middle of a test
if (wc != null) {
wc.setRefreshHandler(refreshHandler);
}
}
Could you please try to write a small JUnit test that is failing when using
ImmediateRefreshHandler and is fixed when using your patch. I think a page with
a refresh <meta> could do the job.
Also don't forget the ugly instanceof before casting the result of
getTestingEngine(), because JUnit tests are designed to run with all testing
engines.
Regards,
Julien
>
>De : Jason McSwain <[email protected]>
>À : Usage problems for JWebUnit <[email protected]>
>Envoyé le : Jeu 2 septembre 2010, 16h 43min 03s
>Objet : Re: [JWebUnit-users] Re : Re : Attempted to refresh a page using an
>ImmediateRefreshHandler which could have caused an OutOfMemoryError Please use
>WaitingRefreshHandler or ThreadedRefreshHandler instead
>
>i agree it's not a clean solution, but that's exactly what i was planning on
>doing. i'm working through the maven setup today and hope to have my env
>setup,
>compiled, and tested soon enough.
>
>here is what i was planning on doing in HtmlUnitTestingEngineImpl:
>
>
> * Add these:
> * private RefreshHandler refreshHandler = null;
> * public void setRefreshHandler(RefreshHandler refreshHandler)
> * Modify initWebClient()
> * if (this.refreshHandler == null) {
> wc.setRefreshHandler(new ImmediateRefreshHandler());
> } else {
> wc.setRefreshHandler(this.refreshHandler);
> }i'll also be putting the updated jar in my env, to see if this fixes the
>problem.
>
>-Jason-
>
>
>
>
>On Thu, Sep 2, 2010 at 1:54 AM, Julien HENRY <[email protected]> wrote:
>
>This is not a clean solution but an easy fix is to change visibility or add
>some
>methods in HtmlUnitTestingEngineImpl, and cast the use:
>>((HtmlUnitTestingEngineImpl) getTestingEngine()).xxxxx (where xxx could be
>>setDefaultRefreshHandler) before calling beginAt().
>>
>>Regards,
>>
>>Julien
>>
>>
>>>
>>>De : Jason McSwain <[email protected]>
>>>À : Usage problems for JWebUnit <[email protected]>
>>>Envoyé le : Mer 1 septembre 2010, 18h 34min 35s
>>>Objet : Re: [JWebUnit-users] Re : Attempted to refresh a page using an
>>>ImmediateRefreshHandler which could have caused an OutOfMemoryError Please
>>>use
>>>WaitingRefreshHandler or ThreadedRefreshHandler instead
>>>
>>>
>>>Thank you for the quick response. I would be interested in contributing.
>>>i'm
>>>looking through the contribution steps here. I would assume that it would
>>>be an
>>>easy fix. Once i have an env setup, i'll put in a fix, and let you review
>>>it.
>>>
>>>Is there any particular way that you would prefer to have this done?
>>>
>>>-Jason-
>>>
>>>
>>>
>>>
>>>On Wed, Sep 1, 2010 at 7:26 AM, Julien HENRY <[email protected]> wrote:
>>>
>>>Hi Jason,
>>>>
>>>>Currently there is no way to change the refresh handler. There is a long
>>>>standing issue about accessing HtmlUnit internals from JWebUnit API. At
>>>>first it
>>>>was a choice to prevent user to call HtmlUnit specific API and prevent easy
>>>>switch to another testing engine but now we admit there are cases where it
>>>>should be possible.
>>>>
>>>>We are waiting for contribution in this area.
>>>>
>>>>Regards,
>>>>
>>>>Julien
>>>>
>>>>
>>>>
>>>>>
>>>>>De : Jason McSwain <[email protected]>
>>>>>
>>>>>À : [email protected]
>>>>>Envoyé le : Mer 1 septembre 2010, 1h 03min 13s
>>>>>Objet : [JWebUnit-users] Attempted to refresh a page using an
>>>>>ImmediateRefreshHandler which could have caused an OutOfMemoryError Please
>>>>>use
>>>>>WaitingRefreshHandler or ThreadedRefreshHandler instead
>>>>>
>>>>>
>>>>>Hello,
>>>>>
>>>>>I searched both the Development and User forums, but didn't find an
>>>>>answer. if
>>>>>this has already been answered please point me to the right entry in the
>>>>>archives. Thank you in advance for any help you can provide.
>>>>>
>>>>>i'm new to the list, but have been using JWebUnit for the last 6 months.
>>>>>it
>>>>>works great on one of the products i test, so we decided to use it on
>>>>>another
>>>>>product, too. This new product has a page that refreshes every 30
>>>>>seconds, and
>>>>>when i go to setup my WebTester, i get an exception. about
>>>>>RefreshHandlers. We
>>>>>are using the HtmlUnit plugin, not selenium. The Question i have is how
>>>>>do i
>>>>>change the Refresh handler? This error happens when i call
>>>>>WebTester.beginAt("/"), and that method initializes the WebClient inside a
>>>>>private method, and sets the refreshHandler to the
>>>>>ImmediateRefreshHandler. i'd
>>>>>like to use another type.
>>>>>
>>>>>
>>>>>Error:
>>>>>java.lang.RuntimeException: Unexpected Exception during init.
>>>>> at TestWebTester.init(TestWebTester.java:53)
>>>>> at TestWebTester.<init>(TestWebTester.java:37)
>>>>> at TestWebTester.main(TestWebTester.java:60)
>>>>>Caused by: java.lang.RuntimeException: Refresh to http://10.10.10.31:90/
>>>>>(30s)
>>>>>aborted by HtmlUnit: Attempted to refresh a page using an
>>>>>ImmediateRefreshHandler which could have caused an OutOfMemoryError Please
>>>>>use
>>>>>WaitingRefreshHandler or ThreadedRefreshHandler instead.
>>>>> at
>>>>>com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:58)
>>>>>
>>>>> at
>>>>>com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1279)
>>>>>
>>>>> at
>>>>com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:218)
>>>>> at
>>>>>com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:427)
>>>>> at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:303)
>>>>> at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:360)
>>>>> at
>>>>>net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl.gotoPage(HtmlUnitTestingEngineImpl.java:248)
>>>>>
>>>>> at
>>>>>net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl.beginAt(HtmlUnitTestingEngineImpl.java:207)
>>>>>
>>>>> at net.sourceforge.jwebunit.junit.WebTester.beginAt(WebTester.java:228)
>>>>> at TestWebTester.init(TestWebTester.java:48)
>>>>>
>>>>>
>>>>>Here is an example code snippet that uncovers the issue:
>>>>>
>>>>>****************************************************************************************
>>>>>
>>>>>public class TestWebTester extends WebTester {
>>>>> private String baseUrl;
>>>>>
>>>>> public TestWebTester() {
>>>>> super();
>>>>> init();
>>>>> }
>>>>>
>>>>> public TestWebTester(String baseUrl) {
>>>>> super();
>>>>> this.baseUrl = baseUrl;
>>>>> init();
>>>>> }
>>>>>
>>>>> public void init() {
>>>>> System.out.println("TestWebTester.init()");
>>>>> // set base url
>>>>> try {
>>>>>
>>>>> setBaseUrl(this.baseUrl);
>>>>> // first part to load
>>>>> System.out.println(" -> set begin at = '/'");
>>>>> beginAt("/");
>>>>>
>>>>> } catch (TestingEngineResponseException e) {
>>>>> throw new RuntimeException("Unexpected
>>>>>TestingEngineResponseException during init.", e);
>>>>> } catch (Exception e) {
>>>>> throw new RuntimeException("Unexpected Exception during
>>>>> init.",
>>>e);
>>>>> }
>>>>> }
>>>>>
>>>>> public static void main(String[] args) {
>>>>> System.out.println("----- Begin -----");
>>>>> try {
>>>>> TestWebTester twt = new
TestWebTester("http://10.10.10.31:90/");
>>>>> } catch (Throwable t) {
>>>>> System.out.println("*** ERROR ***");
>>>>> t.printStackTrace();
>>>>> System.out.println();
>>>>> System.out.println("*************");
>>>>> }
>>>>>
>>>>> System.out.println("----- end -----");
>>>>> }
>>>>>}
>>>>>****************************************************************************************
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>------------------------------------------------------------------------------
>
>>>>This SF.net Dev2Dev email is sponsored by:
>>>>
>>>>Show off your parallel programming skills.
>>>>Enter the Intel(R) Threading Challenge 2010.
>>>>http://p.sf.net/sfu/intel-thread-sfd
>>>>_______________________________________________
>>>>JWebUnit-users mailing list
>>>>[email protected]
>>>>https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>>>
>>>>
>>>
>>
>>------------------------------------------------------------------------------
>>This SF.net Dev2Dev email is sponsored by:
>>
>>Show off your parallel programming skills.
>>Enter the Intel(R) Threading Challenge 2010.
>>http://p.sf.net/sfu/intel-thread-sfd
>>_______________________________________________
>>JWebUnit-users mailing list
>>[email protected]
>>https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>
>>
>
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development