我想创建两个不同的Context文件 - FeatureContext.php和ModuleContext.php,并使用它们来运行behat测试(.feature文件)。
我不想要一个巨大的整体FeatureContext.php文件;所以我将这些功能分配到两个文件中。
在默认的FeatureContext.php中,我定义了一些自定义函数,如:
class FeatureContext extends MinkContext{
/**
* Wait for site to load
*
* @Then /I wait for the site to load$/
*/
public function iWait(){
$this->getSession()->wait();
}
}
在ModuleContext.php中,我想以这种方式调用方法:ClassName :: MethodName(例如:MinkContext :: fixStepArgument而不是$ this-> fixStepArgument)我已经定义了函数
class ModuleContext extends FeatureContext implements Context{
/**
* Plugin availability
*
* @Then /^"([^"]*)" plugin is available for "([^"]*)"$/
*/
public function pluginIs AvailableFor(){
$pluginActivationField = MinkContext::getSession->getPage->find('css selector')->getText()
}
}
在behat.yml中我已经在默认配置文件下定义了两个上下文 有3种不同的配置文件表示不同的测试环境。其中一个配置文件'prod'具有不同的admin密码,因此FeatureContext和WordPressContext部分在此配置文件下重复。
#behat.yml
default:
suites:
default:
contexts:
- FeatureContext:
parameters:
screen_shot_path: 'path to directory'
theme_url: ''
users:
admin:' admin password'
local:'local password'
- WordPressContext:
parameters:
screen_shot_path: 'path to directory'
theme_url: ''
users:
admin:' admin password'
local:'local password'
当我尝试运行测试(.feature文件)时,我收到以下错误:
步骤“/ ^我等待网站加载$ /”已在ModuleContext中定义:: iWaitForTheSiteToLoad()
FeatureContext :: iWaitForTheSiteToLoad() ModuleContext :: iWaitForTheSiteToLoad()
我正在使用PHPStorm。我该如何实现两种不同的上下文?
谢谢!