[英]Symfony2 Selenium Behat base_url not loaded
I am setting up a testing env for an application in symfony2 but I get some errors that I don't find a coherent answer online... 我正在为symfony2中的应用程序设置测试环境,但遇到一些错误,但我在网上找不到一致的答案...
composer json
作曲家json
"require-dev": {
...
"behat/symfony2-extension": "^2.1",
"behat/mink-browserkit-driver": "^1.3",
"behat/mink-goutte-driver": "@stable",
"behat/mink-extension": "@stable",
"behat/mink-selenium2-driver": "^1.3"
},
behat.yml - old one
behat.yml-旧的
default:
extensions:
Behat\MinkExtension:
base_url: 'http://myapp.lan/app_test.php/'
browser_name: firefox
default_session: selenium2
goutte: ~
selenium2: ~
javascript_session: selenium2
Behat\Symfony2Extension: ~
behat.yml - new one
behat.yml-新
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://myapp.lan/app_test.php/
browser_name: firefox
sessions:
goutte:
goutte: ~
selenium2:
selenium2: ~
symfony2:
symfony2: ~
javascript_session: selenium2
suites:
site:
type: symfony_bundle
bundle: SiteBundle
mink_session: symfony2
contexts:
- MyApp\SiteBundle\Features\Context\FeatureContext
feature
特征
Feature: Test login of users
@javascript
Scenario: Login to application
Given: I am on "/"
Then I should see "Login"
I am using 我在用
selenium/selenium-server-standalone-2.50.1.jar
. selenium/selenium-server-standalone-2.50.1.jar
。
Firefox 44 installed in my OS (Linux Mint) 我的操作系统中安装了Firefox 44(Linux Mint)
The browser starts but there no url triggered. 浏览器启动,但是没有触发URL。
As you see the url input is empty and after few seconds the browser closes with the test failing. 如您所见,URL输入为空,几秒钟后浏览器关闭,测试失败。
When i run echo $this->getSession()->getCurrentUrl();
当我运行
echo $this->getSession()->getCurrentUrl();
I get about:blank
so obviously base_url
is ignored. 我得到
about:blank
因此显然base_url
被忽略了。
If i enter the url manually then everything is OK. 如果我手动输入网址,则一切正常。
I don't have a VM or something else installed just a linux box with latest version of firefox/chrome and latest version of selenium which is also my dev environment. 我没有VM或其他东西,只是安装了Linux盒,其中装有最新版本的firefox / chrome和最新版本的selenium,这也是我的开发环境。
I can confirm that this example worked for me. 我可以确认此示例对我有用。 Got it from Installing behat3 with composer.json
通过使用composer.json安装behat3获得了它
composer.json composer.json
{
"require-dev": {
"behat/behat" : "3.0.15",
"behat/symfony2-extension" : "2.0.0",
"behat/mink": "1.6.1",
"behat/mink-extension": "2.0.1",
"behat/mink-browserkit-driver": "1.2.0",
"behat/mink-goutte-driver": "1.1.0",
"behat/mink-selenium2-driver": "1.2.0"
}
}
behat.yml behat.yml
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://myapp.lan/app_test.php
browser_name: firefox
sessions:
goutte:
goutte: ~
selenium2:
selenium2: ~
symfony2:
symfony2: ~
suites:
backend:
type: symfony_bundle
bundle: ApplicationBackendBundle #Change this with your
mink_session: symfony2
contexts:
- Application\BackendBundle\Features\Context\FeatureContext: #Change this with your
param1: hello
param2: world
FeatureContext FeatureContext
namespace Application\BackendBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext
{
private $param1;
private $param2;
public function __construct($param1, $param2)
{
$this->param1 = $param1;
$this->param2 = $param2;
}
}
Gherkin 小黄瓜
Feature: Visit pages and see contents
Scenario: I visit home page and see welcome message
Given I am on "/"
Then I should see "Welcome to Application!"
Scenario: I visit contact page and see contact message
Given I am on "/contact"
Then I should see "Contact me!"
Selenium and Firefox have compatibility issues that I myself experienced before. Selenium和Firefox有我自己以前遇到过的兼容性问题。 If you Google, you'll see similar posts.
如果您使用Google,则会看到类似的信息。 Try in this order:
按此顺序尝试:
selenium-server-standalone-2.43.1.jar
version. selenium-server-standalone-2.43.1.jar
版本。 https://selenium-release.storage.googleapis.com/index.html?path=2.43/ You should really go through http://www.inanzzz.com/index.php/posts/behat for examples. 您确实应该通过http://www.inanzzz.com/index.php/posts/behat获得示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.