Closed dthisner closed 5 years ago
Try using .with({ boundTestRun: t })
e.g
const getLocation = ClientFunction(() => window.location.href);
await t.expect(getLocation.with({ boundTestRun: t })()).contains(url);
Thanks, I will give it a shot :)
@eddiegroves Thanks for your answer, I am getting:
ReferenceError: window is not defined
at Server.ClientFunction (/Users/dennis/Projects/src/applydigital.co/website-agi/AgiWebsite/frontend/src/tests/e2e/stepDefinitions/brands/westeel.js:79:60)
at Object.onceWrapper (events.js:273:13)
at Server.emit (events.js:187:15)
at Server.EventEmitter.emit (domain.js:441:20)
at emitListeningNT (net.js:1324:10)
at process._tickCallback (internal/process/next_tick.js:63:19)
Code:
Then(/^I can see that the URL contains "(.+)"$/, async (t, [URL]) => {
const ClientFunction = require('testcafe');
const getLocation = ClientFunction(() => window.location.href);
await t.expect(getLocation.with({ boundTestRun: t })()).contains(URL);
});
@dthisner
This example should work - ClientFunction
needs to be imported correctly:
const { Given, Then } = require('cucumber');
const { ClientFunction } = require('testcafe');
Given("I open Google's search page", async t => {
await t.navigateTo('https://www.google.com');
});
Then(/^I can see that the URL contains "(.+)"$/, async (t, [url]) => {
const getLocation = ClientFunction(() => window.location.href);
await t.expect(getLocation.with({ boundTestRun: t })()).contains(url);
});
Feature: The big search feature
I want to open Google
Scenario: Open Google
Given I open Google's search page
Then I can see that the URL contains "google.com"
works like a charm! thank you :)
Hello,
Thanks again for this amazing plugin :)
I am stuck, I am trying to verify that the URL is correct and I tried require "ClientFunction" with no luck.
This is what I got:
I am getting following error:
What am I doing wrong?
I also tried:
document.location.href
Then I am getting: