Behat 测试 "Then I should see Laravel 5" 在 laravel 应用程序中失败
Behat test "Then I should see Laravel 5" fails in laravel application
我有一台装有 OS El Capitan 的 Macbook。在我的新 Laravel 应用程序中(由
$ composer create-project laravel/laravel my_app
),我输入:
$ php artisan serve
并且在 localhost:8000 上的浏览器(Safari 或 Chrome)中,我成功地在网页上看到了黑色文本 "Laravel 5"。
我在 features/ 中有一个 hometest.feature 文件,它看起来像:
Feature:
In order to prove that Behat works as intended
We want to test the home page for a phrase
Scenario: Root Test
When I am on the homepage
Then I should see "Laravel 5"
我有一个 /features/bootstrap/FeaturesContext.php 文件,它看起来像:
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
}
}
我有一个 behat.yml 文件,如下所示:
default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
Behat\MinkExtension:
default_session: laravel
base_url: http://localhost:8000
laravel: ~
当我运行(localhost 运行ning 与否运行ning = 没有不同的结果):
$ vendor/bin/behat
控制台输出为:
Feature:
In order to prove that Behat works as intended
We want to test the home page for a phrase
Scenario: Root Test # features/hometest.feature:5
When I am on the homepage # FeatureContext::iAmOnHomepage()
Then I should see "Laravel 5" # FeatureContext::assertPageContainsText()
The text "Laravel 5" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)
--- Failed scenarios:
features/hometest.feature:5
1 scenario (1 failed)
2 steps (1 passed, 1 failed)
0m0.12s (20.26Mb)
为什么我的简单“我应该看到 'Laravel 5' 测试失败了?如果本地主机需要 运行ning,我如何同时 运行 我的测试?什么时候我启动了本地主机,我在终端中输入的任何内容都不再收到响应。
我的适用文件夹目录结构:
app/
bootstrap/
...
features/
bootstrap/
FeatureContext.php
hometest.feature
...
.env.behat
behat.yml
composer.json
...
etc.
谢谢!
终于!我通过服务器日志 (storage/logs/laravel.log) 发现呈现的页面包含文本 "Whoops, looks like something went wrong."(显然是错误的页面)。错误是 "development.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.'"
Whosebug 上大约有 50 个问题和答案,其中 none 有效。经过几天的研究,终于找到了解决方案。它可能是我之前所做更改的组合,或者成功完全归功于此命令。无论如何,尝试:
php artisan config:cache
呸!
我通过在 env.behat 文件
中添加 APP_KEY 解决了这个问题
我有一台装有 OS El Capitan 的 Macbook。在我的新 Laravel 应用程序中(由
$ composer create-project laravel/laravel my_app
),我输入:
$ php artisan serve
并且在 localhost:8000 上的浏览器(Safari 或 Chrome)中,我成功地在网页上看到了黑色文本 "Laravel 5"。
我在 features/ 中有一个 hometest.feature 文件,它看起来像:
Feature:
In order to prove that Behat works as intended
We want to test the home page for a phrase
Scenario: Root Test
When I am on the homepage
Then I should see "Laravel 5"
我有一个 /features/bootstrap/FeaturesContext.php 文件,它看起来像:
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
}
}
我有一个 behat.yml 文件,如下所示:
default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
Behat\MinkExtension:
default_session: laravel
base_url: http://localhost:8000
laravel: ~
当我运行(localhost 运行ning 与否运行ning = 没有不同的结果):
$ vendor/bin/behat
控制台输出为:
Feature:
In order to prove that Behat works as intended
We want to test the home page for a phrase
Scenario: Root Test # features/hometest.feature:5
When I am on the homepage # FeatureContext::iAmOnHomepage()
Then I should see "Laravel 5" # FeatureContext::assertPageContainsText()
The text "Laravel 5" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)
--- Failed scenarios:
features/hometest.feature:5
1 scenario (1 failed)
2 steps (1 passed, 1 failed)
0m0.12s (20.26Mb)
为什么我的简单“我应该看到 'Laravel 5' 测试失败了?如果本地主机需要 运行ning,我如何同时 运行 我的测试?什么时候我启动了本地主机,我在终端中输入的任何内容都不再收到响应。
我的适用文件夹目录结构:
app/
bootstrap/
...
features/
bootstrap/
FeatureContext.php
hometest.feature
...
.env.behat
behat.yml
composer.json
...
etc.
谢谢!
终于!我通过服务器日志 (storage/logs/laravel.log) 发现呈现的页面包含文本 "Whoops, looks like something went wrong."(显然是错误的页面)。错误是 "development.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.'" Whosebug 上大约有 50 个问题和答案,其中 none 有效。经过几天的研究,终于找到了解决方案。它可能是我之前所做更改的组合,或者成功完全归功于此命令。无论如何,尝试:
php artisan config:cache
呸!
我通过在 env.behat 文件
中添加 APP_KEY 解决了这个问题