使用testcafe进行超级慢速测试

时间:2018-07-01 14:06:28

标签: testcafe

我目前是第一次尝试testcafe,我以testdriven.io课程为例,并且面临着缓慢的测试。

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

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,同样的方法,尽管速度更快,只有44s。

(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(),如果有帮助,请保存一个Performance profile inside Firefox

edit2:如果有帮助,这是performance profile in chromium

enter image description here

0 个答案:

没有答案
相关问题