我正在用Behat和Selenium2测试我的UI。这是我的场景:
Scenario: Invite a Facebook friend
Given database is empty
Then I go to "/somewhere"
Given I follow "Invite a friend"
And I fill in "friends" with "Acme"
Then I wait for the suggestion box to appear
Then I select first suggestion
Then show last response
我有自动完成 (jquery-ui) 框。所有句子都按我预期工作并且是绿色的,但用户不是重定向
/**
* @Then /^I wait for the suggestion box to appear$/
*/
public function iWaitForTheSuggestionBoxToAppear()
{
$this->getSession()->wait(
1000,
"$('.ui-autocomplete').children().length > 0"
);
}
但是我加了第二句话
/**
* @Then /^I select first suggestion$/
*/
public function iSelectFirstSuggestion()
{
$this->getSession()->executeScript(
"$('.ui-autocomplete').children().children().click()"
);
}
硒控制台告诉我:
10:06:01.426 INFO - ... $('.ui-autocomplete').children().length > 0;, ...
10:06:01.439 INFO - ...
10:06:01.545 INFO - ... $('.ui-autocomplete').children().length > 0;...
10:06:01.559 INFO - ...
10:06:01.669 INFO - ... $('.ui-autocomplete').children().children().click(); ...
点击后,用户应重定向到/invite/url。
$("#friends").autocomplete({
minLength: 0,
source: projects,
select: function (event, ui) {
document.location.href = '/invite/' + ui.item.uid;
return false;
}
})
相反,此脚本并不总是有效。当硒打开浏览器时,如果我打开另一个窗口,测试将所有步骤返回为绿色。如果没有:如果我继续观看打开的窗口并保持焦点,...单击并重定向,他们不做他们的工作。
为什么?
经过一天的尝试,我得出的结论是,带有Firefox的selenium(以及在我的情况下带有WebDriver的phantomjs)无法从jquery自动完成中捕获所有必需的事件才能正常工作,因为数据输入没有完全模拟手动的使用。
归根结底,底线是只需通过javascript $('element')调用即可。 自动完成("搜索") 我确定显示 ui 自动完成项目
今天我已经阅读并尝试了有关它的所有内容:)
类似的事情:
-
与JavaScript Cucumber
-
与水豚2
-
含硒
-
与朱尼特