如何在Laravel Dusk中强制'type'方法完全在浏览器中输入测试数据

时间:2019-11-18 09:22:27

标签: laravel phpunit laravel-dusk phpunit-testing browser-testing

我有三个测试数据[检查,运输,交货],可以使用循环自动输入。它不会输入第三个,从而导致测试失败。这是代码。

这是我的测试数据的代码

private static function getValidAdminCommentInput()
    {
        return[
            //key
            'Comment[order_comment]' => [
                //testNo           Value                input method    assertMethod
                'testSpec01' => ['Checking order',      'type',         'assertInputValue'],
                'testSpec02' => ['Shipping order',      'type',         'assertInputValue'],
                'testSpec03' => ['Delivering order',    'type',         'assertInputValue'],
            ],
        ];
    }

这是我用来自动输入上述三个测试数据的foreach和while循环

            $adminCommentInputData = self::getValidAdminCommentInput();
            $retryMax = 5;
            $retryCount = 0;
            foreach ($adminCommentInputData as $keys => $keyVal) {
                foreach ($keyVal as $key => $input) {
                    $selector = '[name="' . $keys . '"]';
                    $method = $input[1];
                    $assertMethod = $input[2];
                    sleep(60); // creates time interval of comments to simulate real commenting time interval
                    while ($retryCount++ < $retryMax) {
                        $browser->clickLink('Admin Comments')
                                ->clickLink('Create Admin Comments')
                                ->waitFor($selector)
                                ->$method($selector, $input[0]);
                        try {
                            $browser->$assertMethod($selector, $input[0])
                                    ->press('Create');
                                break;
                        } catch (AssertionFailedError $e) {
                                // ignore
                        }
                    }
                }
            }

请帮助谢谢!

0 个答案:

没有答案