将当前URL写入TestCafe中的控制台

ASE*_*ASE 6 console automated-tests e2e-testing testcafe

我有一个变量“ currentPage”,我想将其设置为运行页面上的当前URL。但是要查看URL是否正确,我想将其打印到控制台。我尝试执行的操作都会不断出现“未定义”,“对象”,... ...另一方面,如果我使用“ await t.expect(...)”方法并使其失败,则会看到所需的URL。

const getURL = ClientFunction(() => window.location.href);
console.log(getURL) //does not work
console.log(getURL()) //does not work
Run Code Online (Sandbox Code Playgroud)

我可以将其写入控制台输出吗?如果是这样的话,我想也应该可以做类似“ currentPage = getURL()”的事情,但是我得到:

current page function __$$clientFunction$$() {
Run Code Online (Sandbox Code Playgroud)

Ale*_*aev 6

await在调用ClientFunction之前,您已经错过了关键字。请参考http://devexpress.github.io/testcafe/documentation/test-api/obtaining-data-from-the-client.html#executing-client-functions。我建议您以以下方式编写它:

const url = await getURL();
console.log(url);
Run Code Online (Sandbox Code Playgroud)

  • 我当然做了。谢谢,效果很好。 (2认同)