admin管理员组文章数量:1021912
I want to assert that I am on the "Home Page" after the user is logged in the Home Page. I made a function 'onPage' to return me the contains of the URL.
Here is the code:
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);
}
And here is my BDD scenario:
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" |
I want to assert that I am on the "Home Page" after the user is logged in the Home Page. I made a function 'onPage' to return me the contains of the URL.
Here is the code:
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);
}
And here is my BDD scenario:
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" |
Share
Improve this question
edited Jul 16, 2019 at 7:10
Alex Skorkin
4,2743 gold badges27 silver badges48 bronze badges
asked Jul 15, 2019 at 7:01
AlexMosAlexMos
811 silver badge6 bronze badges
2 Answers
Reset to default 5It looks like you are using some TestCafe-based BDD framework, so I do not precisely know how to do it with your syntax. However, in TestCafe this issue can be easily solved using the ClientFunctions mechanism.
Please see the following code:
const getURL = ClientFunction(() => window.location.href);
const myUrl = await getURL();
Then you can use the myUrl
value in your assertions.
UPDATE:
Here is a working example which includes the use of TestCafe syntax:
import { ClientFunction } from 'testcafe';
const URL = 'https://example./';
const getURL = ClientFunction(() => window.location.href);
fixture`My Fixture`
.page(URL);
test('Assert page URL', async t => {
await t.expect(getURL()).eql(URL);
});
You'll need to implement something similar. For example, you can use the approach suggested in the error text: const myUrl = await getURL.with({ boundTestRun: testController })();
to get the url outside assert statement, you can call it like:
let myUrl = await getURL.with({ boundTestRun: t })();
I want to assert that I am on the "Home Page" after the user is logged in the Home Page. I made a function 'onPage' to return me the contains of the URL.
Here is the code:
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);
}
And here is my BDD scenario:
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" |
I want to assert that I am on the "Home Page" after the user is logged in the Home Page. I made a function 'onPage' to return me the contains of the URL.
Here is the code:
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);
}
And here is my BDD scenario:
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" |
Share
Improve this question
edited Jul 16, 2019 at 7:10
Alex Skorkin
4,2743 gold badges27 silver badges48 bronze badges
asked Jul 15, 2019 at 7:01
AlexMosAlexMos
811 silver badge6 bronze badges
2 Answers
Reset to default 5It looks like you are using some TestCafe-based BDD framework, so I do not precisely know how to do it with your syntax. However, in TestCafe this issue can be easily solved using the ClientFunctions mechanism.
Please see the following code:
const getURL = ClientFunction(() => window.location.href);
const myUrl = await getURL();
Then you can use the myUrl
value in your assertions.
UPDATE:
Here is a working example which includes the use of TestCafe syntax:
import { ClientFunction } from 'testcafe';
const URL = 'https://example./';
const getURL = ClientFunction(() => window.location.href);
fixture`My Fixture`
.page(URL);
test('Assert page URL', async t => {
await t.expect(getURL()).eql(URL);
});
You'll need to implement something similar. For example, you can use the approach suggested in the error text: const myUrl = await getURL.with({ boundTestRun: testController })();
to get the url outside assert statement, you can call it like:
let myUrl = await getURL.with({ boundTestRun: t })();
本文标签: javascriptI cant get the expected URL with TestCafeStack Overflow
版权声明:本文标题:javascript - I cant get the expected URL with TestCafe - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745578820a2157186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论