由于ajax请求而导致功能测试不成功




public function testLoginLogout()

	{

		$this->open('');

		// ensure the user is logged out

		if($this->isTextPresent('Logout'))

			$this->clickAndWait('link=Logout');


		// test login process, including validation

		$this->clickAndWait('link=Login');

		$this->assertElementPresent('name=LoginForm[username]');

		$this->type('name=LoginForm[username]','demo');

		$this->clickAndWait("//input[@value='Login']");

		$this->assertTextPresent('Password cannot be blank.');

		$this->type('name=LoginForm[password]','demo');

		$this->clickAndWait("//input[@value='Login']");

		$this->assertTextNotPresent('Password cannot be blank.');

		$this->assertTextPresent('Logout');


		// test logout process

		$this->assertTextNotPresent('Login');

		$this->clickAndWait('link=Logout (demo)');

		$this->assertTextPresent('Login');

	}



上面这段代码是yii新建项目时候默认创建的功能测试代码,其中




$this->clickAndWait('link=Logout (demo)');



超时,原因是clickAndWait这个方法会等待被测试的页面reload,但是由于该页面使用了ajax提交数据,不会reload页面,所以导致功能测试总是超时。我在网上找了很多资料,知道可以使用waitForCondition这个方法解决ajax功能测试的问题,但是苦于不会用,找了很多种写法都不行,求一种可行的方法解决这个问题。

Mark一下。