我试图在behat测试中模拟拖放UI行为.到目前为止,没有成功,尽管据说水貂支持这种互动.
奇怪的是,我很难找到关于这些主题的任何相关博客文章.我发现的这个(这和http://www.pix-art.be/post/testing-drag-and-drop-with-behat-and-guzzle )对我帮助不大.特别是后者.
有没有人对如何处理问题或有实际测试交互的经验有任何建议?
您可以在 ownCloud 测试代码中找到一个工作示例,它确实通过拖放将文件移动到文件夹中:
public function moveFileTo(
$name, $destination, Session $session, $maxRetries = STANDARD_RETRY_COUNT
) {
$toMoveFileRow = $this->findFileRowByName($name, $session);
$destinationFileRow = $this->findFileRowByName($destination, $session);
$this->initAjaxCounters($session);
$this->resetSumStartedAjaxRequests($session);
for ($retryCounter = 0; $retryCounter < $maxRetries; $retryCounter++) {
$toMoveFileRow->findFileLink()->dragTo(
$destinationFileRow->findFileLink()
);
$this->waitForAjaxCallsToStartAndFinish($session);
$countXHRRequests = $this->getSumStartedAjaxRequests($session);
if ($countXHRRequests === 0) {
\error_log("Error while moving file");
} else {
break;
}
}
if ($retryCounter > 0) {
$message
= "INFORMATION: retried to move file $retryCounter times";
echo $message;
\error_log($message);
}
}
Run Code Online (Sandbox Code Playgroud)
首先它找到NodeElement需要移动的文件,然后NodeElement找到目标并调用$fileToBeMovedElement->dragTo($destinationElement)
因为它被证明是不稳定的,所以dragTo函数周围有一个重试循环。为了测试拖放操作是否有效,代码检查是否启动了任何 AJAX 调用(在此特定应用程序中,此拖放操作启动了 WebDAV 请求)
| 归档时间: |
|
| 查看次数: |
488 次 |
| 最近记录: |