Feature Requests item #1563168, was opened at 2006-09-21 17:31
Message generated for change (Comment added) made by javajeffg
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=497985&aid=1563168&group_id=61302

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Priority: 5
Submitted By: Jeff Grimshaw (javajeffg)
Assigned to: Nobody/Anonymous (nobody)
Summary: Can generic header information be included in context?

Initial Comment:
We're currently using Canoo WebTest at work and I'd
like to get them to switch over to jWebUnit.  One
feature they use heavily is in the Canoo WebTest
configuration where they set over a dozen values
including 'user-agent', 'x-wap-profile' and a bunch of
other 'x-up- ' values.  I know I can set user agent
using jWebUnit, but I'm stumped on the others.

Is there anyway I can do the same thing with jWebUnit?

Thanks,
    Jeff


----------------------------------------------------------------------

>Comment By: Jeff Grimshaw (javajeffg)
Date: 2006-09-22 12:12

Message:
Logged In: YES 
user_id=552874


Thanks for your quick response.

How about this (sorry I can't make a patch at this time):


  public class TestContext {
   ...
        private Map requestHeaders = new HashMap();
   ...
        public void addRequestHeader(final String name,
final String value) {
            requestHeaders.put(name, value);
        }

        public void removeRequestHeader(final String name) {
          requestHeaders.remove(name);
        }

        public Map getRequestHeaders() {
          return requestHeaders;
        }

        public void resetRequestHeaders() {
          requestHeaders = new HashMap();
        }

   ...
 }

And then in HtmlUnitDialog's beginAt method:

   public void beginAt(String initialURL, TestContext
context) throws TestingEngineResponseException {

        this.setTestContext(context);

        // Pass the TestContext into the WebClient
initialization method.

        initWebClient(context);
   ...
   }

   private void initWebClient(TestContext context) {

        wc = new WebClient(new
BrowserVersion(BrowserVersion.INTERNET_EXPLORER,

                          "4.0", testContext.getUserAgent(),
"1.2", 6));

        // New loadRequestHeaders method to load the request
headers from the TestContext into the WebClient.
        loadRequestHeaders(wc, context);

     ...
   }

   private void loadRequestHeaders(WebClient wc, TestContext
context) {

        Map requestHeaders = context.getRequestHeaders();
        
        Set keys = requestHeaders.keySet();
        Iterator it = keys.iterator();
        
        while (it.hasNext()) {
            String nextRequestHeaderName  = (String) it.next();
            String nextRequestHeaderValue = (String)
requestHeaders.get(nextRequestHeaderName);
            
            wc.addRequestHeader(nextRequestHeaderName,
nextRequestHeaderValue);
        } 
   }
   

This way when WebClient's loadWebResponseFromWebConnection()
method get's called the additional header info will be
included before the call to
getWebConnection().getResponse(webRequestSettings); is made.

Thanks,
    Jeff


----------------------------------------------------------------------

Comment By: Julien HENRY (henryju)
Date: 2006-09-22 03:10

Message:
Logged In: YES 
user_id=1235926

There is currently no way to do this, as nobody ask for it.
If you need it, I think we can add it. HtmlUnit should
support it , but I think Selenium will not.

I don't know these header values, but it seems to be used to
identificate the browser of a mobile phone. Because Selenium
"only" simulate with IE, Firefox, and other browser for PC,
I don't think there is a chance to keep both Selenium and
HtmlUnit dialog reacting in the same way.

In a first time, we could make Selenium Dialog ignore these
values...

Could you please provide a patch for TestContext and for the
beginAt method in HtmlUnitDialog? Better, if you know a way
for testing these settings with Jetty, feel free to write
associated test cases.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=497985&aid=1563168&group_id=61302

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to