【发布时间】:2019-08-12 16:00:12
【问题描述】:
使用 CLI 在 TestCafe 上执行测试时,出现以下错误:
ERROR Cannot prepare tests due to an error.
at Object.<anonymous> (C:\Users\xxxx\Documents\TestCafe_Framework\tests\Test.js:1:1)
at Function._execAsModule (C:\Users\xxxxx\Documents\TestCafe_Framework\node_modules\testcafe\src\compiler\test-file\api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (C:\Users\xxxxx\Documents\TestCafe_Framework\node_modules\testcafe\src\compiler\test-file\api-based.js:150:42)
at ESNextTestFileCompiler.execute (C:\Users\xxxxxx\Documents\TestCafe_Framework\node_modules\testcafe\src\compiler\test-file\api-based.js:174:21)
at ESNextTestFileCompiler.compile (C:\Users\xxxxx\Documents\TestCafe_Framework\node_modules\testcafe\src\compiler\test-file\api-based.js:180:21)
at Compiler._getTests (C:\Users\xxxxxx\Documents\TestCafe_Framework\node_modules\testcafe\src\compiler\index.js:87:31)
at Compiler._compileTestFiles (C:\Users\xxxxx\Documents\TestCafe_Framework\node_modules\testcafe\src\compiler\index.js:99:35)
最初我已经记录了 TestCafe GUI 中的步骤并执行了相同的操作。但是当我将代码转换为 POM 样式时,它会抛出错误
测试文件:这是将从 CLI 执行的实际测试
import LoginPage from `C:\Users\xxxxxx\Documents\TestCafe_Framework\page_object;`
fixture(`Testing`)
.page(`https://xxxx/login.php`);
test('PVT ', async (t) => {
//var email = Math.floor(Math.random() * 555);
//var random_ascii = Math.floor((Math.random() * 25) + 97);
//var name = String.fromCharCode(random_ascii);
await t.LoginPage.login('hp', 'St');
});
页面文件:此文件包含执行登录操作的选择器和操作函数。
import { Selector, t } from 'testcafe';
class LoginPage {
get emailTextBox() { return Selector('#EmailAddr'); }
get passwordTextBox() { return Selector('#Password'); }
get loginButton() { return Selector('#SignIn'); }
async login(username, password) {
await t
.click(this.emailTextBox)
.typeText(this.emailTextBox, username)
.click(this.passwordTextBox)
.typeText(this.passwordTextBox, password)
.click(this.loginButton)
}
}
export default new LoginPage();
【问题讨论】:
标签: testing automated-tests e2e-testing testcafe web-testing