2015-11-24 21 views
1

我在寫一個表單的驗收測試。測試檢查一個複選框,測試複選框是否被選中並取消選中。Codeception uncheckOption()不起作用

所以我必須在我看來,下面的代碼片段:

<form> 
    <div class="checkbox"> 
    <label for="agree"></label> 
    <input type="checkbox" id="agree" name="agree">Agree to the conditions! 
    </div> 
</form> 

,在我的驗收測試我做的:

/* works */ 
$I->seeElement('#agree'); 
$I->dontSeeCheckboxIsChecked('#agree'); 
$I->checkOption('#agree'); 
$I->seeCheckboxIsChecked('#agree'); 
/* This does not work?*/ 
$I->uncheckOption('#agree'); 
$I->cantSeeCheckboxIsChecked('#agree'); 

我使用的PhpBrowser驅動程序,因爲我不能讓WebDriver司機在公司防火牆後面工作。

雖然seeElementseeCheckboxIsChecked確認複選框存在並被選中,但以下uncheckOption不成功。從測試

輸出是:

2) Failed to check checkbox in WelcomeCept (tests\functional\\WelcomeCept.php) 

Step I can dont see checkbox is checked "#agree" 
Fail Failed asserting that 1 matches expected 0. 

Scenario Steps: 

    11. $I->canDontSeeCheckboxIsChecked("#agree") at tests\functional\WelcomeCept.php:18 
    10. $I->uncheckOption("#agree") at tests\functional\WelcomeCept.php:17 
    9. $I->seeCheckboxIsChecked("#agree") at tests\functional\WelcomeCept.php:15 
    8. $I->checkOption("#agree") at tests\functional\WelcomeCept.php:14 
    7. $I->dontSeeCheckboxIsChecked("#agree") at tests\functional\WelcomeCept.php:13 
    6. $I->seeElement("#agree") at tests\functional\WelcomeCept.php:12 

僅供參考我使用的是爾康框架及其伏模板引擎和網頁能正常運行在瀏覽器中。

任何幫助表示讚賞。

回答

1

uncheckOptions的作品,問題是CheckboxIsChecked斷言檢查頁面的來源,而不是測試設置的表單值。

https://github.com/Codeception/Codeception/issues/2355#issuecomment-139166355

的$ I-> dontSeeCheckboxIsChecked()方法執行鍼對 XPath查詢生成的HTML和查找您指定的輸入 元素所檢查的屬性。

+0

謝謝。我終於得到了Webdriver模塊的工作(必須取消設置代理環境變量),現在可以進行這種測試。 – dev0