Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write current URL to console in TestCafe

I have a variable "currentPage" which I want to set to the current URL on the running page. But to see that the URL is correct I want to print it to the console. What ever I try I keep getting "not defined", "object", ... If I on the other hand use the "await t.expect(...)" method and make it fail then I see the wanted URL.

const getURL = ClientFunction(() => window.location.href);
console.log(getURL) //does not work
console.log(getURL()) //does not work

Can I write it to console output? If so then I guess it should also be possible to do something like "currentPage = getURL()" but I get:

current page function __$$clientFunction$$() {
like image 622
ASE Avatar asked Oct 23 '18 15:10

ASE


Video Answer


1 Answers

You've missed the await keyword before calling ClientFunction. Please refer to http://devexpress.github.io/testcafe/documentation/test-api/obtaining-data-from-the-client.html#executing-client-functions.   I suggest you write it in the following manner:

const url = await getURL();
console.log(url);
like image 152
Alex Kamaev Avatar answered Sep 21 '22 20:09

Alex Kamaev