2014-09-10 2 views
0

FeatureContext.php 파일에서 screen_shots_path parameter에 액세스하고 싶지만 $this->getMinkParameter('screen_shots_path');을 작성하는 기능이 작동하지 않습니다.FeaturesContext 내에서 behat.yml 변수에 액세스

누구나 어떻게 해야할지 알고 계십니까?

미리 감사

에 나는 this one 확인하지만 클래스 extends BehatContext 및 광산 extends MinkContext 그래서 나는 그것을 내를 적용하는 방법에 혼란 giot.

스포츠/behat.yml

default: 
    context: 
     class: 'FeatureContext' 
    extensions: 
     Behat\Symfony2Extension\Extension: 
      mink_driver: true 
      kernel: 
       env: test 
       debug: true 
     Behat\MinkExtension\Extension: 
      base_url: 'http://localhost/local/sport/web/app_test.php/' 
      files_path: 'dummy/' 
      screen_shots_path: 'build/behat/' 
      browser_name: 'chrome' 
      goutte: ~ 
      selenium2: ~ 
    paths: 
     features: 'src/Football/TeamBundle/Features' 
     bootstrap: %behat.paths.features%/Context 

스포츠/SRC/축구/TeamBundle/기능/컨텍스트/FeatureContext.php 당신이로 태그 된 것을 알고

namespace Football\TeamBundle\Features\Context; 

use Behat\MinkExtension\Context\MinkContext; 
use Behat\Mink\Exception\UnsupportedDriverActionException; 
use Behat\Mink\Driver\Selenium2Driver; 

class FeatureContext extends MinkContext 
{ 
    /** 
    * Take screen-shot when step fails. 
    * Works only with Selenium2Driver. 
    * 
    * @AfterStep 
    * @param $event 
    * @throws \Behat\Mink\Exception\UnsupportedDriverActionException 
    */ 
    public function takeScreenshotAfterFailedStep($event) 
    { 
     if (4 === $event->getResult()) { 
      $driver = $this->getSession()->getDriver(); 

      if (! ($driver instanceof Selenium2Driver)) { 
       throw new UnsupportedDriverActionException(
        'Taking screen-shots is not supported by %s, use Selenium2Driver instead.', 
        $driver 
       ); 

       return; 
      } 

      #$directory = 'build/behat'; 
      $directory = $this->getMinkParameter('screen_shots_path'); 

      if (! is_dir($directory)) { 
       mkdir($directory, 0777, true); 
      } 

      $filename = sprintf(
       '%s_%s_%s.%s', 
       $this->getMinkParameter('browser_name'), 
       date('Y-m-d') . '_' . date('H:i:s'), 
       uniqid('', true), 
       'png' 
      ); 

      file_put_contents($directory . '/' . $filename, $driver->getScreenshot()); 
     } 
    } 
} 

답변

1

Symfony 질문에 영향을주는 부분이있을 수 있지만 코드에서는 그렇지 않은 것 같습니다. 문제는 아마도 다음과 같습니다.

2.x가 아닌 Mink Extension 1.x를 사용한다고 가정하면, screen_shots_path 매개 변수는 지원되는 매개 변수 목록에 없습니다. 사실 2.x는 그 중 하나를 지원하지 않지만 config에서 잘못된 것을 발견하면 즉시 예외를 throw합니다. 아마도 1.x는 그렇게하지 않습니다. 지원되는 매개 변수 here을 볼 수 있습니다.

가장 일반적인 이유는 screen_shots_path은 구성이 정규화 될 때 무시되고 따라서 getMinkParameter('screen_shots_path')은 아무 것도 반환하지 않습니다. files_path을 입력 해보십시오. dummy/이 표시됩니다.

behat.yml에 구성을 유지하려면 상황을 직접 문맥에 전달하는 것이 가장 좋습니다 (documentation 참조).

# behat.yml 
default: 
    context: 
     class: FeatureContext 
     parameters: 
      screen_shots_path: 'build/behat/' 

로컬 매개 변수를 초기화 할 수있는 생성자로 전달됩니다. 또는 정적 매개 변수를 사용하여 다른 컨텍스트를 통해 액세스 할 수 있습니다.

class FeatureContext extends MinkContext 
{ 
    protected $screenShotsPath; 

    public function __construct($parameters) 
    { 
     $this->screenShotsPath = isset($parameters['screen_shots_path']) ? $parameters['screen_shots_path'] : 'some/default/path'; 
    } 

    public function takeScreenshotAfterFailedStep($event) 
    { 
     $directory = $this->screenShotsPath; 
    } 
} 
+0

집에 돌아 왔을 때 사용해 볼 것이지만, 필자의 FeatureContext에서해야 할 일은 무엇인가? :'public function __construct (array $ parameters) {$ this- directory = $ this-> getMinkParameter ('screen_shots_path'); }' – BentCoder

+0

거의. 업데이트 된 부분을 참조하십시오. –

+0

멋진. 오늘 밤 확인하고 알려 드리겠습니다. 고마워. – BentCoder