javascript - testcafe 高阶选择器
问题描述
我正在尝试创建一个高阶选择器,我可以通过更改文本参数来重用它。在下面的代码段中,当我尝试执行t.click
usingactualSelector
时,它没有按预期工作。当我控制台记录 的值时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);
});
解决方案
推荐阅读
- r - 跨列识别模式并汇总分数
- java - MyBatis 传递多个参数时,如何判断参数属性是否存在?
- android - 如何启动服务器和应用程序之间的通信?
- javascript - 检查元素是否是 offsetParent
- sql - 查询性能 - 获取未从行中获取子文件的行
- iframe - 站点和 iframed 站点之间的通用登录
- json - 读取不带引号的 json 文件的字母数字字段
- typescript - Typescript 在构建时抛出错误,但在 cmd 中执行时没有错误
- python - 如何使用 Scipy 的 solve_ivp 在积分时评估函数
- jquery - 表单不会在第一次之后阻止默认