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 分享