简体   繁体   English

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

[英]TestCafe firefox fails when page load takes too long

I'm pretty new to UI testing and just started exploring testCafe我对 UI 测试还很陌生,刚刚开始探索 testCafe

I'm writing a simple test in testCafe that will go to google, search testCafe, click on the submit button, then click on the first search result that appears and verify if it is the testCafe page:我正在 testCafe 中写一个简单的测试,将 go 发送到 google,搜索 testCafe,点击提交按钮,然后点击出现的第一个搜索结果并验证它是否是 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/")

})

This test works perfectly with Chrome and Safari, however Firefox is taking too long to load the google home page, and it is somehow not able to find the input[type="submit"] button.该测试与 Chrome 和 Safari 完美配合,但是 Firefox 加载 google 主页的时间过长,并且不知何故无法找到input[type="submit"]按钮。 Thus the test fails.因此测试失败。 It seems to me that the test starts executing even before the pageLoad finishes.在我看来,测试甚至在 pageLoad 完成之前就开始执行。

Here is the error that comes in Firefox:这是 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)

Is there a better way to write this test?有没有更好的方法来编写这个测试?

See code below:请参见下面的代码:

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 =>{

const inputBox = Selector('input[name="q"]');
const anchorLinks = Selector(".l");
const gettingStartedText = "Getting Started";

await t
.typeText(inputBox,'testcafe')
.pressKey('enter')
.click(anchorLinks.withText(gettingStartedText))
.expect(getURL()).eql("https://devexpress.github.io/testcafe/documentation/getting-started/")

});

It is good practice to create variables for your selectors, that makes it easy to read.为您的选择器创建变量是一种很好的做法,这样便于阅读。 Also instead of clicking on the submit button, All did was hit the enter key.也不是单击提交按钮,而是按回车键。 You can read up more here你可以在这里阅读更多

You can also pass in a command line argument to slow down the test a little bit.您还可以传入命令行参数以稍微减慢测试速度。 You can read up more here as well你也可以在这里阅读更多内容

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

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