Не удалось передать селектор в ClientFunction - PullRequest
0 голосов
/ 22 апреля 2020

Пожалуйста, посмотрите на структуру ниже. Есть ли способ заставить 'Пример 1' работать? Идея состоит в том, чтобы не хранить 'css строку селектора' в классе 'test'.

MyAccount. js



    import { Selector} from "testcafe";

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

clientFunctions. js



    import { ClientFunction } from 'testcafe';

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

ПРИМЕР 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(myAccount.box.item_1);

    });

ПРИМЕР 2. (ПРОЙДЕН)



    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");

    });

1 Ответ

2 голосов
/ 23 апреля 2020

Проблема в том, что метод браузера querySelector не работает с API-интерфейсом TestCafe Selector. Пожалуйста, измените класс MyAccount следующим образом, чтобы ваш пример работал:

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