Javascript 未能将选择器提供给ClientFunction

Javascript 未能将选择器提供给ClientFunction,javascript,testing,automated-tests,e2e-testing,testcafe,Javascript,Testing,Automated Tests,E2e Testing,Testcafe,请看下面的结构。 有没有办法让“示例1”发挥作用?这样做的目的是避免在“测试”类中存储“css选择器字符串” MyAccount.js clientFunctions.js 示例1。(失败) 示例2。(通过) 问题是浏览器的方法不适用于TestCafe API。请按以下方式更改MyAccount类,以使示例正常工作: 导出类MyAccount{ 构造函数(){ 此.box={ 第1项:“第01项”, 第2项:“第2项” } } } 您可以通过该选项将选择器传递到ClientFunction中,然

请看下面的结构。
有没有办法让“示例1”发挥作用?这样做的目的是避免在“测试”类中存储“css选择器字符串”

MyAccount.js

clientFunctions.js

示例1。(失败)

示例2。(通过)


问题是浏览器的方法不适用于TestCafe API。请按以下方式更改
MyAccount
类,以使示例正常工作:

导出类MyAccount{
构造函数(){
此.box={
第1项:“第01项”,
第2项:“第2项”
}
}
}

您可以通过该选项将选择器传递到ClientFunction中,然后通过调用方法将其覆盖。

是的,我可以使用这种方法作为解决方案,但在这种情况下,我将无法在这样的测试中引用页面元素//wait t t.click(myacount.box.item_1)//,而必须使用//wait t t t t.click(选择器(myAccount.box.item_1))/。但无论如何,似乎没有更好的选择。谢谢您的回答。


    import { Selector} from "testcafe";

    export class MyAccount {
      constructor() { 
        this.box = {
          item_1: Selector("#item01");
          item_2: Selector("#item02");
        }
      }
    }



    import { ClientFunction } from 'testcafe';

    export const scrollInto = ClientFunction((selector) => {
        var element = window.document.querySelector(selector);    
        element.scrollIntoView();
    });



    import { MyAccount } from "../MyAccount";
    import { scrollInto } from "../clientFunctions";

    const myAccount = new MyAccount();

    fixture("Feature A").page(process.env.url);

    test("Test 01", async t => {

      await scrollInto(myAccount.box.item_1);

    });



    import { MyAccount } from "../MyAccount";
    import { scrollInto } from "../clientFunctions";

    const myAccount = new MyAccount();

    fixture("Feature A").page(process.env.url);

    test("Test 01", async t => {

      await scrollInto("#item01");

    });