TESTEVERYTHING

Friday 10 August 2012

Selenium Webdriver 2 Wait /Sleep for time period/wait next step execution/ Set speed for next execution

Some times we have to wait while running the script like for next execution wait for specific duration.But in web driver 2, I did not find the simple way to wait for next step execution after that I have decided to use simplest way to wait in looping statement. I have created a method just call the method with waiting time in seconds.It will wait for given time period.




    public void SleepWait(long timeInSeconds)
    {
        long t= System.currentTimeMillis();
        timeInSeconds = timeInSeconds*1000;
        long end = t + timeInSeconds;
        while(System.currentTimeMillis() < end)
        {
           // to do something
        }
    }

  
        driver = new FirefoxDriver();
        driver.get("www.google.com");
        driver.findElement(By.id("gbqfq")).clear();
        driver.findElement(By.id("gbqfq")).sendKeys("selenium");
        driver.findElement(By.id("gbqfb")).click();

        // calling wait method

        SleepWait(5);

// OR you can use driver wait time

        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);


        String Searchtext;
        Searchtext = "Selenium IDE";
        if (verifyTextPresent(Searchtext)!=true)
            {
            Assert.fail("Did not find the text :" +Searchtext);
            }
       
   

No comments:

Post a Comment

Which one is right ?

Translate







Tweet