2017-03-19 6 views
0

私はsymfonyでbehatを使ってテストを行いましたが、動作していません。function ipst in behatは動作しません

これは私の機能である:

Feature: dossiertest 

@javascriptシナリオ:ディレクトリ内の一覧2つのファイル

Given I am on the homepage 
Then I should see "hello" 
When I go to "/ajoutermed" 
Then I should see "ajouter" 
And I wait 2 seconds 
And I fill in "test_medbundle_med_section" with "tes nom" 
And I fill in "test_medbundle_med_info" with "tes nom" 
And I press "Ajouter Med" 
Then I should see "ajouter" 

これはAjouterContext.phpです:

<?php 

namespace test\MedBundle\Behat\Context; 

use Behat\Behat\Context\Context; 
use Behat\Behat\Context\BehatContext; 
use Behat\Behat\Exception\PendingException; 
use Behat\Gherkin\Node\PyStringNode; 
use Behat\Gherkin\Node\TableNode; 
use Behat\MinkExtension\Context\MinkContext; 
use test\MedBundle\Entity\Apps; 
use test\MedBundle\Entity\Product; 

/** 
* Defines application features from the specific context. 
*/ 
class AjouterContext extends MinkContext 
{ 


    /** 
    * @When I press :arg1 
    */ 
    public function iPress($arg1) 
    { 
     self::$driver->findElement(WebDriverBy::cssSelector($arg1))->click(); 


      //$element = $page->find('css',"input[value='$arg1']"); 
    } 


    /** 
    * @Then I wait :arg1 seconds 
    */ 
    public function iWaitSeconds($arg1) 
    { 
     $this->getSession()->wait($arg1 * 1000); 
    } 


} 

behat.yml:

default: 
    suites: 
     default: 
      bundle: MedBundle 
      contexts: 
       - test\MedBundle\Behat\Context\FeatureContext 
       - test\MedBundle\Behat\Context\AjouterContext 
    extensions: 
     Behat\Symfony2Extension: ~ 
     Behat\MinkExtension: 
      base_url: http://localhost/test/web/app_dev.php 
      goutte: ~ 
      javascript_session: selenium2 
      selenium2: 
       wd_host: http://localhost:4444/wd/hub 
      sessions: 
       default: 
        symfony2: ~  

、これは私がテストをlaunche時に私の問題です:

enter image description here

は私を助けてくださいとあなたのエラーメッセージについて、あなた

+0

ページオブジェクトを使用し、必要な場合にいくつかのメソッドをオーバーライドして新しい共通オブジェクトを追加することができる 'Page'を拡張する基本ページオブジェクトを用意する必要があります。必要な複雑さを加えてデバッグするのが難しくなるようにする前に、適切な構造を持っていることを確認してください。ここをクリックしてくださいhttp://behat-page-object-extension.readthedocs.io/en/latest/guide/introduction.htmlこの機能を持つ – lauda

答えて

0

に感謝し、不明瞭「@When Iプレスがあります"アクション。あなたの機能を変更した場合

/** 
* @When I click on input :arg1 
*/ 
public function iClickOnInput($arg1) 
{ 
    self::$driver->findElement(WebDriverBy::cssSelector($arg1))->click(); 
    //$element = $page->find('css',"input[value='$arg1']"); 
} 

それは動作するはずです。

+0

:「Ajouter Med」という入力をクリックすると、この機能は/ ** * Iは、入力をクリックしてください@When:arg1に */ パブリック関数iClickOnInput($ ARG1) { 自己:: $ driver-> findElement(WebDriverBy :: cssSelector($ ARG1)) - >()をクリックします。// $ element = $ page-> find( 'css'、 "input [value = '$ arg1']"); } 私はこのエラーがあります: http:// imgur。COM/A/Swv89 –

+0

この機能付:/ ** *私は上をクリックし@When:arg1に */ パブリック関数iClickOn2($ ARG1) { \t $要素=の$ this - >のgetSession() - > GETPAGEを() - > findById($ arg1); \t \t if(null === $ element){var_dump( 'ID: "%s"'、$ arg1)の要素を評価できませんでした。 \t \t} $要素 - >()をクリックしてください;} 私はこのエラーを持っている:私はプレスを使用http://imgur.com/a/G1d5Fは ID「test_medbundle_med_submit」が入力に存在するAjouterメッドを提出するが、私はこのエラー –

+0

を持っています私はこの問題を抱えています:http://imgur.com/a/G1d5F –

0

ボタン要素であり、それは次のIDの一つとしてAjouter Medを持っている場合|名|タイトル| ALT |値、それはI press "Ajouter Med"

で動作するはずです、これはリンクであるなら、あなたはI follow "Ajouter Med"

を使用する必要があります

適切なメソッドを検索して、Behat/Gherkinステップの自動補完機能付きのIDEエディタとPHPメソッドを使用してみてください。

カスタムの基本メソッド/ステップを作成しないでください。これは、選択肢がない場合にのみ実行してください。同じことをしている2-3ステップで終了する可能性があります。

+0

Ajouter Medは入力の投稿です –

+0

次に、あなたが属性 'id | name | title | alt | value'。 – lauda

関連する問題