2

我目前正在第一次尝试 testcafe,我以testdriven.io课程为例,我面临着非常慢的测试。

例如testcafe e2e/login.test.js,这基本上是一个注册和登录有时需要 6 分钟才能通过,与作者在他的课程中的 15 秒相比,我发现这非常慢。

import {Selector} from 'testcafe';

const randomstring = require('randomstring');
const username = randomstring.generate();
const email = `${username}@test.com`;
const TEST_URL = process.env.TEST_URL;
fixture('/login').page(`${TEST_URL}/login`);


test(`should display the sign-in form`, async (t) => {
    await t
        .navigateTo(`${TEST_URL}/login`)
        .expect(Selector('H1').withText('Login').exists).ok()
        .expect(Selector('form').exists).ok()
});

test(`should allow a user to sign in`, async (t) => {
// register user
    await t
        .navigateTo(`${TEST_URL}/register`)
        .typeText('input[name="username"]', username)
        .typeText('input[name="email"]', email)
        .typeText('input[name="password"]', 'test')
        .click(Selector('input[type="submit"]'))
// log a user out
    await t
        .click(Selector('a').withText('Log Out'))
// log a user in
    await t
        .navigateTo(`${TEST_URL}/login`)
        .typeText('input[name="email"]', email)
        .typeText('input[name="password"]', 'test')
        .click(Selector('input[type="submit"]'))
// assert user is redirected to '/'
// assert '/' is displayed properly
    const tableRow = Selector('td').withText(username).parent();
    await t
        .expect(Selector('H1').withText('All Users').exists).ok()
        .expect(tableRow.child().withText(username).exists).ok()
        .expect(tableRow.child().withText(email).exists).ok()
        .expect(Selector('a').withText('User Status').exists).ok()
        .expect(Selector('a').withText('Log Out').exists).ok()
        .expect(Selector('a').withText('Register').exists).notOk()
        .expect(Selector('a').withText('Log In').exists).notOk()
// log a user out
    await t
        .click(Selector('a').withText('Log Out'))
// assert '/logout' is displayed properly
    await t
        .expect(Selector('p').withText('You are now logged out').exists).ok()
        .expect(Selector('a').withText('User Status').exists).notOk()
        .expect(Selector('a').withText('Log Out').exists).notOk()
        .expect(Selector('a').withText('Register').exists).ok()
        .expect(Selector('a').withText('Log In').exists).ok()
});

我尝试使用 Firefox,同样的交易,虽然速度要快得多,44 秒。

(project-tOIAx_A8) ➜  testdriven-app git:(master) ✗ testcafe 'chromium' e2e/login.test.js        
Using locally installed version of TestCafe.
(node:16048) ExperimentalWarning: The fs.promises API is experimental
 Running tests in:
 - Chrome 67.0.3396 / Linux 0.0.0

 /login
 ✓ should display the sign in form
 ✓ should allow a user to sign in


 2 passed (6m 15s)

我希望我能提供更多信息,去开发工具,检查控制台,但有时没有注意到任何错误消息:

hammerhead.js:7 WebSocket connection to 'ws://192.168.1.195:38039/4wxhbvTF7!w!http%3A%2F%2F172.18.0.5/http://172.18.0.5/sockjs-node/444/2kjm15kn/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

,瀑布看起来很慢,有没有办法给出它的日志报告以帮助了解这种缓慢的情况?

编辑:我在测试开始和结束时放置了一个 .debug() 并在Firefox 中保存一个性能配置文件,如果有帮助的话

编辑2:如果有帮助,这是铬的性能概况

在此处输入图像描述

4

0 回答 0