Behat 在 JavaScript 上失败了,但没有成功

behat fails with javascript but succeeds without

本文关键字:成功 JavaScript 失败 Behat      更新时间:2023-09-26

我正在使用Behat/Mink为我的php应用程序编写验收测试,发现了一件奇怪的事情:当javascript打开时,Behat找不到输入字段,而在javascript关闭时它找到相同的字段。

确切地说:以下场景

Scenario: adding article keywords, no javascript used
 Given I am on "articles/create"
 When I fill in "Articles[title]" with "About all properties"
...

完美地通过。但是一旦我将标签 javascript 添加到上述场景中

@javascript    
Scenario: adding article keywords
 Given I am on "articles/create"
 When I fill in "Articles[title]" with "About all properties"

它开始失败:

When I fill in "Articles[title]" with "About all properties"
# FeatureContext::fillField()
Form field with id|name|label|value "Articles[title]" not found.

可能是什么原因?

@javascript将使用Selenium驱动程序运行您的功能,Selenium可能需要一些时间来加载页面,您可以尝试添加步骤"我等待......"就在"我在..."之后。希望这只是 DOM 需要时间来加载。

@javascript    
Scenario: adding article keywords
 Given I am on "articles/create"
 Then I wait 1000
 When I fill in "Articles[title]" with "About all properties"