检查我是否留在同一页面

时间:2014-04-22 13:05:26

标签: php behat mink

我使用mink测试网站,我想编写一个测试场景来检查错误情况。所以我想看看如果我插入无效数据页面应该返回错误,我应该在以前的同一页面。我的意思是我不想去另一页。 为此我写了一个如下测试场景:

some steps ....
And Save current page
some other steps....
Then I should stay in the same page

我写给像下面这样的方法的两个步骤:

/**
 * @Given /^Save current page$/
 */
public function SaveCurrentPage() {
    $this->_last_page = $this->getSession ()->getCurrentUrl ();
}

/**
 * @Given /^I should stay in the same page$/
 */
public function StayInSamePage() {
    if ($this->_last_page === null) {
        throw new FailureException ( "current page is not defined" );
        // throw new Exception ( "current page is not defined" );
    }
    if ($this->_last_page !== $this->getSession ()->getCurrentUrl ()) {

        throw new FailureException ( "you should be in " . $this->_last_page . " but you are in  " . $this->getSession ()->getCurrentUrl () );
        // throw new Exception ( "you should be in " . $this->_last_page . " but you are in " . $this->getSession ()->getCurrentUrl () );
    } else {
        return;
    }
}


但我真的不喜欢我的解决方案。由于保存当前页面的行与应用程序的行为无关,仅用于貂皮,我认为不是behat / mink的目标。 有没有更好的解决方案?
提前谢谢

0 个答案:

没有答案