3

My application uses Mink with Selenium 2 driver. when i try to load the page with some resources that are loading slow (or not loading at all) the application waits infinitely until everything is loaded.

for i have several hundreds of iterations in my application - you can imagine how long the script is executed.

question: is there any possibility to set a timeout for page to load? and throw some exception if the page is not loaded during that period?

thanks in advance!

4

4 回答 4

1

根据这篇文章,你可以这样做:

$driver->setTimeouts(['page load' => 10000]);

此超时以毫秒为单位。

于 2015-04-02T10:47:03.753 回答
-1

要在selenium ide中设置页面加载超时,请执行以下步骤:

1.打开selenium ide。

2.点击选项菜单。

3.一般选项卡更改记录命令的默认超时值。

![单击选项菜单后的 Selenium ide 图像][1]

selenium 2中使用此功能

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

尝试这个

 private $timeout = 60000;


public function reload()
    {
        $this->browser
            ->refresh()
            ->waitForPageToLoad($this->timeout)
        ;
    }
  [1]: h

ttp://i.stack.imgur.com/0NKoC.png

于 2013-04-20T06:23:38.820 回答
-1

请在 Featurecontext.php 中使用以下三个函数

public function spin($lambda, $retries,$sleep)  {
do {
$result = $lambda($this);
} while (!$result && --$retries && sleep($sleep) !== false);


}
public function find($type, $locator, $retries = 20, $sleep = 1) {
return $this->spin(function($context) use ($type,$locator) {

$page = $context->getSession()->getPage();
if ($el = $page->find($type, $locator)) {
    if ($el->isVisible()) {
        return $el->isVisible();
    }
}
return null;
}, $retries, $sleep);

}

/**
* Wait for a element till timeout completes
*
*  @Then /^(?:|I )wait for "(?P<element>[^"]*)" element$/
*/
public function iWaitForSecondsForFieldToBeVisible($seconds,$element) {

  //$this->iWaitSecondsForElement( $this->timeoutDuration, $element);
$this->find('xpath',$element);
}
于 2013-10-25T13:44:44.210 回答
-2

Behat文档建议在您的上下文中使用自定义 spin() 函数。

以下 spin() 函数示例取自 behat 文档:

public function spin ($lambda, $wait = 60)
{
    for ($i = 0; $i < $wait; $i++)
    {
        try {
            if ($lambda($this)) {
                return true;
            }
        } catch (Exception $e) {
            // do nothing
        }

        sleep(1);
    }

    $backtrace = debug_backtrace();

    throw new Exception(
        "Timeout thrown by " . $backtrace[1]['class'] . "::" . $backtrace[1]['function'] . "()\n" .
        $backtrace[1]['file'] . ", line " . $backtrace[1]['line']
    );
}

不幸的是,我没有一个工作示例如何将其集成到您的上下文中。

于 2013-05-12T00:44:30.847 回答