2016-06-28 7 views
0

私はBehatによって私のLaravelアプリケーションをテストしようとしています。 名前、メール、「登録」ボタンのフィールドがあるホームページがあります。私はbehat試験でボタンを押ししようとしているが、私はエラーが致命的なエラーを持っている:Behat Laravelがサブミットを見つけることができません

:(Behat \ Testwork \コール\例外の\ FatalThrowableError)

マイHTMLヌルのメンバ関数を押して()の呼び出し

<html> 
 
    <head> 
 
    </head> 
 
    <title>Registration</title> 
 
    <body> 
 
     <form action="/thanks" name="register"> 
 
      <p align="center"><font size="4"><b>Please, enter your name and e-mail</b></font></p> 
 
      <p align="center"><input name="name" type="text" value="name"></p> 
 
      <p align="center"><input name="email" type="text" value="e-mail"></p> 
 
      <p align="center"><input name="registerButton" type="submit" value="Register"></p> 
 
      <p>&nbsp;</p> 
 
     </form> 
 
    </body> 
 
</html>

マイFeatureContext機能:

/** 
* @When I press the :submit 
*/ 

public function iPressTheSubmit($submit) { 
    $element=$this->getSession()->getPage()->findButton($submit);  
    $element->click(); 
} 

シナリオ:

Scenario: Register Test 
Given I am on the homepage 
When I press the "registerButton" 
Then I should be on "/thanks" 

出力:

Scenario: Register Test # features/regpage.feature:4 Given I am on the homepage # FeatureContext::iAmOnHomepage() When I press the "registerButton" submit # FeatureContext::iPressTheSubmit() Fatal error: Call to a member function press() on null (Behat\Testwork\Call\Exception\FatalThrowableError) Then I should be on "/thanks" # FeatureContext::assertPageAddress() --- Failed scenarios: features/regpage.feature:4 1 scenario (1 failed) 3 steps (1 passed, 1 failed, 1 skipped)

behat.yml: default: extensions: Laracasts\Behat: # env_path: .env.behat Behat\MinkExtension: default_session: laravel base_url: localhost:8000 laravel: ~

+0

致命的なエラー要素が見つからなかったためでありますfindButtonはnullを返し、nullを押すことを試みています。要素が見つからない場合は、例外をスローする要素を待機するために待機条件を使用します。 $ this-> getSession() - > getPage() - > pressButton( 'yourButton');を試してみましたか? ? – lauda

答えて

1

私は2つのステップでそれを固定:FeatureContentは、このようなファイルの修正.envと.env.behatファイル 2の 1.設定APP_KEYパラメータ:

/** 
* @When I press the :arg1 
*/ 
public function iPressThe($arg1) 
{ 
    $element=$this->getSession()->getPage()->find('named', array('id_or_name', $arg1)); 
    $element->press(); 
} 
0

カスタムFeatureContext法上のPHPのdocblockを解析Behatないのですか?

@When I press the :submitは、Behatが使用することができないjQueryセレクタ構文を使用しているようです。同様の例をベースのFeatureContextクラスで見てください。

+0

標準の動作構文http://docs.behat.org/en/v3.0/guides/4.contexts.html – Olga

関連する問題