1

I am using Selenium RC with Junit.

After running following simple script i am getting timeout error.

com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms

I have recorded the IDE script which work fine using IDE. When same code formatted using Junit format and tried to run through Eclipse and Junit it gives above timeout error.

package script;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class ComparePrice extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("http://www.landmarkonthenet.com/", "*firefox");
    }
    public void testComparePrice() throws Exception {
        selenium.open("http://www.landmarkonthenet.com/");
        selenium.click("link=Books");
        selenium.waitForPageToLoad("60000");
        selenium.type("id=TopSearch", "junit");
        selenium.click("css=button[type=\"submit\"]");
        selenium.waitForPageToLoad("60000");
        selenium.click("xpath=(//a[contains(text(),'Desc')])[2]");
        selenium.waitForPageToLoad("60000");
        String P1 = selenium.getText("xpath=/html/body[@id='department']/div[@id='page-body']/div[@id='main-content']/div[@id='page-content']/div[3]/div[1]/article/div[2]/p/span[1]");
        System.out.println(P1);
        String P2 = selenium.getText("xpath=/html/body[@id='department']/div[@id='page-body']/div[@id='main-content']/div[@id='page-content']/div[3]/div[2]/article/div[2]/p/span[2]");
        System.out.println(P2);
        String T3 = selenium.getEval("var A = Number(\"" + P1 + "\".substr(3).replace(/,/g,'')); var B= Number(\"" + P2 + "\".substr(3).replace(/,/g,'')); var c = false; if(A>=B) C=true; C");
        System.out.println(T3);
    }
}
testing
  • 1,736
  • 15
  • 46
  • 75
Sudhir Patil
  • 25
  • 3
  • 7

5 Answers5

0

in which line do you get the timeout error? usually it's when selenium can not recognize an element from the DOM, check your xpaths if they return anything. I would recommend you to use xpath finder: https://addons.mozilla.org/en-us/firefox/addon/xpath-finder/

Nir
  • 1,524
  • 6
  • 23
  • 41
  • When I run above class. its just open the site http://www.landmarkonthenet.com and after few second its closes the browser giving above error. As per steps it should click the Books link and redirect to the following page http://www.landmarkonthenet.com/books/.. this is not happening. I have check the Xpath of the link ( Books) which is /html/body[@id='home']/header/div[2]/div[@id='mainnav']/nav[@id='browse']/ul/li[1]/a – Sudhir Patil Mar 03 '13 at 05:49
  • which firefox version do use? notice sometimes Selenium is able to open the browser properly and execute a navigation such as openning the website but when it comes to recognize the DOM element is failing. – Nir Mar 03 '13 at 11:08
0

try to use Selenium Remote Control 1.0.2 you can read about it here Selenium Remote Control 1.0.2 and download the jar there:

Nir
  • 1,524
  • 6
  • 23
  • 41
  • 1.I tried it with Selenium RC 1.0.2. Still getting same problem. 2. Another probelem i want to note that when i run the script it opens two browser one of rc server and other of the test url which i used in my script. Can any one tell me what the purpose of first browser i.e. which display some RC server detail. How we can avoid it – Sudhir Patil Mar 09 '13 at 15:19
0

Update Selenium RC standalone jar to the latest: http://docs.seleniumhq.org/download/ i.e. 2.31.0

Put some next element for waiting that you are expecting to come up once URL is loaded using waitForElementToPresent instead of waitForPageToLoad

Use windowMaximize for better view.

If your complete session is getting timeout, then use setTimeOut

Amit Shakya
  • 1,396
  • 12
  • 27
0

Instead of using selenium.waitForPageToLoad("60000");

Try to use the following after every click

for (int second = 0;; second++) {
            if (second >= 60) Assert.fail("timeout");
            try { if (selenium.isVisible("next element")) break; } catch (Exception e) {}
            Thread.sleep(1000);
        }

You will then be able to find out where exactly its getting timed out error e.g.

public void testComparePrice() throws Exception {

selenium.open("http://www.landmarkonthenet.com/");

selenium.click("link=Books");

for (int second = 0;; second++) {
    if (second >= 60) Assert.fail("timeout");
    try { if (selenium.isVisible("id=TopSearch")) break; } catch (Exception e) {}
    Thread.sleep(1000);
        }

selenium.type("id=TopSearch", "junit");
selenium.click("css=button[type=\"submit\"]");

And so on

gaurav
  • 1
  • 1
0

You can try below approach -> 1. Whenver you are trying to navigate through the appliction. find out some static elements in the application, and apply dynamic wait control by using For Loop and inside loop, check whether that element is present or not.

for (int second = 0;; second++) {
        if (second >= 160) fail("timeout");
        try { if (selenium.isTextPresent(" Web Element on the page")) break; } catch (Exception e) {}
        Thread.sleep(1000);
    }