简体   繁体   English

使用javascript在laravel中进行Behat测试 - 不使用测试环境

[英]Behat testing in laravel with javascript - not using test environment

I have a Laravel 5 project using Behat for acceptance testing. 我有一个使用Behat进行验收测试的Laravel 5项目。 I'm also running this in a Homestead Vagrant box. 我也在Homestead Vagrant盒子里运行它。

I have a page in my site that uses Javascript, and I'm using the Selenim2 driver with phantom js. 我的网站中有一个使用Javascript的页面,我正在使用带有幻像js的Selenim2驱动程序。 Selenium seems to be working fine. 硒似乎工作正常。 The problem is when I run my test it uses the development database instead of the testing one. 问题是,当我运行我的测试时,它使用开发数据库而不是测试数据库。 Here's my .env.behat file: 这是我的.env.behat文件:

APP_ENV=acceptance
APP_DEBUG=true

DB_TYPE=sqlite
DB_PATH=acceptance.sqlite

And here is my behat.yml file 这是我的behat.yml文件

default:
    extensions:
        Laracasts\Behat: ~
#            env_path: .env.behat
        Behat\MinkExtension:
            default_session: laravel
            laravel: ~
            javascript_session: selenium2
            base_url: http://127.0.0.1/
            selenium2:
                wd_host: "http://localhost:8643/wd/hub"
            selenium2: ~

When I run scenario that doesn't use javascript it uses my test database (as specified in the .env.behat file. 当我运行不使用javascript的场景时,它使用我的测试数据库(在.env.behat文件中指定)。

Thank you for any help! 感谢您的任何帮助!

To preserve Behat's testing environment when testing Javascript applications, you can use BehatLaravelJs package as a companion to Behat's Laravel extension. 为了在测试Javascript应用程序时保留Behat的测试环境,您可以使用BehatLaravelJs包作为Behat的Laravel扩展的伴侣。

Besides preserving the environment, it also addresses other limitations like authentication and database transactions when testing Javascript apps using a browser emulator. 除了保留环境之外,它还在使用浏览器模拟器测试Javascript应用程序时解决了身份验证和数据库事务等其他限制。

Environment variables set in the command line are not visible by your web server as it runs in a separate process. Web服务器在命令行中设置的环境变量在单独的进程中运行时不可见。

You could do either of the following: 您可以执行以下任一操作:

  • Set up a test environment in a separate test front controller. 在单独的测试前端控制器中设置测试环境。
  • Set up a test environment in a separate test virtual host. 在单独的测试虚拟主机中设置测试环境。

In both cases you'll need to update the base_url in behat.yml : 在这两种情况下,您都需要更新behat.ymlbase_url

default:
    extensions:
        Behat\MinkExtension:
            base_url: http://127.0.0.1/app_test.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Javascript在实时网站上创建测试环境 - Using Javascript to create a test environment on live website 当页面上出现javascript错误时,失败的behat @javascript测试 - Fail a behat @javascript test when there is a javascript error on the page Behat测试验证消息 - Behat test validation message 如何使用JavaScript测试框架测试网站布局 - How to test web layout using javascript testing frameworks 使用 jest javascript 测试库异步等待测试用例失败 - Async await test cases failed using jest javascript testing library React/TypeScript 测试失败。 “考虑使用‘jsdom’测试环境。” - React/TypeScript testing failed. "Consider using the "jsdom" test environment." Javascript未在Rails测试环境中加载 - Javascript not loading in Rails Test Environment Javascript Testing Framework是关于测试javascript代码还是使用javascript测试以某种其他编程语言编写的任何应用程序? - Is Javascript Testing Framework about testing javascript code or using javascript to test any application written in some other programming language? 使用Javascript-Test-Driver进行Javascript单元测试 - Javascript Unit Testing with Javascript-Test-Driver behat使用javascript失败,但是没有 - behat fails with javascript but succeeds without
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM