【发布时间】:2020-04-05 14:36:45
【问题描述】:
尝试使用 testcafe 在 UI 上运行一些端到端测试。以下脚本应该从用户那里获取输入并在运行时对其进行评估,以帮助开发新的测试脚本。
但是,它无法识别Selector。
例如
>> console.log("hi")
hi
>> t.click(Selector('button').withText('Google Search'))
✖ test 1
1) ReferenceError: Selector is not defined
Browser: Chrome 80.0.3987.162 / macOS 10.15.4
12 |let x = "";
13 |
14 |test('test 1', async (t) => {
15 | while (1) {
16 | x = await getInput();
> 17 | eval(x)
18 | }
19 |})
20 |
21 |async function getInput() {
22 | return new Promise(
知道为什么吗?谢谢!!
这里是代码
import {Selector} from 'testcafe';
import readline from "readline";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
fixture`test page`
.page(`https://www.google.com`)
let x = "";
test('test 1', async (t) => {
while (1) {
x = await getInput();
eval(x)
}
})
async function getInput() {
return new Promise(
(resolve, reject) => {
rl.question(">> ", function (txt) {
resolve(txt)
})
}
);
};
【问题讨论】:
标签: javascript node.js testing automated-tests testcafe