I want to use behat to example test and I used Mink and Selenium to test javascript. I have a a element in html file and when I click on the link then JQuery add to DOM new element. I want to test this case.
composer.json
{
"require": {
"behat/behat": "^3.1",
"bossa/phpspec2-expect": "^1.0",
"behat/mink-extension": "^2.2",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
"behat/mink-browserkit-driver": "^1.3",
"behat/mink": "^1.7"
}
}
behat.yml
default:
extensions:
Behat\MinkExtension:
goutte: ~
browser_name: firefox
selenium2:
wd_host: http://0.0.0.1:4444/wd/hub
example.feature
Feature: example
Scenario: Test javascript for
Given I am on "http://www.example.com/"
When I follow "clickButton" #a has id clickButton
Then I should see "Works!"
Behat throw error in Then I should see "Works!" step and it is fine, because this element not exists on body.
But when add #javascript annotation
#javascript
Feature: example
Scenario: Test javascript for
Given I am on "http://www.example.com/"
When I follow "clickButton"
Then I should see "Works!"
Behat throw exception:
When I follow "clickButton" # FeatureContext::clickLink()
Link with id|title|alt|text "clickButton" not found. (Behat\Mink\Exception\ElementNotFoundException)
What's wrong? I have Selenium on server.
Related
I try to run behat tests in a Laravel project.
When I run bin/php vendor/bin/behat:
I have this error:
In GoutteFactory.php line 117:
Method Goutte\Client::setClient() does not exist
My composer.json:
"require": {
"php": "^8.0.2",
[...]
"behat/mink": "^1.9",
"dmore/behat-chrome-extension": "^1.4",
"behat/mink-goutte-driver": "^2.0",
"dmore/chrome-mink-driver": "^2.8"
},
"require-dev": {
"behat/behat": "^3.10",
"friends-of-behat/mink-extension": "^2.6",
[...]
}
}
My behat.yml:
default:
extensions:
Behat\MinkExtension:
goutte: ~
Myfeature is a very simplest tests. It only uses rules provided by Mink, like "Given I am on "/".
My FeatureContext.php
use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\MinkContext;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext implements Context
{
}
When I call bin/behat to execute my tests, I get this error:
test.dev bin/behat
[Zend_Db_Adapter_Exception]
SQLSTATE[HY000] [2002] No such file or directory
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
This is my composer.json:
{
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"magetest/magento-behat-extension": "dev-develop",
"magetest/magento-phpspec-extension": "~2.0",
"peridot-php/webdriver-manager": "dev-master",
"bossa/phpspec2-expect": "dev-master",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-selenium-driver": "*"
},
"autoload": {
"psr-0": {
"": [
"html/app",
"html/app/code/community",
"html/app/code/core",
"html/lib"
],
"Mage" : "html/app/code/core"
}
},
"config": {
"bin-dir": "bin"
}
}
And this is my behat.yml:
default:
paths:
features: features
bootstrap: features/bootstrap
extensions:
MageTest\MagentoExtension\Extension: ~
Behat\MinkExtension\Extension:
base_url: http://test.dev
goutte: ~
selenium2: ~
default_session: selenium2
It's a patchwork of several tutorials while every of them threw the same error. My Magento installation is in html under project. Only thing that differs to all tutorials is, that I have no html/app/code/local folder.
Composer install and behat --init run without errors.
Edit:
I'm working with MAMP Pro, so I found this issue. But linking the socket file to /tmp did not fix my problem.
Since I use MAMP, I have to configure it for CLI as well:
export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH
Now CLI uses my MAMP PHP version and everything runs well.
I've configured SonataUserBundle together with SonataAdminBundle. I now have access to URLs like /login, /register, /profile. This is how the login page looks like. Other pages also do not have any styles loaded.
Does Sonata provide any default styles for these pages. I though that maybe I have a problem with dependency version. This is 'Sonata' fragment of my composer.json:
"sonata-project/admin-bundle": "~2.3",
"sonata-project/doctrine-orm-admin-bundle": "^2.3",
"sonata-project/easy-extends-bundle": "^2.1",
"sonata-project/user-bundle": "^2.2",
"knplabs/knp-menu": "~1.1",
"knplabs/knp-menu-bundle": "~1.1",
"sonata-project/core-bundle": "~2.3"
I've also installed the assets with php app/console assets:install web --symlink, cleared the cache with php app/console cache:clear.
When I inspect the 'Network' tab in the Chrome Dev tools, no asset files are ever attempted to be loaded.
I'd rather expect something like this.
What am I missing here?
You shall check first in your configuration with the reference one on the official documentation :
https://sonata-project.org/bundles/admin/master/doc/reference/configuration.html
for the 2.3 version, you should have :
assets:
stylesheets:
# Defaults:
- bundles/sonataadmin/vendor/bootstrap/dist/css/bootstrap.min.css
- bundles/sonataadmin/vendor/AdminLTE/css/font-awesome.min.css
- bundles/sonataadmin/vendor/AdminLTE/css/ionicons.min.css
- bundles/sonataadmin/vendor/AdminLTE/css/AdminLTE.css
- bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css
- bundles/sonataadmin/vendor/jqueryui/themes/base/jquery-ui.css
- bundles/sonataadmin/vendor/select2/select2.css
- bundles/sonataadmin/vendor/select2/select2-bootstrap.css
- bundles/sonataadmin/vendor/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css
- bundles/sonataadmin/css/styles.css
- bundles/sonataadmin/css/layout.css
javascripts:
# Defaults:
- bundles/sonataadmin/vendor/jquery/dist/jquery.min.js
- bundles/sonataadmin/vendor/jquery.scrollTo/jquery.scrollTo.min.js
- bundles/sonatacore/vendor/moment/min/moment.min.js
- bundles/sonataadmin/vendor/bootstrap/dist/js/bootstrap.min.js
- bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js
- bundles/sonataadmin/vendor/jqueryui/ui/minified/jquery-ui.min.js
- bundles/sonataadmin/vendor/jqueryui/ui/minified/i18n/jquery-ui-i18n.min.js
- bundles/sonataadmin/jquery/jquery.form.js
- bundles/sonataadmin/jquery/jquery.confirmExit.js
- bundles/sonataadmin/vendor/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.min.js
- bundles/sonataadmin/vendor/select2/select2.min.js
- bundles/sonataadmin/App.js
- bundles/sonataadmin/Admin.js
I cannot get Mink/Behat to find the default step for the phrase
Then I should see "some text" in the element "element"
Here is my thepage.feature file:
Feature: Page Works
In order to use the page
As a visitor
I need to be able to load it and see content
Scenario: Navigating to the page
Given I am on "mypage.php"
#Then I should see "some text"
#Then the "body" element should contain "sometext"
#Then I should see "sometext" in the "body" element
My FeatureContext extends MinkContext so I don't see why the lower two Then statements come up as undefined, but the upper one works.
Scenario: Navigating to the page # features\wikipedia.feature:6
Given I am on "thepage.php" # FeatureContext::visit()
Then I should see "sometext" in the element "body"
1 scenario (1 undefined)
2 steps (1 undefined)
Since the Given statement works, I don't understand what could be wrong! Surely it can't be the yml file or composer.json?
composer.json:
{
"require": {
"behat/behat": "2.4.*#stable",
"behat/mink": "1.4.*#stable",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
behat.yml:
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://localhost
goutte: ~
selenium2: ~
Where else could the problem be? Thanks
Try to use
Then I should see "sometext" in the "body" element
instead of
Then I should see "sometext" in the element "body"
Here is MinkContext method description
Try with these (got it from here):
composer.json
"require-dev": {
"behat/behat": "2.5.5",
"behat/mink-extension": "1.3.3",
"behat/mink": "1.5.0",
"behat/symfony2-extension": "1.1.2",
"behat/mink-selenium2-driver": "1.1.1",
"behat/mink-browserkit-driver": "1.1.0",
"behat/mink-goutte-driver": "1.0.9"
}
behat.yml
default:
formatter:
name: pretty
parameters:
output_styles:
comment: [ magenta ]
context:
class: Application\BackendBundle\Features\Context\FeatureContext
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://football.local/app_test.php/'
javascript_session: selenium2
browser_name: firefox
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
For more examples, look here
I'm having a lot of trouble with setting up behat + mink for my laravel project.
The error msg:
PHP Deprecated: The ability to pass file names to Yaml::parse() was deprecated in 2.7
and will be removed in 3.0. Please, pass the contents of the file instead. in
home/user/projects/php/projectname/vendor/symfony/yaml/Symfony/Component/Yaml/Yaml.php
on line 58
[Behat\Testwork\ServiceContainer\Exception\ExtensionInitializationException]
`Behat\MinkExtensions\Extension` extension file or class could not be located.
My composer.json:
"require": {
"laravel/framework": "4.2.*",
"behat/behat": "~3.0.6",
"behat/mink": "1.6.*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-sahi-driver": "*",
"behat/mink-zombie-driver": "*"
My behat.yml (located in the root of the project)
default:
extensions:
Behat\MinkExtensions\Extension:
goutte: ~
I've tried different versions, but still same error msg.
The commands I've run are:
./vendor/bin/behat --init
./vendor/bin/behat
But produces same msg.
https://github.com/Behat/MinkExtension/blob/master/doc/index.rst
Reading the above solved the problem and the behat.yml should look like this.
# behat.yml
default:
# ...
extensions:
Behat\MinkExtension:
base_url: 'http://example.com'
sessions:
default:
goutte: ~