7 Replies Last post: Jan 7, 2009 11:27 AM by Paul Grandjean  
Paul Grandjean Master 417 posts since
Feb 4, 2008
Currently Being Moderated

Dec 22, 2008 12:31 PM

what's "proxy injection mode"

alright, I'm full of questions today!

 

Just read this in the Selenium RC Tutorial.

 

"If your test needs to use multiple domains (HTTP and HTTPS in the same test), your best choices are the *chrome or *iehta browser launchers, alternatively you can use proxy injection mode."

 

What's proxy injection mode"? 

anatar02 Master 379 posts since
Apr 4, 2008
Currently Being Moderated
1. Dec 23, 2008 5:38 AM in response to: Paul Grandjean
Re: what's "proxy injection mode"

Hi,

If you are starting selenium server through multiWIndow mode or interactive mode then it will make your proxy setting by automatically, But If you are staring through proxyInjectionMode then you can set your own proxy setting....

 

 

Thanks

Ashok N

Haw-Bin Chai Master 515 posts since
May 19, 2006
Currently Being Moderated
3. Dec 26, 2008 12:10 PM in response to: Paul Grandjean
Re: what's "proxy injection mode"

Not having used PI mode much, here's my understanding (anyone please correct me if I'm wrong!):

 

In non-PI mode, there is NO proxy between the browser and the AUT. Requests and responses are exchanged directly between them. The Selenium server is basically responsible for launching the Selenium-instrumented browser window, and the Selenium frame/window communicates with the RC. This frame/window has a reference to the "normal" browser window and thus controls test execution.

 

Browser  <=>  WebApp

 

In PI mode, the Selenium server sits between the browser and the AUT. As such, it can intercept and manipulate the exchange on the request / response level. One thing this makes possible is injecting arbitrary markup / scripting into any part of the response data, so we can inject javascript into the <head> element that runs before the rest of the page starts to load. This isn't possible in non-PI mode. Because we have this ability in PI mode, we don't even need a separate frame/window for Selenium - it's injected directly into the AUT. This does introduce a greater possibility of javascript variable namespacing issues, however.

 

Browser  <=>  Selenium server as proxy  <=>  WebApp

 

PI mode also allows you to work around the same origin policy. I believe that is one of the reasons it was first implemented.

 

 

 

Haw-Bin

Haw-Bin Chai Master 515 posts since
May 19, 2006
Currently Being Moderated
5. Jan 3, 2009 12:06 PM in response to: Paul Grandjean
Re: what's "proxy injection mode"

Paul,

 

Yet more good questions ... you're forcing me to go digging for the answers myself, which is good. 

 

1)  I don't believe HTA and chrome modes involve a proxy between the browser and AUT. They are able to circumvent the same origin policy because they are running with elevated privileges. HTA, or "HTML Application", is really an HTML file that is opened locally, and as such can access the filesystem and basically act like a desktop application, thus escaping the browser sandbox ... and the same origin policy. Chrome is an elevated privilege mode for Firefox that is accessed via "chrome URL's", i.e. URL's that start with "chrome://" . Firefox plugins, for example, are accessed via chrome URL's, and are able to use the Firefox API's for accessing / modifying the filesystem and again basically acting like a full fledged application. With these two privileged modes, it's not necessary to have a proxy.

 

2)  If you run the Selenium server with an invalid argument, it will print out a help message. This will give you an idea of the ways in which proxy injection can be useful:

...
 -proxyInjectionMode: puts you into proxy injection mode, a mode
    where the selenium server acts as a proxy server for all content
    going to the test application.  Under this mode, multiple domains
    can be visited, and the following additional flags are supported:

    -dontInjectRegex <regex>: an optional regular expression that
      proxy injection mode can use to know when to bypss injection
    -userJsInjection <file>: specifies a JavaScript file which will
      then be injected into all pages
    -userContentTransformation <regex> <replacement>: a regular
      expression which is matched against all test HTML content; the
      second is a string which will replace matches.  These flags can
      be used any number of times.  A simple example of how this could
      be useful: if you add "-userContentTransformation https http"
      then all "https" strings in the HTML of the test application will
      be changed to be "http". 
...

Apart from rewriting HTTPS URL's as HTTP, another example use of for proxy injection is capture javascript errors that happen on the page, by redefining window.onerror . Normally, you are not able to catch any javascript errors that happen on the page during page load. However, because PI mode allows you to inject script content before the page content, the redefinition of onerror will happen in time to catch the errors.

 

One note about the -userJsInjection flag - the entire content of the file you specify will be included before the <html> element on the page, and will not be automatically placed in a <script> block. Thus, the content of the injected file should probably be something like:

 

<script>
// my customizations
window.error = function() { return true; }
...
</script>

And also remember that when using PI mode, you need to specify a PI browser, i.e. *piiexplore .

 

3)  PI mode has been consistently labeled as "experimental" in the documentation. I'm not sure of the extent of its usage. It was broken in Subversion for a while and I didn't personally encounter a ton of complaints (but that doesn't mean anything!) Some JIRA tickets indicate a desire to make PI mode the default mode, but I'm not sure if that's still the intention. It should be working in the latest snapshot.



Haw-Bin
Bill Expert 212 posts since
Oct 3, 2008
Currently Being Moderated
6. Jan 7, 2009 10:55 AM in response to: Haw-Bin Chai
Re: what's "proxy injection mode"

I actually find PI mode the best mode for IE testing and would be a real step forward for RC if it was the IE standard.....at least I would if it worked as intended.

 

Advantage over normal IE multiwindow is speed as there is no RPC overhead.

Advantage over IEHTA is that you get a real IE instance and thus don't run into these pesky js error popups.

 

However I find (at least with my AUT) that it breaks styles, font and font sizes are wrong, formatting is all over the place and it completely breaks some functionality all together. I suspect this is the reason for its poor adoption.

More Like This

  • Retrieving data ...