Selenium 验证页面的日历视图显示当前月份和日期-behat测试自动化脚本
我是测试自动化的新手,目前我们正在使用behat+mink+selenium的组合来自动化测试。我想检查日历视图是否显示正确的月份和日期。这是我的小黄瓜剧本:Selenium 验证页面的日历视图显示当前月份和日期-behat测试自动化脚本,selenium,behat,mink,Selenium,Behat,Mink,我是测试自动化的新手,目前我们正在使用behat+mink+selenium的组合来自动化测试。我想检查日历视图是否显示正确的月份和日期。这是我的小黄瓜剧本: Feature: Users see the current date when the calendar view is clicked! @javascript Scenario: As a registered user, when I click on calendar, the page should display curr
Feature: Users see the current date when the calendar view is clicked!
@javascript
Scenario: As a registered user, when I click on calendar, the page should display current date (mm-dd)
Given I go to "URL"
When I fill in "username" with "username"
When I fill in "password" with "password"
Then I press "edit-submit"
Then I follow "calendar"
Then I should see "June 28"
这是我在FeatureContext.php文件中添加的内容:
public function getCurrentDate() {
return $this->currentDate()->format('Y-m-d');
}
protected function currentDate() {
return new Date();
}
由于此测试应该是自动化的,因此我希望将脚本中的最后一步更改为以下内容:
Then I should see "current date (mm-dd)"
我不确定这是否可能,但正如我之前所说,我对behat是新手,我不确定如何实现这样的功能。我正在用Behat搭配水貂和硒。
谢谢你的帮助 我找到了答案,想发布一个解决方案,以防将来有人需要它: 将其添加到FeatureContext.php文件中。 每个函数顶部的注释解释了它的功能 第一个功能:
// call currentDate() to fetch and format the date (month year)
public function getCurrentDate() {
return $this->currentdate = $this->currentDate()->format('F Y');
}
//month year date matcher does not take any arguments
/**
* Checks, that page contains specified text.
*
* @Then /^match current month year with page$/
*/
public function MonthYearDateMatcher()
{
$this->assertSession()->pageTextContains($this->fixStepArgument($this->getCurrentDate()));
}
第二个功能:
// Get current date time
protected function currentDate() {
return new DateTime();
}
第三项职能:
// call currentDate() to fetch and format the date (month year)
public function getCurrentDate() {
return $this->currentdate = $this->currentDate()->format('F Y');
}
//month year date matcher does not take any arguments
/**
* Checks, that page contains specified text.
*
* @Then /^match current month year with page$/
*/
public function MonthYearDateMatcher()
{
$this->assertSession()->pageTextContains($this->fixStepArgument($this->getCurrentDate()));
}