TestCafe firefox在页面加载时间过长时失败

问题描述 投票:0回答:1

我对UI测试非常陌生,刚刚开始探索testCafe

[我正在用testCafe编写一个简单的测试,它将转到google,搜索testCafe,单击Submit按钮,然后单击出现的第一个搜索结果,并验证它是否是testCafe页面:

import {Selector} from 'testcafe';
import {ClientFunction} from 'testcafe';

const getURL = ClientFunction(()=> window.location.href);

fixture `Getting Started`
    .page `https://www.google.com/`;

test('Google Search test', async t =>{
    await t
    .typeText('input[name="q"]','testcafe')
    .click('input[type="submit"]')
    .click('div.r > a')
    .expect(getURL()).eql("https://devexpress.github.io/testcafe/documentation/getting-started/")

})

此测试与Chrome和Safari完美配合,但是Firefox加载Google主页所需的时间太长,而且无法找到input[type="submit"]按钮。因此测试失败。在我看来,测试甚至在pageLoad完成之前就开始执行。

这是Firefox中出现的错误:

   1) The element that matches the specified selector is not visible.

      Browser: Firefox 75.0 / macOS 10.14

          7 |    .page `https://www.google.com/`;
          8 |
          9 |test('Google Search test', async t =>{
         10 |    await t
         11 |    .typeText('input[name="q"]','testcafe')
       > 12 |    .click('input[type="submit"]')
         13 |    .click('div.r > a')
         14 |    .expect(getURL()).eql("https://devexpress.github.io/testcafe/documentation/getting-started/")
         15 |
         16 |})

         at <anonymous> (/Users/goplap/TestCafeTest/tests/sampleTest.js:12:6)
         at <anonymous> (/Users/goplap/TestCafeTest/tests/sampleTest.js:9:1)
         at <anonymous> (/Users/goplap/TestCafeTest/node_modules/testcafe/src/api/wrap-test-function.js:17:28)
         at TestRun._executeTestFn (/Users/goplap/TestCafeTest/node_modules/testcafe/src/test-run/index.js:295:19)
         at TestRun.start (/Users/goplap/TestCafeTest/node_modules/testcafe/src/test-run/index.js:345:24)



 1/1 failed (18s)

是否有更好的方法编写此测试?

javascript testing automated-tests testcafe ui-testing
1个回答
0
投票

请参见下面的代码:

© www.soinside.com 2019 - 2024. All rights reserved.