【问题标题】:Dynamically-populated <select> not populated during testing with Codeception在使用 Codeception 进行测试期间未填充动态填充的 <select>
【发布时间】: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


    【解决方案1】:

    抱歉,事实证明这毕竟与 Codecepetion 无关:问题部分与搜索表单背后的后端逻辑有关(它似乎不喜欢逗号),部分原因是我因为没有注意到在 Codeception 之外执行相同操作时,实际上也确实发生了带有空下拉菜单的行为。

    版主:这个帖子现在可以关闭/删除(因为这个问题在 Codeception 的上下文中不是问题)。

    【讨论】:

      【解决方案2】:

      似乎您没有在右侧字段或搜索框的文本输入字段中填写值:

      代替:

      $I->fillField('Enter your postcode or house number and street','Brighton Town Hall, Bartholomew Square');
      

      用途:

      $I->fillField('.dataelr input', "Your Value here");
      

      希望对你有帮助。

      【讨论】:

      • 您好 Anirudh,感谢您的回复。据我所见,下拉菜单出现的事实意味着文本框中有有效的输入,尽管不明确。此外,即使问题与文本框的引用有关,代码状态中的 cmets the form elements' 'id's, 'class'es and 'name's are auto-generated ([the field you're referencing] just happens to have a label [making it easier to reference]) 因此,通过 CSS ID 引用特定字段是不可重现的。
      • 好吧,我更新了答案以使用不使用 Is 的稳定 css 参考,但我不明白您为什么要尝试在标签中填充一个值,只有带有 标签的文本框或字段可以使用。
      • 来自codeception.com/docs/04-AcceptanceTests(“表单”部分;它似乎没有锚点),我的印象是可以有如下表单元素:&lt;label for="foo"&gt;Bar&lt;/label&gt; &lt;input name="foo" ... /&gt; 然后,在 Codeception 中:$I-&gt;fillField('Bar','CONTENT'); 为了完整起见,我尝试了您关于使用稳定的 CSS 参考的建议,并获得了预期的结果。重申一下,文本字段的引用不是问题,因为我发布的代码 sn-p 正确填写了该字段。
      • 澄清一下,我实际上要问的是,鉴于 出现/填充所需的时间长是不够的。我还简要地研究过使用类似waitForJS("return $.active == 0;", 10); 的东西,但似乎没有任何效果。
      猜你喜欢
      • 2013-08-02
      • 2012-10-10
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 2023-02-02
      • 2022-06-21
      相关资源
      最近更新 更多