13 Replies Last post: Jun 21, 2009 4:11 AM by daScientist  
demiurg Beginner 43 posts since
Dec 26, 2008
Currently Being Moderated

Jun 6, 2009 5:18 PM

Proxy injection mode not working

Is proxy injection mode  supposed to work at all or not ?

 

The following code, which (not surprisingly) works OK in the default mode

browser.open("http://www.ca.com");
browser.waitForPageToLoad("50000");

fails with the following exception in proxy injection mode

 

org.openqa.selenium.server.RemoteCommandException: timed out waiting for window '' to appear

 

 

Any ideas ?

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
1. Jun 10, 2009 3:32 AM in response to: demiurg
Re: Proxy injection mode not working

How do you set-up the proxy ?

did you try do ping it to see the latency ?

 

can you provide the code you use to set-up the selenium-server ?

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
3. Jun 10, 2009 4:33 AM in response to: demiurg
Re: Proxy injection mode not working

yep - you right - I confused it with setting a custom proxy .

 

but nevertheless - I've tested your case ( selenium 1.0 , started with -proxyInjectionMode ).

 

the test was

 

        browser = new DefaultSelenium( "localhost", 4444, "*firefox", "http://localhost/" );
        browser.start();
        browser.open( url );    
        // some test .........
        browser.close;
 

it worked fine ( I also tested it with ebay according the url to the bug you've sent ).

 

Can you send me how do you initialize the browser ?

Which version of browser/selenium are you using ?

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
5. Jun 10, 2009 9:13 AM in response to: demiurg
Re: Proxy injection mode not working

Yep - you're right . the problem is in waitForPageToLoad.

 

I''ve added stackTrace from selenium-server to your bug ( http://jira.openqa.org/browse/SRC-678 )

 

this happens in Selenium-Server ( the stack trace you placed in the bug is from selenium browser ) , and the problem is ( I think ) in fact that proxyInjectionMode inserts another Frame to the page - and the waitForLoad() method confuses it with the actual page.

 

In general from what I've found in the net - using waitForPageToLoad is not always encouraged , probably because of these non deterministic behaviours.

I've debugged the server - in proxyInjectionMode it has a frame named "top" - which causes the wait to fail.

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
7. Jun 10, 2009 9:34 AM in response to: demiurg
Re: Proxy injection mode not working

think you can use browser.wait() ,

or even Thread.sleep() -> cause the page loading is being performed in separate Thread anyway.

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
9. Jun 14, 2009 2:52 AM in response to: demiurg
Re: Proxy injection mode not working

any Object.wait() can throw that exception ( in addition to InterrupedException ) . refer to http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#wait(long)

if you use Thread.sleep() InterruptedException should also be caught ( http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Thread.html#sleep(long) )

 

so in general - simply surround it with try-catch . this will do the work

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
11. Jun 16, 2009 10:09 AM in response to: demiurg
Re: Proxy injection mode not working

Well  - I simply thought that it's trivial to read the following : http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#wait(long)

The exception is generated because you don't own the monitor on selenium.

 

in case you use browser.wait(); you probably forgot to synchronize it

 

synchronized(browser)
{
     browser.wait(SOME_TIMEOUT);
     browser.notifyAll();
}

 

or you can use Thread.sleep()  -> as it embeds the synchronized block  - and you need to catch only InterruptedException.

daScientist Advanced 64 posts since
Jun 1, 2009
Currently Being Moderated
13. Jun 21, 2009 4:11 AM in response to: demiurg
Re: Proxy injection mode not working

welcome . ( didn't mean to give you a lesson - just wanted to ensure you RTFM ).

 

The code I've suggested - simply waits the specified amount of time ( InterruptedException will be generated if some other thread Interrups the selenium during the wait ).

The waitForPageToLoad() - is special cause it stops waiting when the page is loaded ( you've opened a bug in it no ? ).

you can replace it with wait() only if you know when exactly the page is fully loaded - i.e. you know of any element which loads in the end.

Let's say you have element with id = "someLastElement1" - they you can use the following code ( which emulates the waitForPageToLoad() pretty well ).

 

 

private void customWaitForPageToLoad(long timeout, long singleStep )
{
        long maxWait = 0;
        while( maxWait < timeout )
        {
            if( browser.isElementPresent( "someLastElement1" ) )
            {
                return;
            }
            else
            {
                maxWait += singleStep;
                try
                {
                    Thread.sleep( singleStep );
                }
                catch ( InterruptedException e )
                {
                    e.printStackTrace();
                    // your interrupt handling
                }
            }
        }
}
 
 

the singleStep should be ~100milliseconds - this way you won't wait too much after page loaded.

More Like This

  • Retrieving data ...