clevyr/laravel-behat-dusk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clevyr/laravel-behat-dusk

Composer 安装命令:

composer require clevyr/laravel-behat-dusk

包简介

README 文档

README

GitHub release (latest SemVer including pre-releases)

Laravel Behat Dusk is a simple package with the goal of integrating Behat with Laravel and Laravel Dusk.

This is not a 1:1 implementation of Behat with Laravel, the current goal is to enable a simple and quick way to write Behavior Driven Tests in Laravel Applications.

Pre-requisites

  • Laravel 8+
  • PHP 8.0+
  • Basic Understanding of Behavioral Driven Development and Behat

Installation

composer require clevyr/laravel-behat-dusk --dev

Install the Package

php artisan lbd:install

The following files will be outputted

  • features
    • bootstrap
      • FeatureContext
  • behat.yml

Testing Environments

Laravel Behat Dusk's environment setup works the exact same way as Laravel Dusk. Take a look at their documentation for environment handling. https://laravel.com/docs/8.x/dusk#environment-handling

Running in Docker

  • Create a .env.dusk.local file by running cp .env .env.dusk.local and add it to your .gitignore file
  • Update the following .env.dusk.local environment file with the following
APP_URL=http://laravel.test
DUSK_DRIVER_URL=http://selenium:4444/wd/hub

If you are not using Laravel Sail use the docker-compose container names for your Application and Selenium Containers.

  • Run Laravel Behat Dusk in the app container sail artisan lbd

Usage

Creating a context file

This creates a Context file in the features/bootstrap and appends the relevant configuration data inside the behat.yml

php artisan lbd:make ExampleContext

--profile[=PROFILE]  Create under the profile in the Behat Config [default: "default"]
--suite[=SUITE]      Create under the suite in the Behat Config [default: "default"]

Running Behat

Run this command to run the Behat test runner, you are able to use all arguments from the Behat CLI

php artisan lbd

Traits

Refresh the database before each Scenario use RefreshScenario;

Example feature file and context file

login.feature file

Feature: User Login

    In order to acess the site
    As a user
    I want to be able to login

    Scenario: Logging in as a User
        Given There are users
            | email            | password |
            | user@example.com | password |
        When I am on the "/login" page
        When I fill in email
        When I fill in password
        When I press the submit button
        Then I should be redirected to the "/dashboard" page

FeatureContext.php

<?php

use Behat\Gherkin\Node\TableNode;
use Clevyr\LaravelBehatDusk\BehatDuskTestCase;
use Clevyr\LaravelBehatDusk\Traits\RefreshScenario;
use Laravel\Dusk\Browser;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends BehatDuskTestCase
{
    use RefreshScenario;

    /**
     * @var array $user
     */
    public array $user;

    /**
     * @Given /^There are users$/
     * @param TableNode $table
     */
    public function thereAreUsers(TableNode $table)
    {
        foreach ($table->getHash() as $row) {
            $this->user = ['email' => $row['email'], 'password' => $row['password']];
        }
    }

    /**
     * @When /^I am on the "([^"]*)" page$/
     * @param string $page
     * @throws Throwable
     */
    public function iAmOnThePage(string $page)
    {
        $this->browse(function (Browser $browser) use ($page) {
            $browser->visit($page);
        });
    }

    /**
     * @When /^I fill in (.*)$/
     * @throws Throwable
     */
    public function iFillIn()
    {
        $this->browse(function (Browser $browser) {
            $browser
                ->type('email', $this->user['email'])
                ->type('password', $this->user['password']);
        });
    }

    /**
     * @When /^I press the submit button$/
     * @throws Throwable
     */
    public function iPressTheSubmitButton()
    {
        $this->browse(function (Browser $browser) {
            $browser
                ->press('[type="submit"]')
                ->waitForLocation('/dashboard');
        });
    }

    /**
     * @Then /^I should be redirected to the "([^"]*)" page$/
     * @param string $page
     * @throws Throwable
     */
    public function iShouldBeRedirectToThePage(string $page)
    {
        $this->browse(function (Browser $browser) use ($page) {
            $browser->assertPathIs($page);
        });
    }
}

Testing

composer test

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Laravel Behat Dusk is GPL-3.0 License Licensed

clevyr/laravel-behat-dusk 适用场景与选型建议

clevyr/laravel-behat-dusk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 clevyr/laravel-behat-dusk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 clevyr/laravel-behat-dusk 我们能提供哪些服务?
定制开发 / 二次开发

基于 clevyr/laravel-behat-dusk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 10
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-19