Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/josevte/laravel-dusk-5.1


https://github.com/josevte/laravel-dusk-5.1

dusk laravel laravel-dusk

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        


Build Status
Total Downloads
Latest Stable Version
License

## Laravel 5.1


Build Status
Total Downloads
Latest Stable Version
License

## Introduction

Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your machine. Instead, Dusk uses a standalone Chromedriver. However, you are free to utilize any other Selenium driver you wish.

## Official Documentation

Documentation for Dusk can be found on the [Laravel website](https://github.com/laravel/dusk/tree/1.0).

## Installation

To get the last version of Laravel Dusk for 5.1, simply require the project using [Composer](https://getcomposer.org/):

```bash
composer require --dev josrom/laravel-dusk-5.1
```

Instead, you may of course manually update your require block and run composer update if you so choose:

```json
{
"require-dev": {
"josrom/laravel-dusk-5.1": "0.1.*"
}
}
```

Add the service provider `app/Providers/AppServiceProvider.php` file:

```php
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Dusk\DuskServiceProvider::class);
}
```

After installing the Dusk package, run the `dusk:install` Artisan command:

```bash
php artisan dusk:install
```

A `Browser` directory will be created within your `tests` directory and will contain an example test. Next, set the `APP_URL` environment variable in your `.env` file. This value should match the URL you use to access your application in a browser.

To run your tests, use the `dusk` Artisan command. The `dusk` command accepts any argument that is also accepted by the `phpunit` command:

```bash
php artisan dusk
```

## Configuration

By default dusk use the port 9515 and have a timeout of 20 seconds.

If you need change the configuration the dusk port and/or timeout, it is needed to publish the config file:

```bash
php artisan vendor:publish --provider="Laravel\Dusk\DuskServiceProvider" --tag="config"
```

To make the changes by *environment variables**, add the fields in the **dusk env file**.

## Extra methods

| Method | Definition |
| ------ | ---------- |
| [switchFrame](#switchFrame) | (type of selector, value of selector) |
| [select2](select2) | (selector, value(s), wait in seconds) |
| [selectBySelector](selectBySelector) | (selector css, value of selector) |
| [assertFragmentIs](assertFragmentIs) | (value of fragment) |
| [assertQueryIs](assertQueryIs) | (value of query) |
| [scrollTo](scrollTo) | (selector jQuery) |
| [wysiwyg](wysiwyg) | (type of wysiwyg: tinymce, ID of wysiwyg, value) |

### Examples

#### switchFrame

Example of payment with paypal using the `switchFrame` method:

```php
$browser->loginAs($user)
->visit('/user')
->assertSee('Some Event')
->clickLink('Register Now')
->assertSee('Some Event')
->check('accept_terms')
->press('Submit Application')
->assertSee('Your application has been submitted.')
->press('.paypal-button')
->waitFor('#injectedUnifiedLogin', 30)
->switchFrame('injectedUl')
->type('#email', env('PAYPAL_TEST_BUYER_USERNAME'))
->type('#password', env('PAYPAL_TEST_BUYER_PASSWORD'))
->press('#btnLogin')
->waitFor('#confirmButtonTop', 30)
->waitUntilMissing('#spinner')
->press('#confirmButtonTop')
->waitForText('You paid', 30)
->waitUntilMissing('#spinner')
->press('#merchantReturnBtn')
->waitForText('Events Registration', 30)
->pause(10000) // waiting for IPN callback from paypal
->refresh()
->assertSee('Payment verified')
;
```

#### select2

Example of `select2` uses:

* For default select2. If value not passed, it be selected automatically:

```php
$browse->select2('@selector');
```

* Another way, if need concrete value:

```php
$browse->select2('@selector', 'you_text_value');
```

* For multiple mode usage like this:

```php
$browse->select2('@selector', ['foo', 'bar'], 5);
```

* Css-selector for the select html tag should be ends with + select2 name:

```html

```

```php
$browse->select2('.select2-users + .select2', 'you_text_value');
```

#### selectBySelector

Example of `selectBySelector` uses:

```php
$browse->selectBySelector('select.my-custom-selector', 'value');
```

#### assertFragmentIs

Example of `assertFragmentIs` uses:

```php
$browser->visit('http://laravel.com/#/login')
->assertPathIs('/')
->assertFragmentIs('/login');
```

#### assertQueryIs

Example of `assertQueryIs` uses:

```php
$browser->visit('http://laravel.com?key=test')
->assertPathIs('/')
->assertQueryIs('key=test');
```

#### scrollTo

Example of `scrollTo` uses:

```php
$browser->visit('http://laravel.com')
->scrollTo('#cookie-id')
->click('#cookie-id');
```
#### wysiwyg

Example of `wysiwyg` uses:

```php
$browser->visit('http://laravel.com')
->wysiwyg('tinymce', 'form-id', '

value

');
```

## License

Laravel Dusk is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)