Yii2 Codeception“seeLink”行为似乎不正确

时间:2016-07-14 03:54:11

标签: yii2 codeception

我正在使用Codeception版本2.0.16在Yii2中运行一些验收测试。我的单元测试和功能测试工作完美,但验收测试似乎显示出一个奇怪的结果。我定义了以下验收测试:

I->wantTo('test link discovery');
$I->seeElement(Locator::href('/index-test.php/user/create'));
$I->seeLink('Create User');

现在'href'和链接文本引用相同的链接。但是当我运行它时,我收到以下错误:

1) Failed to test link discovery in UserCept (/var/www/localhost/<mysite>/tests/codeception/acceptance/UserCept.php)
Couldn't see link "Create User": Element located either by name, CSS or XPath 'a' was not found on page.  
Scenario Steps:
12. I see link "Create User"
11. I see element "//a[@href=normalize-space('/index-test.php/user/create')]"

如您所见,Locator函数找到链接,但“seeLink”请求失败。这非常令人惊讶;这是返回的实际页面:(部分来自'_output'结果页面“UserCept.fail”) ...

<body>

<div class="wrap">
    <nav role="navigation" class="navbar navbar-fixed-top" id="w1"><div class="container"><div class="navbar-header"><button data-target="#w1-collapse" data-toggle="collapse" class="navbar-toggle" type="button"><span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span></button><a href="/index-test.php" class="navbar-brand">NGO Review</a></div><div class="collapse navbar-collapse" id="w1-collapse"><ul class="navbar-nav navbar-right nav" id="w2"><li><a href="/index-test.php/site/index">Home</a></li>
<li><a href="/index-test.php/site/about">About</a></li>
<li><a href="/index-test.php/site/contact">Contact</a></li>
<li><a href="/index-test.php/site/login">Login</a></li></ul></div></div></nav>
    <div class="container">
        <ul class="breadcrumb"><li><a href="/index-test.php">Home</a></li>
<li class="active">Users</li>
</ul>        <div class="user-index">

    <h1>Users</h1>

    <p>
        <a href="/index-test.php/user/create" class="btn btn-success">Create User</a>    </p>
    <div class="grid-view" id="w0"><div class="summary">Showing <b>1-2</b> of <b>2</b> items.</div>
<table class="table table-striped table-bordered"><thead>
<tr><th>#</th><th><a data-sort="username" href="/index-test.php/user/index?sort=username">E-Mail Address</a></th><th><a data-sort="first_name" href="/index-test.php/user/index?sort=first_name">First Name</a></th><th><a data-sort="last_name" href="/index-test.php/user/index?sort=last_name">Last Name</a></th><th><a data-sort="last_login_time" href="/index-test.php/user/index?sort=last_login_time">Last Login Time</a></th><th class="action-column"> </th></tr>
</thead>

...

(关键代码为 <a href="/index-test.php/user/create" class="btn btn-success">Create User</a> ) 显然我可以使用Locator语法来运行测试,但如果有人能解释为什么Locator功能正常工作,但是“seeLink”失败了,我会非常感激吗?感谢。

0 个答案:

没有答案