Behat测试遇到动态页面加载问题?Robertfausk/Behat-Panther-Extension来帮你!

当我在使用Behat进行Web应用测试时,遇到了一个难题:如何有效地测试JavaScript动态加载的内容?传统的Behat测试无法直接执行JavaScript,导致很多交互逻辑无法验证。我需要一个能够模拟真实浏览器行为,并且能够与Behat无缝集成的解决方案。这时,我发现了Robertfausk/Behat-Panther-Extension。

这个扩展的核心在于集成了symfony panther,panther是一个基于chrome/firefox的web爬虫和测试库,它能够执行javascript,并且提供了丰富的api来模拟用户行为。通过robertfausk/behat-panther-extension,你可以在behat中使用panther作为mink的驱动,从而实现对动态内容的测试。

首先,你需要通过composer安装这个扩展:

composer require --dev robertfausk/behat-panther-extension

然后,在你的behat.yml文件中配置该扩展:

extensions:     RobertfauskBehatPantherExtension: ~     BehatMinkExtension:         javascript_session: javascript_chrome         sessions:             default:                 panther: ~             javascript_chrome:                 panther:                     options:                         browser: 'chrome'                         webServerDir: '%paths.base%/public' # 你的项目public目录

通过以上配置,你可以指定使用Panther作为JavaScript会话的驱动,并且可以配置Panther的各种选项,例如指定浏览器类型、Web服务器目录等等。

以下是一个简单的Feature文件示例,展示了如何使用该扩展进行文件下载测试:

# acme_download.feature Feature: Acme 文件可以被下载    Background:     Given 下载目录中没有文件     # 还可以设置你的数据库条目等(如果需要)    @javascript   Scenario: 作为具有管理员角色的用户,我可以下载现有的acme文件     Given 我以 "admin@acme.de" 身份通过身份验证     And 我在 "/acme-file-list" 页面     Then 我等待 "acme.pdf" 出现     When 我点击测试元素 "button-acme-download"     Then 我可以在下载目录中找到文件 "acme.pdf"

通过这个扩展,你可以轻松地编写涉及JavaScript动态加载内容的Behat测试,并且可以利用Panther提供的各种功能来模拟用户行为,例如点击、输入、等待等等。Robertfausk/Behat-Panther-Extension极大地扩展了Behat的测试能力,让你可以更全面地测试你的Web应用。 Composer在线学习地址:学习地址 总而言之,Robertfausk/Behat-Panther-Extension 的优势在于:

  • 无缝集成: 与Behat无缝集成,使用方式与原生Behat测试一致。
  • 动态内容支持: 能够测试JavaScript动态加载的内容,弥补了传统Behat测试的不足。
  • 真实浏览器模拟: 基于Chrome/Firefox,模拟真实浏览器行为,测试结果更可靠。
  • 灵活配置: 提供了丰富的配置选项,可以根据需要定制Panther的行为。

Robertfausk/Behat-Panther-Extension 为 Behat 测试带来了强大的动态内容处理能力,使得Web应用的功能测试更加全面和可靠。 input: intervention/image

Image handling and manipulation library with support for laravel integration

Intervention Image

Intervention Image is an open source php image handling and manipulation library. It provides an easier and more expressive way to create, edit, and compose images. The library builds on top of the GD library or Imagick PHP extension and is suitable for web applications, small to medium scale image processing tasks and scenarios that require more control over the image handling process.

Features

Create, edit and save images with an easy to use API. Support for the most common image formats like JPEG, PNG, Gif, TIFF and more. Load images from files, streams or strings. Resize, crop, rotate and apply other common image manipulations. Add text or other images to images. Draw shapes and lines on images. Apply filters to images. Save images to files, streams or strings. Support for Laravel integration.

Installation

The recommended way to install Intervention Image is through Composer. Just add the following to your composer.json file.

{     "require": {         "intervention/image": "^2.7"     } }

Or use the following command:

composer require intervention/image

Configuration

Intervention Image requires either the GD library or Imagick PHP extension to be installed on your server. You can configure which of these libraries to use in your application’s configuration file.

GD Library

To use the GD library, set the driver option to gd in your config file.

'image' => [     'driver' => 'gd' ]

Imagick

To use the Imagick library, set the driver option to imagick in your config file.

'image' => [     'driver' => 'imagick' ]

Basic Usage

To create a new image instance, you can use the make method. this method accepts a file path, a URL, or a data URI.

use InterventionImageImageManagerStatic as Image;  $img = Image::make('public/foo.jpg');

You can then use the various methods provided by the Image class to manipulate the image.

$img->resize(320, 240); $img->greyscale(); $img->save('public/bar.jpg');

Laravel Integration

Intervention Image provides a service provider and facade for easy integration with Laravel.

Service Provider

To register the service provider, add the following to the providers Array in your config/app.php file.

'providers' => [     InterventionImageImageServiceProvider::class ]

Facade

To register the facade, add the following to the aliases array in your config/app.php file.

'aliases' => [     'Image' => InterventionImageFacadesImage::class ]

Configuration File

To publish the configuration file, run the following command.

php artisan vendor:publish --provider="InterventionImageImageServiceProviderLaravel5"

This will create a config/image.php file in your application. You can then use this file to configure the library.

Basic Usage

To create a new image instance, you can use the Image facade.

use Image;  $img = Image::make('public/foo.jpg');

You can then use the various methods provided by the Image class to manipulate the image.

$img->resize(320, 240); $img->greyscale(); $img->save('public/bar.jpg');

Documentation

For more information on how to use Intervention Image, please refer to the documentation.

https://www.php.cn/link/ada216e157757c965a766aae6e21423a

License

Intervention Image is licensed under the MIT License.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

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

Credits

Oliver Vogel All Contributors

Support us

Intervention Image is an MIT licensed open source project with its development made possible entirely by the support of its contributors. If you are using Intervention Image in a commercial project, please consider sponsoring us to help support its ongoing development.

Sponsor

Alternatives

If you are looking for alternatives to Intervention Image, you might want to consider the following libraries:

Imagine Gregwar Image WideImage

These libraries provide similar functionality to Intervention Image and might be a better fit for your needs.

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享