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" |
It 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.com/';
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 })();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With