简体   繁体   English

Laravel Dusk-运行测试并通过代码获取结果

[英]Laravel Dusk - Run tests & get results via code

I need to make a tool to Browser test my production system. 我需要制作一个工具来浏览器测试我的生产系统。 I have read up all about Laravel Dusk and it seems like a perfect tool. 我已经阅读了有关Laravel Dusk的所有内容,它似乎是一个完美的工具。 However, I need to run tests automatically via schedule and have a dashboard with the results. 但是,我需要通过时间表自动运行测试,并有一个包含结果的仪表板。

I can easily run the command php artisan dusk from the code using the Scheduler, however, how can I get the results? 我可以使用Scheduler从代码轻松运行php artisan dusk命令,但是如何获得结果? Is there a better option than simply parsing the Console Output from that command? 是否有比仅从该命令解析控制台输出更好的选择? Ideally I would have a way of getting the status of each test (whether it passed or failed) to be able to log, process and display all that information. 理想情况下,我将有一种方法来获取每个测试的状态(无论测试通过还是失败),以便能够记录,处理和显示所有这些信息。

The Dusk documentation hasn't got any more information on running the tests programatically, it only has instructions to run via php artisan dusk . Dusk文档没有有关以编程方式运行测试的更多信息,它仅具有通过php artisan dusk运行的说明。

Has anyone encountered this? 有人遇到过这个吗?

Thank you! 谢谢!

The way I have achieved what I needed is to use the command options for dusk/phpunit. 我所需要的方法是使用黄昏/ phpunit的命令选项。

I used --filter=MyTestClass to single out which test I wanted to run, and --log-junit log.log to log the results for that test, which I then parsed via code as well to fetch the results. 我使用--filter=MyTestClass来选择要运行的测试,并使用--log-junit log.log记录该测试的结果,然后通过代码对其进行解析以获取结果。 This allowed me to build a fully custom dashboard that was able to run each test individually, report the results, send notifications etc. 这使我能够构建一个完全自定义的仪表板,该仪表板能够单独运行每个测试,报告结果,发送通知等。

Not the prettiest solution, but it worked well for what I needed. 不是最漂亮的解决方案,但是它可以很好地满足我的需求。 If anyone encounters better way to achieve that (or just use Dusk in general as a browser/scraper outside phpunit) please do post a comment/answer! 如果有人遇到更好的方法来实现这一目标(或者只是将黄昏一般用作phpunit之外的浏览器/抓取工具),请发表评论/答案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM