sTg
sTg

Reputation: 4424

Selenium testcase execution speed issues

I have a issue with selenium where i am able to pass the testcase, but the issue is the execution of the testcase is very quick. Is there any way or attribute through which i can control the speed of the execution. I have been facing this problem big time. Any help will be greatly appreciated. Below is my script for reference.

package test.selenium;

import java.util.concurrent.TimeoutException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class test{
    WebDriver driver;

    public TrafficGroupUpdateTestNG() {
    }

    /**
     * @throws java.lang.Exception
     */
    @BeforeTest
    public void setUp() throws Exception {
        // Use Internet Explorer and set driver;
        System.setProperty("webdriver.ie.driver",
                "D:\\IBM\\Selenium\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();

        // And now use this to visit URL
        driver.get("URL Of JSP");
    }

    /**
     * @throws java.lang.Exception
     */
    @AfterTest
    public void tearDown() throws Exception {
        driver.close();
    }

    @Test
    public final void test() {
        final WebElement formElement = driver.findElement(By.id("search"));

        final Select drelement = new Select(drelement.findElement(By.id("my_input")));


        drelement.selectByIndex(0);

        final WebElement submit = driver.findElement(By.id("Submit"));
        submit.click();

    }

}

Upvotes: 0

Views: 592

Answers (3)

Maddy
Maddy

Reputation: 63

There are many ways you can control speed of the execution..

Implicity wait

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

by providing this imlicity wait, webdriver waits until 20 seconds before it returns object not found

explicit wait

WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(locator));

This will wait explicitly for given element..

Upvotes: 0

sTg
sTg

Reputation: 4424

I used

Thread.sleep(2000);

A convinient way for making the page wait.

Upvotes: 0

Brantley Blanchard
Brantley Blanchard

Reputation: 1218

It sounds like elements from AJAX calls are not visible or ready when document.ready status is updated. Working with my webdevs, I had them add a waiting class while they loaded things and remove it when they're done.

As a result, I was able to create this "WaitForPageLoad" method that waits until AJAX is finished. It's in C# but simple enough to translate into Java.

Upvotes: 1

Related Questions