如何让WebGuy-> fillField在Codeception验收测试中工作?

时间:2014-01-13 15:00:39

标签: codeception acceptance

我希望有人可以帮助我,因为我真的正准备在这张桌子上停下来: - (

我正在尝试让fillFIeld工作,但我似乎无法让它垮掉。

seeInField在同一个表单字段上工作,所以我认为我的定位等都很好。

我甚至写了一个非常基本的测试来尝试一切规则。

HTML ...

<!DOCTYPE html>
<html>
<body>
    <form id="SearchForm" action="" method="get">
        <input type="text" name="search" value="abc" />
        <button type="submit">Search</button>
    </form>  
</body>
</html>

测试......

//INSTANTIATE WEB GUY
$I = new WebGuy($scenario);

//DEFINE TEST
$I->wantTo('search from home');

//GET ON THE HOME PAGE
$I->amOnPage('/'); 
$I->seeInField('search', 'abc');
$I->fillField('search', 'def');
$I->seeInField('search', 'def');

输出......

Acceptance Tests (1) ---------------------------------------------------------------------------------------
Modules: PhpBrowser, WebHelper
------------------------------------------------------------------------------------------------------------
Trying to search from home (Search_From_Home_Page_Cept.php)       
Scenario:
* I am on page "/__staging/"
* I see in field "search","abc"
* I fill field "search","def"
* I see in field "search","def"
FAIL

------------------------------------------------------------------------------------------------------------

Time: 25 ms, Memory: 12.25Mb

There was 1 failure:

---------
1) Failed to search from home in Search_From_Home_Page_Cept.php
Sorry, I couldn't see in field "search","def":
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'def'
+'abc'

Scenario Steps:
4. I see in field "search","def"
3. I fill field "search","def"
2. I see in field "search","abc"
1. I am on page "/__staging/"

FAILURES!
Tests: 1, Assertions: 2, Failures: 1.

我显然遗漏了一些非常明显的东西,但是花了几个小时拖网论坛而没有找到解决它的任何东西我需要帮助!

2 个答案:

答案 0 :(得分:1)

使用属性选择器按名称属性选择输入元素:

$I->fillField('input[name=search]', 'def');

答案 1 :(得分:0)

将ID分配给该字段。

<input type="text" id="search_input" name="search" value="abc" />


$I->seeInField('#search_input', 'abc');
$I->fillField('#search_input', 'def');
$I->seeInField('#search_input', 'def');

我希望这项工作。