Closed jawadst closed 1 year ago
I did some more testing and the test passes when enabling proxyless mode.
Hi @jawadst,
I managed to reproduce the issue. But it happens only if you set cookies with ClientFunction
or t.eval
. If you set cookies directly on the page, the getCookies
method will return them. I recommend you replace setting cookies with ClientFunction
or t.eval
to the setCookies
method.
Hi @Aleksey28,
Thanks for taking a look. I see the same problem if I set the cookie from a test page instead of via t.eval
in the test.
Example HTML:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript">
document.cookie = 'favorite_food=tripe';
</script>
</head>
<body></body>
</html>
And the test that is failing:
fixture`FixtureCookie`.page('http://localhost:8081/page.html');
test('Creates a cookie', async t => {
let cookies = await t.getCookies();
console.log({ cookies });
await t.expect(cookies.length).gte(1);
});
Here again, the test is failing while the cookie shows in the DevTools:
I wrote those tests as the smallest reproducible test cases that would fail to submit them here but I am generally seeing that TestCafe misses cookies in getCookies
when testing with our full application as well (that sets cookies with document.cookie
in JS). We generally see some cookies but not all of them. Could it be related to setting cookies client-side via document.cookie
?
I managed to reproduce the issue. We will update this thread once we have any news.
As a workaround, you can use the --experimental-proxyless
option. We are actively working on this mode.
Hi @jawadst,
This issue is not reproduced with combination of testcafe@3.0.1
and the Google Chrome browser. Feel free to reopen this issue if you encounter it in other browsers.
What is your Scenario?
I am trying to test that a specific cookie is created (in JavaScript) by the page that I am testing.
What is the Current behavior?
getCookies
returns an empty arrayWhat is the Expected behavior?
getCookies
should return the cookie that was created by the tested pageWhat is your public website URL? (or attach your complete example)
No public URL ; see TestCafe test code that should be self sufficient
What is your TestCafe test code?
Your complete configuration file
No config
Your complete test report
Running tests in:
Chrome 110.0.0.0 / Ventura 13
FixtureCookie { cookies: [] } ✖ Creates a cookie
1) AssertionError: expected 0 to be at least 1
expected - actual
-0 +1
Browser: Chrome 110.0.0.0 / macOS 10.15.7
5 | 6 | let cookies = await t.getCookies('favorite_food'); 7 | 8 | console.log({ cookies }); 9 |
at (/secure-cookies.js:10:34)
at asyncGeneratorStep (/secure-cookies.js:1:114)
at _next (/secure-cookies.js:1:452)
Screenshots
The cookie correctly appears in Chrome Devtools:
Steps to Reproduce
Simply run the provided test
TestCafe version
2.3.0
Node.js version
16.16.0
Command-line arguments
testcafe chrome /secure-cookies.js
Browser name(s) and version(s)
Chrome 110
Platform(s) and version(s)
Mac OS
Other
No response