如何在另一台服务器上 运行 TestCafe

How to run TestCafe on another server

我正在关注 TestCafe 文档,了解如何编写测试并运行 从命令行在本地进行测试。我想知道如何在远程服务器上托管测试并从其他地方执行它们。到目前为止,我能看到的唯一方法是使用 API 设置远程服务器,然后执行命令以 运行 TestCafe 测试。有没有更简单的方法来完成这个,它可以 运行 测试而不执行命令?

您可以在 NodeJS 脚本中创建一个 TestCafe 实例并使用 TestCafe API 来 运行 您的测试:

const createTestCafe = require('testcafe');
let testcafe         = null;

createTestCafe('localhost', 1337, 1338)
    .then(tc => {
        testcafe     = tc;
        const runner = testcafe.createRunner();

        return runner
            .src('test.js')
            .browsers('chrome')
            .run();
    })
    .then(failedCount => {
        console.log('Tests failed: ' + failedCount);
        testcafe.close();
    });

请参阅以下主题以查找有关此方法的更多信息: Runner Object, TestCafe Object