@@ -896,30 +896,33 @@ class Playwright extends Helper {
896
896
try {
897
897
this . debugSection ( 'Playwright' , `registering custom locator strategy: ${ strategyName } ` )
898
898
899
- // Create a selector engine for this custom strategy
900
- const engine = {
901
- query ( root , selector ) {
899
+ // Convert the function to a string and create the selector engine content
900
+ const functionString = strategyFunction . toString ( )
901
+ const selectorEngine = `
902
+ exports.query = (root, selector) => {
902
903
try {
903
- const result = strategyFunction ( selector , root )
904
- return Array . isArray ( result ) ? result [ 0 ] : result
904
+ const strategyFunction = ${ functionString } ;
905
+ const result = strategyFunction(selector, root);
906
+ return Array.isArray(result) ? result[0] : result;
905
907
} catch (error) {
906
- console . warn ( ` Error in custom locator ' ${ strategyName } ':` , error )
907
- return null
908
+ console.warn(' Error in custom locator " ${ strategyName } ":' , error);
909
+ return null;
908
910
}
909
- } ,
910
-
911
- queryAll ( root , selector ) {
911
+ };
912
+
913
+ exports. queryAll = (root, selector) => {
912
914
try {
913
- const result = strategyFunction ( selector , root )
914
- return Array . isArray ( result ) ? result : result ? [ result ] : [ ]
915
+ const strategyFunction = ${ functionString } ;
916
+ const result = strategyFunction(selector, root);
917
+ return Array.isArray(result) ? result : result ? [result] : [];
915
918
} catch (error) {
916
- console . warn ( ` Error in custom locator ' ${ strategyName } ':` , error )
917
- return [ ]
919
+ console.warn(' Error in custom locator " ${ strategyName } ":' , error);
920
+ return [];
918
921
}
919
- } ,
920
- }
922
+ };
923
+ `
921
924
922
- await playwright . selectors . register ( strategyName , engine )
925
+ await playwright . selectors . register ( strategyName , { content : selectorEngine } )
923
926
} catch ( error ) {
924
927
console . warn ( `Failed to register custom locator strategy '${ strategyName } ':` , error )
925
928
}
0 commit comments