Ale*_*Mos 5 javascript automation automated-tests e2e-testing testcafe
我想在用户登录主页后断言我在“主页”上。我创建了一个函数“onPage”来返回 URL 的内容。
这是代码:
function onPage (secondPage, URL) {
if (secondPage === 'Home Page') {
return await
testController.expect(URL.textContent).contains('URL-of-the-Home-Page');
}
}
Then(THEN.THE_HOME_PAGE_IS_OPENED, async (secondPage) => {
await testController.expect(onPage(secondPage, URL)).eql(true);
}
Run Code Online (Sandbox Code Playgroud)
这是我的 BDD 场景:
Scenario Outline: User is logged in the
Given the <namePage> is opened
And the user populate <username>
And the user populate <password>
When the user clicks on Login button
Then he is on <secondPage>
Examples:
| namePage | username | password | secondPage |
| "Login Page" | "admin" | "admin" | "Home Page" |
Run Code Online (Sandbox Code Playgroud)
看起来你正在使用一些基于 TestCafe 的 BDD 框架,所以我不知道如何使用你的语法来做到这一点。然而,在 TestCafe 中,这个问题可以使用ClientFunctions机制轻松解决。
\n\n请看下面的代码:
\n\nconst getURL = ClientFunction(() => window.location.href);\nconst myUrl = await getURL();\nRun Code Online (Sandbox Code Playgroud)\n\nmyUrl然后您可以在断言中使用该值。
更新:
\n\n这是一个工作示例,其中包括 TestCafe 语法的使用:\xc2\xa0
\n\nimport { ClientFunction } from \'testcafe\';\n\xc2\xa0\nconst URL = \'https://example.com/\';\nconst getURL = ClientFunction(() => window.location.href);\n\xc2\xa0\nfixture`My Fixture`\n .page(URL);\n\xc2\xa0\ntest(\'Assert page URL\', async t => {\n await t.expect(getURL()).eql(URL);\n});\nRun Code Online (Sandbox Code Playgroud)\n\n您需要实现类似的东西。例如,您可以使用错误文本中建议的方法:const myUrl = await getURL.with({ boundTestRun: testController })();