繁体   English   中英

带有 select 自动完成 ajax 字段的 Codeception 测试表

[英]Codeception testing form with select autocomplete ajax field

生产环境中的行为。

我有一个带有自动完成 select 框的表单,其初始表示为空:

<select name="customer"></select>

稍后,当我单击时,一个 ajax 请求会加载并填充选项的第一页(此时我不需要输入任何内容)。

然后,我可以选择一个选项并使用 ajax 提交表单。 实体已成功保存,我显示 flash 消息“项目已成功创建”。

在 Codeception 环境中测试行为:

我需要测试之前使用功能测试(Codeception)解释的行为

$I->amOnPage('/create');
$I->selectOption('select[name="customer"]', 1); //choose option with value = 1
$I->submitForm('form');
$I->canSee('Item has been successfully created.');

结果:

[InvalidArgumentException] 输入“客户”不能将“1”作为值(可能的值: )。

这当然行不通。 select 元素为空(无选项)。

所以此刻我的问题很明显,我该如何测试这个场景?

稍后我找到了问题的答案:

http://codeception.com/docs/modules/PhpBrowser#submitForm

对于字段( <select> )是动态填充(AJAX)的情况,只需省略$I->selectOption(...)语句,然后将值传递给$I->submitForm('form', [...]); 直接,所以:

$I->amOnPage('/create');
$I->submitForm('form', ['customer' => 1]);
$I->canSee('Item has been successfully created.');

够了,我的测试又恢复为绿色:)

I.fillField("#inputName", "first three letters for ex..");
const required = '#theIdOfRequiredSelectedElement'
I.click(required)

or the required may be the XPath of the item To get the XPath of the item you want to select the item by catch the item on the elements side of (inspect of the browser) then right click, choose copy then choose XPath

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM