gpt4 book ai didi

php - 通过 Saucelabs 的 Mink Extension.php(Selenium2) 解析 Behat/Mink Yml 文件配置中的动态值

转载 作者:搜寻专家 更新时间:2023-10-31 20:42:26 25 4
gpt4 key购买 nike

我想知道是否有可能解析动态值的方法,特别是 name通过使用 *.feature Behat/Mink 在使用 Selenium2 功能运行到 Yml 配置文件时进行测试

behat.yml文件使用 Behat/Mink/Extension文件中包含 Selenium 2 Capabilities 参数的扩展文件。

    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 file内: https://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)->

Extension.php在 MinkExtension 目录中,它加载了 selenium2.xml包含一组数组的文件,以将该文件中的信息解析到 behat.yml .

我注意到如果 yml 文件中没有指定 Selenium2 功能的任何参数,Extension.php将根据数组名称分配一个默认值:


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

话虽如此,我想知道是否有任何可能的方法来使用 Behat/Mink 功能测试的名称 <test>.feature在我的本地目录中解析 name 中的标题在测试运行时。

最佳答案

迟到的答案,但总比没有好...

如何在您的 .feature 测试中使用标签?您可以建议 behat 只执行那些带有给定标签的测试:

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>

这意味着在 behat-c​​li 中:

bin/behat --tags '@your_tag'

手动启动你的 ant 脚本:

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

对于完全自动化,您可以启动您的 ant 脚本(和您的 behat 测试),例如通过 jenkins(或任何其他可以处理 apache ant 的 CI)。您还可以传递 behat.yml、composer.json(如果您使用 composer)等所需的任何参数。

如果您真的只想执行一个 .feature,您可以采用相同的方式。

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

这意味着在 behat-c​​li 中:

bin/behat your.feature

开始于

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

来自 behat --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)

关于php - 通过 Saucelabs 的 Mink Extension.php(Selenium2) 解析 Behat/Mink Yml 文件配置中的动态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19034632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com