0

I have written automation test cases for my application.Below is the sample code i have used for web testing.

class UserWebTestcase extends CakeWebTestCase{

var $name='UserWebTestcase';

function testLogin001()
{
    //Test if new user registration form works as intended when all the inputs are given properly.
    $this->get(Configure::read('url'));
    $this->setField('email', 'admin45@gmail.com');
    $this->setField('tmppassword', 'admin123');
    $this->setField('password_confirm', 'admin123');
    $this->clickSubmit('SUBMIT');
    $this->assertText('login');
}

}

In test case it always gives false even though the inputs for fields are correct.The error i got like this (Failed C:\xampplite\htdocs\spotchase\app\tests\cases\models\user.test.php -> UserWebTestcase -> testLogin001). Im really confused while using the assertText() method.How should i use this assertText() method and what parameters should i pass to this method. Please help.

4

1 回答 1

0

这不是 cakephp 方法,而是最简单的方法。

下面是实际方法

   /**
     *    Will trigger a pass if the text is found in the plain
     *    text form of the page.
     *    @param string $text       Text to look for.
     *    @param string $message    Message to display.
     *    @return boolean           True if pass.
     *    @access public
     */
    function assertText($text, $message = '%s') {
        return $this->assert(
                new TextExpectation($text),
                $this->_browser->getContentAsText(),
                $message);
    }

所以看起来它只是在页面中寻找实际的文本,而不是按钮或其他元素。也许“欢迎鲍勃”会是一个更好的搜索

于 2011-06-16T13:03:22.543 回答