Safari版本:11.0.2 MAC版本:10.12.6 Mac OS Sierra selenium-java版本:3.5.3 语言:JAVA
每当我在Safari驱动程序上运行selenium测试时,它会在执行几个步骤后挂起(无法找到特定的模式)。 IOS / Safari,Android / Chrome,MAC / Chrome上的相同测试运行文件。
工作正常,你在debug / step中逐步运行测试。可能是Safari没有回应的原因是什么?
答案 0 :(得分:0)
以下是模拟问题的代码。 Safari挂起,无法点击“继续购物”
public static void main(String[] args) {
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
// safariOptions.setUseTechnologyPreview(true);
DesiredCapabilities safariCapabilities = DesiredCapabilities.safari();
safariCapabilities.setJavascriptEnabled(true);
safariCapabilities.setAcceptInsecureCerts(true);
safariCapabilities.setPlatform(Platform.MAC);
safariCapabilities.setCapability("platformName", Platform.MAC);
safariCapabilities.setVersion("11.2");
safariCapabilities.setBrowserName("safari");
safariCapabilities.setCapability(SafariOptions.CAPABILITY, safariOptions);
WebDriver safariDriver = new SafariDriver(safariCapabilities);
safariDriver.manage().window().maximize();
safariDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
safariDriver.get("https://www.shoppersstop.com/");
waitFor(safariDriver, ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='cart']")));
safariDriver.findElement(By.xpath("//a[@href='cart']")).click();
waitFor(safariDriver, ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Continue Shopping']")));
safariDriver.findElement(By.xpath("//a[text()='Continue Shopping']")).click();
}
public static <T> T waitFor(WebDriver safariDriver, ExpectedCondition<T> condition) {
return new FluentWait<WebDriver>(safariDriver).withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(500, TimeUnit.MILLISECONDS).until(condition);
}
答案 1 :(得分:0)