Share
Go down
prasad ginjupalli
Posts : 2
Join date : 2015-05-22

How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Fri May 22, 2015 2:03 pm
Hi everyone,
We have recently started automating the Test Cases of our websites using Selenium Webdriver.
However we find that even though a test case has been correctly automated, it cannot be executed in a  reliable fashion:
-    Different parts of a website get loaded at different speeds (due to various factors like net traffic, server load etc.)
-    If the web-control (text box, frame etc..) has not yet loaded in the browser when Selenium starts to look for it, the script will simply fail with a message that the control was not found.
-    The solutions we have found so far on the internet is that we should increase the time that Selenium should wait till it starts looking for the control.
-    The trouble is that each time it seems to fail at a different point or control on the website.
-    This forces us to introduce a “thread.sleep()” statement at each and every step i.e. before  each click, text entry, item selection etc.
-    This however has the downside of hugely increasing the test execution time.

Any advice from you on this would be much appreciated.
Job46
Posts : 3
Join date : 2015-05-22

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Fri May 22, 2015 4:23 pm
Hello,
you can change the command 'click' by using 'clickAndWait' in the Selenium IDE.

Or you cant try "SeleniumUtils.WaitForElement(By./* you put your web control */, driver);

Ex: (C# code)

SeleniumUtils.WaitForElement(By.LinkText("test"), driver);

driver.FindElement(By.LinkText("test")).Click();
prasad ginjupalli
Posts : 2
Join date : 2015-05-22

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Tue May 26, 2015 12:03 pm
Hi Job46,

Thank you for your advice.

we will try this and let you know results
AgoBalan
Amateur
Amateur
Posts : 36
Join date : 2015-02-23

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Fri May 29, 2015 1:56 pm
Dear Job46,
please be careful wilreplying back to users,in your reply "SeleniumUtils.WaitForElement(By.LinkText("test"), driver);" 
is SeleniumUtils a method in  selenium or a class in your framework?,I think its a class in your framewrok there is no SeleniumUtils method in selenium,

New user will get confused so easily,they might look for SeleniumUtils method in selenium jar file
AgoBalan
Amateur
Amateur
Posts : 36
Join date : 2015-02-23

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Fri May 29, 2015 2:02 pm
dear prasad ginjupalli,
Always define your own  method  for all raw selenium command,for example insteasd of directlky using driver.click method,you should have your own defined method for click,

public void clickOnWEbElements(String strXpath){
int iMaximumTimeWait=30;
while(!iMaximumTimeWait=0){
  try{
  driver.findelement(By.xpath("passed xpath value")).click();
   break;
   }
  catch(Exception e){
  Thread.sleep(1000);
  iMaximumTimeWait=iMaximumTimeWait-1;
  }
}
if(iMaximumTimeWait==0){
"break execution";
}
}
Job46
Posts : 3
Join date : 2015-05-22

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Fri May 29, 2015 5:15 pm
hey ! 
I finally tried something new using @AgoBalans code.
This is my version:

public void clickOnWEbElementsCAR(String strXpath)
        {
            countDown(By.XPath(strXpath));
        }


public void countDown(By by)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            while (stopwatch.ElapsedMilliseconds < 60000) // 1 min before timeOut
            {
                try
                {
                    driver.FindElement(by).Click();
                    break;
                }
                catch (Exception)
                {
                    // Ignore errors if unable to click
                }

            }
        }
AgoBalan
Amateur
Amateur
Posts : 36
Join date : 2015-02-23

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

on Fri May 29, 2015 5:18 pm
Very Happy
Sponsored content

Re: How to minimize test cases execution time Vs timeout failures in Selenium WebDriver

Back to top
Permissions in this forum:
You cannot reply to topics in this forum