2013-09-26 40 views
3

我想知道是否有作爲它的運行是解析的動態值的可能方式,特別是name通過使用*.feature貝哈特/水貂測試進入帶有Selenium2功能的Yml配置文件通過水貂Extension.php(Selenium2),用於Saucelabs解析在貝哈特/水貂YML文件配置動態值

behat.yml文件在文件中使用帶有Selenium 2功能參數的Behat/Mink/Extension擴展文件。

default: 
     context: 
     class: 'FeatureContext' 
     extensions: 
     Behat\MinkExtension\Extension: 
     base_url: 
     javascript_session: 'selenium2' 
     goutte: 
     selenium2: 
      browser: firefox 
      wd_host: <sauce username>:<accesscode>@ondemand.saucelabs.com/wd/hub 
      capabilities: { "platform": "Windows 7" , "version": "21" , "name":"Test" } 

Extension.php filehttps://github.com/Behat/MinkExtension/blob/2.0/src/Behat/MinkExtension/Extension.php

  arrayNode('selenium2')-> 
       children()-> 
        scalarNode('browser')-> 
         defaultValue(isset($config['selenium2']['browser']) ? $config['selenium2']['browser'] : '%behat.mink.browser_name%')-> 
        end()-> 
        arrayNode('capabilities')-> 
         normalizeKeys(false)-> 
         children()-> 
          scalarNode('browserName')-> 
           defaultValue(isset($config['selenium2']['capabilities']['browserName']) ? $config['selenium2']['capabilities']['browserName'] : 'firefox')-> 
          end()-> 
          scalarNode('version')-> 
           defaultValue(isset($config['selenium2']['capabilities']['version']) ? $config['selenium2']['capabilities']['version'] : "9")-> 
          end()-> 
          scalarNode('platform')-> 
           defaultValue(isset($config['selenium2']['capabilities']['platform']) ? $config['selenium2']['capabilities']['platform'] : 'ANY')-> 
          end()-> 
          scalarNode('browserVersion')-> 
           defaultValue(isset($config['selenium2']['capabilities']['browserVersion']) ? $config['selenium2']['capabilities']['browserVersion'] : "9")-> 
          end()-> 
          scalarNode('browser')-> 
           defaultValue(isset($config['selenium2']['capabilities']['browser']) ? $config['selenium2']['capabilities']['browser'] : 'firefox')-> 
          end()-> 
          scalarNode('ignoreZoomSetting')-> 
           defaultValue(isset($config['selenium2']['capabilities']['ignoreZoomSetting']) ? $config['selenium2']['capabilities']['ignoreZoomSetting'] : 'false')-> 
          end()-> 
          scalarNode('name')-> 
           defaultValue(isset($config['selenium2']['capabilities']['name']) ? $config['selenium2']['capabilities']['name'] : 'Behat Test')-> 
          end()-> 
          scalarNode('deviceOrientation')-> 
           defaultValue(isset($config['selenium2']['capabilities']['deviceOrientation']) ? $config['selenium2']['capabilities']['deviceOrientation'] : 'portrait')-> 
          end()-> 
          scalarNode('deviceType')-> 
           defaultValue(isset($config['selenium2']['capabilities']['deviceType']) ? $config['selenium2']['capabilities']['deviceType'] : 'tablet')-> 
          end()-> 
          scalarNode('selenium-version')-> 
           defaultValue(isset($config['selenium2']['capabilities']['selenium-version']) ? $config['selenium2']['capabilities']['selenium-version'] : '2.31.0')-> 
          end()-> 
          scalarNode('max-duration')-> 
           defaultValue(isset($config['selenium2']['capabilities']['max-duration']) ? $config['selenium2']['capabilities']['max-duration'] : '300')-> 
          end()-> 
          booleanNode('javascriptEnabled')->end()-> 
          booleanNode('databaseEnabled')->end()-> 
          booleanNode('locationContextEnabled')->end()-> 
          booleanNode('applicationCacheEnabled')->end()-> 
          booleanNode('browserConnectionEnabled')->end()-> 
          booleanNode('webStorageEnabled')->end()-> 
          booleanNode('rotatable')->end()-> 
          booleanNode('acceptSslCerts')->end()-> 
          booleanNode('nativeEvents')->end()-> 
          booleanNode('passed')->end()-> 
          booleanNode('record-video')->end()-> 
          booleanNode('record-screenshots')->end()-> 
          booleanNode('capture-html')->end()-> 
          booleanNode('disable-popup-handler')->end()-> 
          arrayNode('proxy')-> 
           children()-> 
            scalarNode('proxyType')->end()-> 
            scalarNode('proxyAuthconfigUrl')->end()-> 
            scalarNode('ftpProxy')->end()-> 
            scalarNode('httpProxy')->end()-> 
            scalarNode('sslProxy')->end()-> 
           end()-> 
           validate()-> 
            ifTrue(function ($v) { 
             return empty($v); 
            })-> 
            thenUnset()-> 
           end()-> 
          end()-> 
          arrayNode('firefox')-> 
           children()-> 
            scalarNode('profile')-> 
             validate()-> 
             ifTrue(function ($v) { 
              return !file_exists($v); 
             })-> 
              thenInvalid('Cannot find profile zip file %s')-> 
             end()-> 
            end()-> 
            scalarNode('binary')->end()-> 
           end()-> 
          end()-> 
          arrayNode('chrome')-> 
           children()-> 
            arrayNode('switches')-> 
             prototype('scalar')->end()-> 
            end()-> 
            scalarNode('binary')->end()-> 
            arrayNode('extensions')-> 
             prototype('scalar')->end()-> 
            end()-> 
           end()-> 
          end()-> 
         end()-> 
        end()-> 
        scalarNode('wd_host')-> 
         defaultValue(isset($config['selenium2']['wd_host']) ? $config['selenium2']['wd_host'] : 'http://localhost:4444/wd/hub')-> 
        end()-> 
       end()-> 
      end()-> 
      arrayNode('saucelabs')-> 
       children()-> 
        scalarNode('username')-> 
         defaultValue(getenv('SAUCE_USERNAME'))-> 
        end()-> 
        scalarNode('access_key')-> 
         defaultValue(getenv('SAUCE_ACCESS_KEY'))-> 
        end()-> 
        booleanNode('connect')-> 
         defaultValue(isset($config['saucelabs']['connect']) ? 'true' === $config['saucelabs']['connect'] : false)-> 
        end()-> 
        scalarNode('browser')-> 
         defaultValue(isset($config['saucelabs']['browser']) ? $config['saucelabs']['browser'] : 'firefox')-> 
        end()-> 
        arrayNode('capabilities')-> 
         children()-> 
          scalarNode('name')-> 
           defaultValue(isset($config['saucelabs']['name']) ? $config['saucelabs']['name'] : 'Behat feature suite')-> 
          end()-> 
          scalarNode('platform')-> 
           defaultValue(isset($config['saucelabs']['platform']) ? $config['saucelabs']['platform'] : 'Linux')-> 
          end()-> 
          scalarNode('version')-> 
           defaultValue(isset($config['saucelabs']['version']) ? $config['saucelabs']['version'] : '21')-> 
          end()-> 
          scalarNode('deviceType')-> 
           defaultValue(isset($config['saucelabs']['deviceType']) ? $config['saucelabs']['deviceType'] : null)-> 
          end()-> 
          scalarNode('deviceOrientation')-> 
           defaultValue(isset($config['saucelabs']['deviceOrientation']) ? $config['saucelabs']['deviceOrientation'] : null)-> 

下的MinkExtension目錄Extension.php,它加載了selenium2.xml文件,一組陣列來解析該文件到behat.yml的信息。

我注意到,如果沒有從YML文件中指定的Selenium2能力的任何參數,則Extension.php將基於陣列名指定一個默認值:

scalarNode('name')-> defaultValue(isset($config['selenium2']['capabilities']['name']) ? $config['selenium2']['capabilities']['name'] : 'Behat Test')->

與此說,我想知道是否有任何可能的方法使用我的本地目錄中的Behat/Mink Feature測試<test>.feature的名稱在測試運行時解析name中的標題。

回答

3

晚的答案,但也許有總比沒有好......

如何在.feature測試中使用標籤?你可以建議貝哈特與給定的標籤只執行這些測試:

behat documentation - tags

如果要動態執行你的測試,你可以通過一個ant文件解析的,例如標籤:

<target name="test-behat"> 
    <exec dir="${basedir}" executable="bin/behat" failonerror="false"> 
     <arg line="--config ${basedir}/behat.yml --tags '${env.SELENIUM_TAG}'"/> 
    </exec> 
</target> 

這意味着在貝哈特-CLI:

bin/behat --tags '@your_tag' 

手工啓動螞蟻腳本:

ant -file <path to your ant-script> -D'SELENIUM_TAG'='@whatever_you_want' 

對於完全自動化,您可以啓動您的ant腳本(以及您的behat測試),例如通過jenkins(或任何其他可以處理apache螞蟻的CI)。 您也可以傳遞您的behat.yml,composer.json(如果您使用作曲家)等所需的任何參數。

如果你真的想要只執行一個.feature,你可以用同樣的方法。

<target name="test-behat"> 
    <exec dir="${basedir}" executable="bin/behat" failonerror="false"> 
     <arg line="--config ${basedir}/behat.yml '${env.FEATURE_FILE}'"/> 
    </exec> 
</target> 

這意味着在貝哈特-CLI:

bin/behat your.feature 

ant -file <path to your ant-script> -D'FEATURE_FILE'='your.feature' 

通訊線路從貝哈特--help啓動:

behat [--many config params we don't need right here] [features] 

Arguments: 
features   Feature(s) to run. Could be: 
        - a dir (features/) 
        - a feature (*.feature) 
        - a scenario at specific line (*.feature:10). 
        - all scenarios at or after a specific line (*.feature:10-*). 
        - all scenarios at a line within a specific range (*.feature:10-20)