Behat,PhantomJS - 点击链接后等待页面加载?

时间:2015-09-21 22:06:29

标签: selenium-webdriver phantomjs behat ghostdriver

我正在使用Behat 3和PhantomJS 2.目前我的方案定义如下:

@javascript
Scenario: I visit the blog through the Blog & Events menu.
  Given I am an anonymous user
  And I am on the homepage
  And I follow "Link Text"
  Then I should be on "/path-to-page"

当我和Goutte一起跑步时,它很好。当我用香草Selenium运行它时,它很好(它启动了我能看到的浏览器)。但是,当我将Selenium配置为将webdriver主机指向PhantomJS时,它会在Then I should be on "/path-to-page"上爆炸,声称它仍在/上。

如果我添加以下等待步骤:

@javascript
Scenario: I visit the blog through the Blog & Events menu.
  Given I am an anonymous user
  And I am on the homepage
  And I follow "Link Text"
  And I wait 4 seconds
  Then I should be on "/path-to-page"

然后我的场景以绿色传递,一切都很好。

在检查当前路径之前,有没有办法让PhantomJS等待页面加载?我不想依赖于任意超时。我需要一个无头解决方案,PhantomJS似乎得到了很好的支持,但是如果我不能做一些简单的事情,比如点击链接并验证加载的页面而不在任何地方添加随机等待步骤,我可能需要重新评估我的决定。

1 个答案:

答案 0 :(得分:0)

尝试在功能上下文中使用此隐式等待。根据我的经验,它有所帮助。

/**
 * @BeforeStep
 */
public function implicitlyWait($event)
{
    // Set up implicit timeouts
    $driver = $this->getSession()->getDriver()->getWebDriverSession();
    $driver->timeouts()->implicit_wait(array("ms" => 10000));
}