Read JSON response
1) When I visit this URL 'http:example.com/fruits', it hits an endpoint 'http:example.com/v1/collections/fruits' and I see JSON in the browser network response:
{
"total":3,
"page":1,
"pageSize":24,
"rows":[
{
"id":19,
"title":"Apple"
},
{
"id":21,
"title":"Grape",
},
{
"id":6,
"title":"Orange",
},
]
}
Run Code Online (Sandbox Code Playgroud)
2) I want to pick up the first title - Apple and pass it to a selector and click on it
我正在使用TestCafe,并想确定checkbox元素是否存在。在HTML元素中,如果该复选框已被选中,则该属性checked存在,否则不存在。如何确定使用TestCafe?
我使用了TestCafe中可用的功能- .hasAttribute('checked')但返回的是undefined。
选中此复选框时,以下是HTML代码:
<input class="jss1523" tabindex="-1" type="checkbox" data-indeterminate="false" value checked>
取消选中此复选框时,这是HTML代码:
<input class="jss1523" tabindex="-1" type="checkbox" data-indeterminate="false" value>
如何使用TestCafe解决此问题?
我有一个使用元标记的测试套件,我正在尝试运行特定的测试。
我尝试使用以下方法:
.filter((fixturePath, fixtureName, testMeta) => {
return testMeta.smoke == 'true';
})
Run Code Online (Sandbox Code Playgroud)
跑步者.ts
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then((tc) => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/specs/**/*.spec.ts'])
.filter((fixturePath, fixtureName, testMeta) => {
return testMeta.smoke == 'true';
})
.browsers(['chrome'])
.reporter([
'list'
])
.run();
})
.then((failedCount) => {
console.log('Tests failed: ' + failedCount);
testcafe.close();
});
示例测试
test('Login with correct credentials', async (t) => {
await LoginPage.login(data.users.userPrivate.username, data.users.userPrivate.password);
await t.expect(Helper.getLocation()).contains(endpoints.personalAreaOverview);
}).meta('regression', 'true').meta('smoke', 'true'); … 我在通过黄瓜运行Testcafe时遇到问题。无论出于何种原因,当我通过黄瓜运行testCafe时,即使测试失败,该过程也始终会以退出代码0退出。
如果我通过黄瓜来操纵木偶戏,我不会遇到这个问题。我认为这种行为是由于我在我的钩子文件中设置了东西的方式造成的,在该文件中我没有正确解释测试咖啡馆出口代码。
在我的hooks文件中,我将在我的Before钩子中创建一个testCafe运行器,然后在我的after钩子中将其关闭。
我想知道我可以使用什么命令来获取TestCafe退出代码,而我却找不到任何信息。
例如,退出代码是从close函数返回的还是什么?
我正在尝试TestCafe使用以下代码从现有页面返回上一页:
await t.pressKey('alt+left');
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。页面没有变化。但是,当我在浏览器中进行验证时,手动进行似乎可以正常工作。
有人可以帮我这个忙,我希望能够仅使用键盘击键返回上一页。
我刚刚开始使用 testcafe,到目前为止,我发现文档有助于进行测试和自动化 E2E。
我想断言 td 中是否存在一个值,如下所示:
async checkBankAccount(accountNumber, currencyCode){
const formatedAccount = formatBankAccount(accountNumber, currencyCode);
console.log(formatedAccount);
await t
.expect(Selector('td').withText(formatedAccount).innerText).eql(formatBankAccount);
}
Run Code Online (Sandbox Code Playgroud)
我遇到以下错误:
未指定断言方法。
我想断言我的 HTML 中是否存在包含 formatedAccount 文本的 td。
谢谢
我正在尝试在隔离模式下运行一个简单的测试:
test.only("test", async t => {
await t.expect(true).notOk();
});
这是我的跑步者
const createTestCafe = require("testcafe");
let testcafe = null;
const runTests = (testFiles) => {
const runner = testcafe.createRunner();
return runner
.src(testFiles)
.browsers(["chrome"])
.run({
quarantineMode: true
});
};
createTestCafe("localhost", 1337, 1338)
.then(tc => {
testcafe = tc;
return runTests(["src/tests/"])
})
.then(() => testcafe.close());
Run Code Online (Sandbox Code Playgroud)
但测试仍然只运行一次。我还尝试在我的 package.json 文件附近添加配置文件,并在我的 runner 文件附近添加配置文件,但仍然没有结果。
如何使用 testcafe 重新加载当前页面?我发现
.eval(() => location.reload(true))
Run Code Online (Sandbox Code Playgroud)
但看起来像旧代码,目前的TestCafe 不理解这一点。(无功能错误)
设想:
\n\n我使用 API 运行封装在代码中的 TestCaf\xc3\xa9 \n我有一个想要参数化的测试,使用不同的动态值进行测试。
\n\n问题
\n\nTestcaf\xc3\xa9 不支持向测试发送参数。有没有办法注入值?
\n我正在使用react-virtualized来获取一长串(1000 多个)项目列表以供选择。我正在尝试设置一个端到端测试,需要单击当前未渲染的元素之一。
通常,我会简单地使用类似的东西:
await t.click(
ReactSelector('ListPage')
.findReact('ListItem')
.nth(873) // or .withText(...) or .withProps(...)
)
Run Code Online (Sandbox Code Playgroud)
但由于只渲染了 s 的一小部分ListItem,TestCafe 无法找到所需的元素。
我一直在试图弄清楚如何使用 TestCafe 的ClientFunction滚动列表容器,以便ListItem呈现所需的内容。
但是,我遇到了一些问题:
Selector并ClientFunction修改DOM元素的scrollTop?或者我是否必须直接通过 DOM 重新查询元素?ListItems 的高度不同,滚动位置不是索引x项目高度的简单计算。如何在此函数中不断更新/滚动,直到所需的内容Selector可见?automated-tests typescript reactjs react-virtualized testcafe
testcafe ×10
e2e-testing ×6
testing ×6
javascript ×4
typescript ×2
assertion ×1
automation ×1
dom ×1
exit-code ×1
inject ×1
json ×1
node.js ×1
page-refresh ×1
reactjs ×1