While writing tests with TestCafe i'm creating utility functions, but there seems to be a problem when using the Selector('') method inside any function.
The Selector('') method works fine inside test files and also when importing from another file (utility_selectors.js). I think I need to include something inside the function, but I'm stuck and can't seem to find the solution.
My goal is to create a function to select mouse click coordinates.
Utility_selectors.js
import { Selector } from 'testcafe';
export const viewport = Selector('.viewport').find('canvas');
Utility_functions.js
import * as s from './selectors.js';
export const selectPoint = (x,y) => {
return s.viewport + ",{ offsetX :" + x + ", offsetY :" + y + "}"
}
OR (both don't work)
export function selectPoint(x,y){
return s.viewport + ",{ offsetX :" + x + ", offsetY :" + y + "}"
}
Testfile.js (utility function in action)
import { selectPoint } from '../utilities/functions.js';
test('example utility function', async (t) => {
await t.click(selectPoint(100,200));
});
When executing, the following error occurs in cmd:
SyntaxError: Failed to execute 'querySelectorAll' on 'Document': 'function
__$$clientFunction$$() {
const testRun = builder._getTestRun();
const callsite = (0, _getCallsite.getCallsiteForMethod)(builder.callsiteNames.execution);
const args = [];
// OPTIMIZATION: don't leak `arguments` object.
for (let i = 0; i < arguments.length; i++) args.push(arguments[i]);
return builder._executeCommand(args, testRun, callsite);
},{ offsetX :100, offsetY :200}' is not a valid selector.
So long story short, I want to include the TestCafe's Selector('') method inside a utility function.
Thanks in advance!
t.click(s.viewport, {offsetX: 100, offsetY: 200})
? – Snowmobile