我正在使用 Laravel 5 , Behat 和 Laravel的Mink Extension 。用于安装组件的composer.json
件是:
"require-dev": {
"phpunit/phpunit": "~4.0",
"behat/behat": "^3.0",
"behat/mink": "^1.6",
"behat/mink-extension": "^2.0",
"laracasts/behat-laravel-extension": "^1.0"
}
我已在behat.yml
中设置了基本网址,该文件的全部内容为:
default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
Behat\MinkExtension:
base_url: http://localhost/leaveTracker/public
default_session: laravel
laravel: ~
请注意,我已将base_url设置为:
base_url: http://localhost/leaveTracker/public
我也写了这个示例功能:
Feature: Viewing the list of employees
In order to operate the employees' data
As a user
I need to see the list of employees
Scenario: I have the option to add employee
Given I am on page "/employee"
Then the current URL should be "http://localhost/leaveTracker/public/employee"
FeatureContext.php
的相应部分是:
/**
* @Then the current URL should be :arg1
*/
public function theCurrentUrlShouldBe($arg1)
{
PHPUnit::fail($this->getSession()->getCurrentUrl());
}
这里我得到以下错误,这对我来说是正常的:
Scenario: I have the option to add employee
Given I am on page "/employee"
Then the current URL should be "http://localhost/leaveTracker/public/employee"
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/employee'
+'http://localhost/leaveTracker/public/employee'
现在我的问题是:为什么base_url
未从behat.yml
文件中读取?
注意:我还尝试设置base_url: https://test.com
,但需要http://localhost/employee
答案 0 :(得分:4)
从Behat 2.x更新到Behat 3.x时遇到了同样的问题
behat.yml:[定义base_url]
extensions:
Behat\MinkExtension:
base_url: 'http://localhost/index.php'
在从RawMinkContext调用扩展的Context类中:
$this->visitPath($url);
该功能将$config['base_url']
与$url
结合在一起。呼叫$this->getSession()->visit($url)
浏览普通$url
。
答案 1 :(得分:0)
而不是:
Given I am on page "/employee"
尝试:
Given I am on "/employee"
我不了解Laravel,但这就是我们在symfony中所做的事情:
default:
extensions:
Behat\MinkExtension\Extension:
base_url: 'http://localhost/myproject/web/app_test.php/'
当您在下面调用命令时,您应该看到上面的基本URL,以便在您的情况下会发生什么?
class FeatureContext extends MinkContext
{
// In one of you methods run this
echo $this->getSession()->getCurrentUrl();
}