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
Related
I have developed an application in Symfony 4. The application works perfectly in localhost, with the command php -S 127.0.0.1:8000 -t public I see the application in localhost: 8000, but if I access localhost / nameproject / public I have a page white. I ran the commands composer install --no - dev --optimize - autoloader, export APP_ENV = prod, php bin / console cache: clear --env = prod --no - debug and composer require symfony / apache - pack. Can someone help me?
I found the error, with php -v I return the 7.1.14 version, but with phpinfo () I found that I have in the php php version 5.6! I hope my experience can be useful to someone!
I'm using LopiPusherBundle for Getting following error while clearing the cache in symfony 2.7.26
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "scheme, cluster, url" under "lopi_pusher"
# app/config/config.yml
lopi_pusher:
scheme: http
host: api.pusherapp.com
port: 80
cluster: ap2
timeout: 30
debug: false
app_id: <app_id>
key: <key>
secret: <secret>
url: <scheme>://<key>:<secret>#<host>[:<port>]/apps/<app-id>
auth_service_id: my_channel_authenticator
Your installed version is smaller than 1.3 and these options are not available.
You can see this here https://github.com/laupiFrpar/LopiPusherBundle/blob/1.2.9/DependencyInjection/Configuration.php
Check your composer.json and make sure the correct version is there
You can just use
"laupifrpar/pusher-bundle": "*"
Dont forget to update your dependency after modifying composer.json using
composer update "laupifrpar/pusher-bundle"
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
Attempts to use a sqlite file database in the app/cache/tests directory fail. This is determined by clearing the dev MySQl database and populating the test environment database via the console. Test database being populated was confirmed by an external Sqlite Manager. [Tests performed without the sqlite configuration pass.]
codeception.yml:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
- Db:
dsn: 'sqlite:./app/cache/test/test.sqlite'
user: ''
password: ''
dump: tests/_data/test.sql
populate: true
cleanup: false
reconnect: true
Edit:
In an Ubuntu VM, adding the Symfony2 configuration to acceptance.yml allows for partial success - the test uses the Sqlite db but does not rewrite from the specified dump (test.sql). In Windows adding the Symfony configuration makes no difference.
acceptance.yml:
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://vol
- \Helper\Acceptance
# adding these lines enables Ubuntu to use sqlite db
- Symfony2:
app_path: ./app
environment: test
You haven't enabled Db module in acceptance.yml
modules:
enabled:
- Db
- PhpBrowser:
url: http://vol
- \Helper\Acceptance
Also don't add PhpBrowser and Symfony2 at the same time,
only one can be used.
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.