Safari驱动程序在运行自动化测试时挂起

时间:2017-12-21 00:28:25

标签: selenium-webdriver safaridriver

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没有回应的原因是什么?

2 个答案:

答案 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)

即使主题死了,我也遇到类似的问题,解决方法是设置

之后关闭显示”设置为“ 从不

在 “苹果”>“首选项”>“节能器” enter image description here