在使用TestCafe编写测试时,我正在创建实用程序函数,但在任何函数中使用Selector('')方法时似乎存在问题.
Selector('')方法在测试文件中以及从另一个文件(utility_selectors.js)导入时都可以正常工作.我想我需要在函数中包含一些东西,但我卡住了,似乎无法找到解决方案.
我的目标是创建一个选择鼠标点击坐标的功能.
Utility_selectors.js
import { Selector } from 'testcafe';
export const viewport = Selector('.viewport').find('canvas');
Run Code Online (Sandbox Code Playgroud)
Utility_functions.js
import * as s from './selectors.js';
export const selectPoint = (x,y) => {
return s.viewport + ",{ offsetX :" + x + ", offsetY :" + y + "}"
}
Run Code Online (Sandbox Code Playgroud)
或(两者都不起作用)
export function selectPoint(x,y){
return s.viewport + ",{ offsetX :" + x + ", offsetY :" + y + "}"
}
Run Code Online (Sandbox Code Playgroud)
Testfile.js(实用功能在起作用)
import { selectPoint } from …
Run Code Online (Sandbox Code Playgroud) 我想做的是打印/使用Polyline属性的值。
<Polyline points="x,y x,y x,y x,y">
Run Code Online (Sandbox Code Playgroud)
我尝试用这些方法来获取它们:
这是一个实用函数
export const getPointAttribute = async () => {
const polyline = s.polyline;
const polylineData = ClientFunction(() => polyline().attributes, {
dependencies: { polyline }
});
return polylineData
}
Run Code Online (Sandbox Code Playgroud)
这是测试脚本里面的
test('', async (t) => {
console.log(u.getPointAttribute())
}
Run Code Online (Sandbox Code Playgroud)
或者
test('', async (t) => {
console.log(s.polyline.getAttribute('points'));
}
Run Code Online (Sandbox Code Playgroud)
我将我的选择器包括在外部
import * as s from '../utilities/selectors';
Run Code Online (Sandbox Code Playgroud)
但我得到的只是控制台日志中输出的承诺
承诺 { }
或者
ReExecutablePromise { _then: [], _fn: [函数], _taskPromise: null }
任何帮助表示赞赏!