Seleniumに問題があります。次のテストでは、Webサイトにアクセスし、製品を取り出してカートに追加し、カートに移動する必要があります。その間に、いくつかの要素が表示されるのを待ちます。
私のマシンでは、カートに製品を追加するまでテストは正常に機能します。この後、divはajaxで満たされ、テストはそこで要素を待機する必要があります。要素はブラウザに表示されますが、テストは待機中です。タイムアウトでさえ、それを気にするほど面白くないようです。
wait.until(pause(2));
代わり に待つか、driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
すべてを設定すると正常に機能しますが、これは正しい解決策にはなりません。
何か案が?
私のシステム:
MacOS X10.8.2またはWindows7(64ビット)
Firefox 17.0.1
Java 1.6、JUnit 4.10、selenium-api-2.25.0、selenium-support-2.25.0、selenium-firefox-driver-2.25.0、guava-12.0
私のテスト:
import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;
import javax.annotation.Nullable;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.google.common.base.Function;
public class TestSomeWebsite {
@Test
public void test() throws Exception {
FirefoxDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("http://www.obi.de");
// take first product
driver.findElement(By.cssSelector("p.product_desc > a")).click();
// add to cart
wait.until(elementToBeClickable(By.id("addtocart")));
driver.findElement(By.id("addtocart")).submit();
// go to cart
/** everything fine by now **/
wait.until(elementToBeClickable(By.partialLinkText("Zum Warenkorb")));
/** we never come to this point :( **/
driver.findElement(By.partialLinkText("Zum Warenkorb")).click();
}
private Function<WebDriver, Object> pause(final int time) {
return new Function<WebDriver, Object>() {
int count = 0;
@Nullable
public Object apply(@Nullable WebDriver input) {
count++;
return count >= time;
}
};
}
}