【发布时间】:2015-05-01 17:00:54
【问题描述】:
我对 Codeception 比较陌生,我正在尝试使用它和 Selenium WebDriver 和 Firefox 对表单进行验收测试。该表单(可在http://www.brighton-hove.gov.uk/content/parking-and-travel/parking/find-your-parking-zone 获得)主要由一个文本框和一个自动填充的文本框组成,如果文本框的输入导致多个匹配,则会将其插入到 DOM 中;每个字段还有一个提交按钮。
我遇到的问题是,当在 Firefox 中正常测试时,它的行为符合预期,并且在初始文本搜索返回多个匹配项的情况下会自动填充(例如,输入任何布莱顿邮政编码,尽管特定情况是搜索“Brighton Town Hall, Bartholomew Square”,返回 3 个结果)。但是,当尝试通过 Codeception 进行测试时(运行完整的测试或通过控制台尝试每个步骤),它被插入到 DOM 中,但似乎从未填充真实结果(它包含的唯一元素是“请选择您的地址...')。
我的测试步骤如下:
$I->amOnUrl('http://www.brighton-hove.gov.uk/content/parking-and-travel/parking/find-your-parking-zone');
$I->fillField('Enter your postcode or house number and street','Brighton Town Hall, Bartholomew Square');
// XPath is used here as the form elements' 'id's, 'class'es and 'name's are auto-generated (the one above just happens to have a label).
$I->click("//div[@id='achieveform']/form/div/div/div[1]/div[1]/div/div[3]/div/input[@type='submit' and @value='Search'])";
// I've also tried using 'submitForm(...)' here, rather than just clicking the button.
// Wait an unnecessarily long amount of time in the hope that the dropdown appears and is also populated...
$I->waitForElement("//div[@id='achieveform']/form/div/div/div[1]/div[1]/div/div[7]/div/div[3]/div/div[1]/span/select", 5);
// The first option is there...
$I->seeElementInDOM("//div[@id='achieveform']/form/div/div/div[1]/div[1]/div/div[7]/div/div[3]/div/div[1]/span/select/option[1]");
// ...but it doesn't have 4 options, as expected.
$I->seeNumberOfElements("//div[@id='achieveform']/form/div/div/div[1]/div[1]/div/div[7]/div/div[3]/div/div[1]/span/select/option", 4);
虽然我希望执行的测试本质上是黑盒测试,但我的下一步行动是尝试跟踪表单提交和 DOM 更新,即使对系统底层结构的这种知识水平不应该是必要的。我忽略了一些简单的事情吗?任何指针将不胜感激。
【问题讨论】:
标签: html forms dom selenium-webdriver codeception