php - "When I fill the following fields"输入今天的日期?

标签 php selenium behat

behat 有没有办法让它在我填写字段时输入今天的日期?

一个例子

鉴于我填写了以下字段 |字段日期 |今天 |

我希望输出为 dd/mm/YYYY

我不明白为什么我找不到它,或者找到其他人以前做过这个?我找到了小 cucumber 和 cucumber 的答案,但没有找到 PHP 和 behat 的答案..

谢谢

最佳答案

我设法让它工作...将其添加到您的 FormContext 文件 -

/**
 * Fills in specified field with date
 * Example: When I fill in "field_ID" with date "now"
 * Example: When I fill in "field_ID" with date "-7 days"
 * Example: When I fill in "field_ID" with date "+7 days"
 * Example: When I fill in "field_ID" with date "-/+0 weeks"
 * Example: When I fill in "field_ID" with date "-/+0 years"
 *
 * @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with date "(?P<value>(?:[^"]|\\")*)"$/
 */
public function fillDateField($field, $value)
{
    $newDate = strtotime("$value");

    $dateToSet = date("d/m/Y", $newDate);
    $this->getSession()->getPage()->fillField($field, $dateToSet);
}

关于php - "When I fill the following fields"输入今天的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37998665/

相关文章:

php - 联系表格 7 设置字段值与获取请求

java - 使用 Selenium webdriver 从文件系统拖放文件

symfony - 在我的 Behat 场景中传递强制参数

symfony - 并行运行行为测试(在两个浏览器窗口中)

php - 将标签包裹在某些单词周围

php - 如何显示MySQL表中具有特定列值的所有行?

PHP/连接 Sphinx 需要用户名/密码

java - Selenium - 以编程方式将 html 转换为 junit

java - 如何处理 Selenium Webdriver 中由于服务器响应时间导致的脚本失败?

session-cookies - 如何重新启动浏览器以保留 Behat 中的 cookie?