My behat.yml looks like this:
default:
firefox:
context:
parameters:
Browser_Name: firefox
extensions:
Behat\MinkExtension\Extension:
base_url: https://google.com
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
I'm getting this exception:
[Symfony\Component\Yaml\Exception\ParseException] Indentation problem in "D:\\mypgms\\behat.yml" at line 7 (near " extensions:").
How can I resolve this issue?
The indentation of your YAML file is inconsistent.
Please see the YAML spec's chapter indentation spaces.
Either use 2 or 4 spaces indentation consistently across your YAML config file to resolve the issue.
example with 2-space indentation:
default:
extensions:
Behat\MinkExtension\Extension:
base_url: "https://base-url.com"
# ...
context:
parameters:
class: Your\Custom\Context
base_url: "https://context-base-url.com"
# ...
Related
Hi I would like to version my API. So I would like t prefix my roote with a version. like that?
# config/routes/annotations.yaml
controllers:
resource: ../../src/Controller/
type: annotation
prefix:
name: '{version}'
It works bit I would like to add a requirement to check the version.
Like:
requirements:
version: v1|v2
I don't find any documentation talking about that. Is there a good way to do it?
In the FOSRestBundle there is a complete chapter about versioning.
https://symfony.com/doc/master/bundles/FOSRestBundle/versioning.html
The FOSBundle has an option for versioning.
#app/config/config.yml
fos_rest:
versioning:
enabled: true
resolvers:
query: true # Query parameter: /users?version=v1
custom_header: true # X-Accept-Version header
media_type: # Accept header
enabled: true
regex: '/(v|version)=(?P<version>[0-9\.]+)/'
Trying to set behat tests for mobile devices in a Symfony2 Project.
I'm running selenium standalone server with chromedriver
This is my config file behat.yml
default:
suites:
default:
contexts:
- FeatureContext:
simpleArg: '%%kernel.environment%%'
session: '#session'
mink_session: default
mink_javascript_session: selenium_chrome_mobile_session
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://frontend.local
show_cmd: open -a Google\ Chrome %s
sessions:
default:
symfony2: ~
selenium2:
selenium2:
wd_host: http://127.0.0.1:4444/wd/hub
selenium_chrome_mobile_session:
selenium2:
browser: chrome
capabilities:
extra_capabilities:
chromeOptions:
mobileEmulation:
deviceName: "Google Nexus 5"
selenium_chrome_session:
selenium2:
browser: chrome
capabilities:
extra_capabilities:
chromeOptions:
args:
- "--start-maximized"
- "--test-type"
emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
name: html
renderer: Twig,Behat2
file_name: behat_report
print_args: true
print_outp: true
loop_break: true
formatters:
html:
output_path: %paths.base%/web
chrome_mobile:
extensions:
Behat\MinkExtension:
default_session: selenium_chrome_mobile_session
chrome:
extensions:
Behat\MinkExtension:
default_session: selenium_chrome_session
The website is adaptative (not responsive) and when I run the mobile features, the response is the one made for desktop browsers.
What I'm missing in my behat.yml?
For some reason running behat with profile doesn't work for chrome sessions
behat -p chrome_mobile -f pretty
Instead I added a tag with the session to execute. Like this:
Feature: This is my feature
#mink:selenium_chrome_session
Scenario: This is first scenario
When I am in homepage
It works now
I followed this blog as an example and read the ParallerRunner info. When I call bin/behat command, one browser window opens and runs all the tests successfully with the setting below.
symfony/behat.yml
default:
context:
class: Site\CommonBundle\Features\Context\FeatureContext
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://symfony.local/app_test.php/'
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
I modified the behay.yml (as shown below) to run some tests in one browser window and some in another window, however it doesn't do that. What it does is, it opens two browser windows but they both run same tests! How can I overcome this issue?
symfony/behat.yml
default:
context:
class: Site\CommonBundle\Features\Context\FeatureContext
parameters:
output_path: %behat.paths.base%/build/behat/output/
screen_shot_path: %behat.paths.base%/build/behat/screenshot/
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://symfony.local/app_test.php/'
files_path: %behat.paths.base%/build/dummy/
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
shvetsgroup\ParallelRunner\Extension:
process_count: 2
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
F1:
filters:
tags: "#backend"
F2:
filters:
tags: "#frontend"
BEHAT TESTS:
This should run in one window:
#frontend
Feature: User Login
#javascript
Scenario: I can login to the system
Given I am on "/login"
And I login as "user"
This should run in another window:
#backend
Feature: Admin Login
#javascript
Scenario: I can login to the system
Given I am on "/login"
And I login as "admin"
I setup parallel test execution with GNU Parallel and xargs.
Also implement consolidated report for all executed features.
Details in my article here:
http://parallelandvisualtestingwithbehat.blogspot.com/p/blog-page.html
find ./features -name "*.feature" |
parallel --gnu --halt-on-error=0 -j 3 --keep-order vendor/bin/behat -c src/my_directory/behat.yml
--halt-on-error possibilities are :
0 Do not halt if a job fails. Exit status will be the number of jobs
failed. This is the default.
1 Do not start new jobs if a job fails, but complete the running
jobs including cleanup. The exit status will be the exit status from
the last failing job.
2 Kill off all jobs immediately and exit without cleanup. The exit
status will be the exit status from the failing job.
-j 3 : Run 3 jobs in parallel
It work perfectly with selenium.
Here is what I would expect to work fine:
parameters.yml
host:
main: example.com
app/config/config.yml
twig:
globals:
hosts_main: %host.main%
But an exception is thrown:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "host.main".
And I cannot find any examples in docs.
Strange.
For example, Incenteev\ParameterHandler\ScriptHandler::buildParameters() replaces "flow" notation with mapping if there is one in .dist file and both structures are equal in terms of YAML but Symfony itself seems to not understand YAML.
Could anyone please suggest some adequate workaround.
The parametes key is missing and it should be flat:
parameters:
host.main: example.com
Or
parameters:
hosts:
main: example.com
other: example.com
twig:
globals:
hosts: "%hosts%"
I installed a Symfony2 extension for Behat Mink from here
When I run test, an error occurs
[ReflectionException] Class AppKernel does not exist.
What am I doing wrong?
behat.yml
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://localhost/behat
goutte: ~
selenium2: ~
Behat\Symfony2Extension\Extension: ~
First run these commands to install the dependencies:
composer require behat/behat
composer require behat/symfony2-extension
composer require behat/mink
composer require behat/mink-browserkit-driver
composer require behat/mink-extension
composer require behat/mink-goutte-driver
composer require behat/mink-selenium2-driver
composer require emuse/behat-html-formatter
composer require coduo/php-matcher
Now say your symfony applcation you want to host as localhost.behat, then add the vhost configuration to httpd_vhost.conf:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/behat/web"
ServerName lochost.behat
DirectoryIndex app_dev.php
<Directory "C:/xampp/htdocs/behat/web">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Now your behat.yml file should be at app/config/behat.yml with belo content :
default:
formatters:
html:
output_path: web/behat
extensions:
Behat\Symfony2Extension: ~
# Irs\BehatPopupExtension\Extension: ~
Behat\MinkExtension:
base_url: http://lochost.behat/app_dev.php/
javascript_session: selenium2
sessions:
symfony2:
symfony2: ~
selenium2:
selenium2:
browser: chrome
emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
name: html
renderer: Twig,Behat2
file_name: index
print_args: true
print_outp: true
loop_break: true
suites:
api:
type: symfony_bundle
bundle: NameSpaceYourBundle
#mink_session: symfony2
mink_session: selenium2
contexts:
- NameSpace\YourBundle\Features\Context\FeatureContext:
baseUrl: http://lochost.behat/app_dev.php/
screenCapturePath: web/behat
# Add "-p firefox" parameter to behat command to run tests with Firefox browser
firefox:
extensions:
Behat\MinkExtension\Extension:
browser_name: firefox
# Add "-p chrome" parameter to behat command to run tests with Chrome browser
chrome:
extensions:
#Behat\MinkExtension\Extension:
Behat\MinkExtension:
browser_name: chrome
# Add "-p safari" parameter to behat command to run tests with Safari browser
safari:
extensions:
Behat\MinkExtension\Extension:
browser_name: safari
All you go, now add your feature and context file at namespace : NameSpace\YourBundle\Features\Context\FeatureContext
and run the below commands from command prompt/git bash(preferrable):
bin/behat -v --suite=api #NameSpaceYourBundle/your.feature --config=app/config/behat.yml -f pretty
or if you want to save the output as html at web/behat directory then:
bin/behat -v --suite=api #NameSpaceYourBundle/your.feature --config=app/config/behat.yml
Let me know if it works
Note:
I am not sure if you are running selenium server or standalone server, hence adding the step to run selenium standalone server:
Download selenium and chromedriver and place the selenium server .exe and chromedriver.exe in same folder
check with "java -version" and it should not be < 1.6.x
you may need to download compatible selenium server and chrome driver
open command prompt and run the below commands:
cd C:\<folder contains selenium server .exe and chromedriver.exe>
java -Dwebdriver.chrome.driver="chromedriver.exe" -jar selenium-server-standalone-x.xx.0.jar