马文的地下室

学习笔记《Laravel 浏览器测试》

2017-05-10  本文已影响18人  马文Marvin

Laravel Dusk 是 Laravel 官方提供的浏览器测试解决方案:
https://laravel.com/docs/5.4/dusk

一个演示视频:
https://www.youtube.com/watch?v=V75hPsS6cvk

体验下来的优势包括:

风险:

自定义环境变量:

To force Dusk to use its own environment file when running tests, create a .env.dusk.{environment} file in the root of your project. For example, if you will be initiating the dusk command from your local environment, you should create a .env.dusk.local file.
When running tests, Dusk will back-up your .env file and rename your Dusk environment to .env. Once the tests have completed, your .env file will be restored.

绕过登录

$this->browse(function ($first, $second) {
    $first->loginAs(User::find(1))
          ->visit('/home');
});

支持 Drag & Drop

The drag method may be used to drag an element matching the given selector to another element:

$browser->drag('.from-selector', '.to-selector');

Or, you may drag an element in a single direction:

$browser->dragLeft('.selector', 10);
$browser->dragRight('.selector', 10);
$browser->dragUp('.selector', 10);
$browser->dragDown('.selector', 10);

Pages 机制

如果你的测试用例会出现比较复杂的页面跳转情况,那么就可以用 Pages 的机制实现代码分离,也便于让测试用例看起来更清晰,具体可以参照官方文档

持续集成

官方推荐 Travis CI 或者 CircleCI

备忘

运行测试:

./artisan dusk
上一篇 下一篇

猜你喜欢

热点阅读