を有効にすることが、私はBehatを使用してスクリーンショットを撮る達成したいことができなかった、ミンクやSeleniumGridBehat3 MinkExtensionが
しかし、私はこのエラーを取得:
は、私が に行く考える「mySite.org/private "# FeatureContext :: visit() MinkインスタンスがMinkコンテキストクラスに設定されていません。 Mink Extensionを有効にしましたか? (RuntimeException) │ ⇒MinkインスタンスがMinkコンテキストクラスに設定されていません。 Mink Extensionを有効にしましたか? (のRuntimeException) │└─@AfterStepの#偉業
マイbehat.yml:
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://integration.fvs.dev.intern.etecture.de/private-clients
browser_name: 'firefox'
selenium2:
wd_host: http://hub.selenium.intern.etecture.de:4444/wd/hub
capabilities: { "browser": "firefox", "version": "14"}
goutte: ~
sessions:
goutte:
goutte: ~
selenium2:
selenium2: ~
symfony2:
symfony2: ~
suites:
backend:
type: symfony_bundle
mink_session: selenium2
contexts:
- app\features\bootstrap\FeatureContext:
screen_shot_path: app/screenshot
私FeatureContext.php
class FeatureContext extends MinkContext
{
private $screenShotPath;
public function __construct()
{
$this->screenShotPath = "/app/screenshot";
}
/**
* Take screen-shot when step fails. Works only with Selenium2Driver.
*
* @AfterStep
* @param AfterStepScope $scope
*/
public function takeScreenshotAfterFailedStep(AfterStepScope $scope)
{
if (99 === $scope->getTestResult()->getResultCode()) {
$driver = $this->getSession()->getDriver();
if (! $driver instanceof Selenium2Driver) {
return;
}
if (! is_dir($this->screenShotPath)) {
mkdir($this->screenShotPath, 0777, true);
}
$filename = sprintf(
'%s_%s_%s.%s',
$this->getMinkParameter('browser_name'),
date('Ymd') . '-' . date('His'),
uniqid('', true),
'png'
);
$this->saveScreenshot($filename, $this->screenShotPath);
}
}
/**
* @Then /^I should see the css selector "([^"]*)"$/
* @Then /^I should see the CSS selector "([^"]*)"$/
*/
public function iShouldSeeTheCssSelector($css_selector) {
$element = $this->getSession()->getPage()->find("css", $css_selector);
if (empty($element)) {
throw new \Exception(sprintf("The page '%s' does not contain the css selector '%s'", $this->getSession()->getCurrentUrl(), $css_selector));
}
}
/**
* @Then /^I should not see the css selector "([^"]*)"$/
* @Then /^I should not see the CSS selector "([^"]*)"$/
*/
public function iShouldNotSeeAElementWithCssSelector($css_selector) {
$element = $this->getSession()->getPage()->find("css", $css_selector);
if (empty($element)) {
throw new \Exception(sprintf("The page '%s' contains the css selector '%s'", $this->getSession()->getCurrentUrl(), $css_selector));
}
}
}
は誰のアイデアを持って? Thx
ありがとうございました。 私はこの問題を解決しました。それは多くの問題でした。私のプロジェクトセットアップが正しくありませんでした。 私は要塞を持っています。 私が言うとき: browser_name: "firefox" ==> Selenium2-Serverはfirefox Browserを使用します。 しかし、 "browser": "chrome"といくつかのバージョンで機能を設定すると、Selenium2-ServerはまだFirefoxを使用します。 能力の使用はどうですか? –
良い質問ですが、私は能力の面で大きな専門家ではありません。しかし、私が知っているように、この引数( 'browser'、' version')はセレンドライバに渡されるべきです。しかし、 'browser_name'は' browser'よりも大きなパワーを持っています。つまり、 'browser_name'が' browser'よりも空でなければ無視されます。ここに 'browser_name'パラメータを' browser'とする[Selenium2Factory](https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/ServiceContainer/Driver/Selenium2Factory.php#L41)があります。 –
hhmm ..... "browser_name: 'chrome'"が見つからない場合、デフォルトでSelenium2-Serverがfirefox-browserを使用すると読んでいます。私が言うとき : "BROWSER_NAME: 'Firefoxの'" とwihtin機能:{ "ブラウザ": "クローム"} (または反転)を、Selenium2-Serverは、まだ取るのfirefox ^^ いずれかの機能が役に立たないか、その何かあります間違って.... –