使用click进行重定向时,代码测试随机失败

时间:2016-07-01 09:24:47

标签: codeception

我遇到了代码测试失败的奇怪问题。

有时,链接/按钮上使用的点击方法不会重定向到页面。 有时它确实如此,但代码选择无法识别它(我在输出中看到重定向工作的图像)。 有时它完全没问题,测试运行率为100%。

我在jenkins上使用带有phantomjs 2.1.1的codeception 2.2.1版本。

有问题的测试之一:

$I->wantTo('verify that recent comments module are correctly presented');
$I->amOnPage('/pl/');
$I->click('.cookie-policy-info__btn-close');
$I->see('Najciekawsze opinie', '.section-title-bar');
$I->seeElement('.hp-recent-opinions.one-column-product-wrapper');
$I->seeElement('ul.slides:nth-child(1) > li > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-
$I->click('ul.slides:nth-child(1) > li > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child
$I->seeInCurrentUrl('/audiobook/');
$I->moveBack(1);
$I->click('ul.slides:nth-child(1) > li > div.product-tile > div.product-tile__desc > div.product-tile__author
$I->seeInCurrentUrl('/search/author?');
$I->moveBack(1);

$this->titleCss() = 'ul.slides:nth-child(1) > li > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)'

的示例

和代码输出:

5) ContentModulesCest: Verify that recent comments module are correctly presented
Test  tests/acceptance/ContentModulesCest.php:recentCommentsModule
Step  See in current url "/foobar/"
Fail  Failed asserting that '/pl/' contains "/foobar/".

Scenario Steps:

8. $I->seeInCurrentUrl("/foobar/")
7. $I->click("ul.slides:nth-child(1) > li > div:n...")
6. $I->seeElement("ul.slides:nth-child(1) > li > div:n...")
5. $I->seeElement(".hp-recent-opinions.one-column-prod...")
4. $I->see("Najciekawsze opinie",".section-title-bar")

在图像上,我看到了该页面。有点奇怪。 任何想法如何阻止随机失败?

1 个答案:

答案 0 :(得分:2)

当Codeception尝试单击时,该元素可能不可见(尚未加载)。尝试在click方法之前使用waitForElementVisible方法。

它也可以与PhantomJS版本连接。我有很多奇怪的问题 - 一切皆有可能。

相关问题