testcafe高阶选择器

问题描述

我正在尝试创建一个高阶选择器,可以通过更改text参数来重用该选择器。在下面的代码段中,当我尝试使用t.click执行actualSelector时,它无法正常工作。当我用控制台记录actualSelector的值时,我看到整个项目的值都已打印。

似乎我没有正确使用它。您能帮我吗?

例如

const testItemNameGenericSelector = (itemName) =>
    Selector(
      ".ms-Callout-container .ms-Callout-main  div div"
    )
  .withText(itemName);
...
  const itemNametoSelect = "Test Item-8ab1ec12-e719-4ab6-a0a3-ed538143d6d3";
  const actualSelector = testItemNameGenericSelector(itemNametoSelect)
...
  console.log(`selecting ${await actualSelector().textContent}`)

下面是此测试的完整testcafe代码


fixture`Getting Started`
  .page // declare the fixture
`https://hasans30.github.io/testpage/dropdown.html`; // specify the start page

//then create a test and place your code there
test("My first test",async (t) => {

   const testItemNameGenericSelector = (itemName) =>
    Selector(
      ".ms-Callout-container .ms-Callout-main  div div"
    )
  .withText(itemName);
  const buttonSelector = Selector('.ms-Button-label');
  const selectedValue = Selector('.ms-Dropdown-title');

  const itemNametoSelect = "Test Item-8ab1ec12-e719-4ab6-a0a3-ed538143d6d3";
  const actualSelector = testItemNameGenericSelector(itemNametoSelect);


  await t.click(buttonSelector,{speed:0.51})
  console.log(`selecting ${await actualSelector().textContent}`)

  await t.click(actualSelector,{speed:0.51})
  await t.expect(await selectedValue().textContent).eql(itemNametoSelect);

});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)