fix(course-package): use document.cookie instead of addCookies for teacher UI test
addCookies uses CDP Storage.setCookies which rejects some JWT cookies with "Invalid cookie fields" on certain Chromium versions. Switching to document.cookie bypasses CDP validation entirely. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -268,12 +268,18 @@ test.describe('课包(course_package)', () => {
|
||||
timeout: 60_000,
|
||||
});
|
||||
|
||||
const teacherDomain = '.moicen.com';
|
||||
await page.context().addCookies([
|
||||
{ name: 'HtyTeacherToken', value: jwt!, domain: teacherDomain, path: '/' },
|
||||
{ name: 'CurrentUserRole', value: currentRole, domain: teacherDomain, path: '/' },
|
||||
{ name: 'CurrentUserName', value: currentUserName, domain: teacherDomain, path: '/' },
|
||||
]);
|
||||
// 使用 document.cookie 设置(addCookies 在某些 Chromium 版本上返回 Invalid cookie fields)
|
||||
await page.evaluate(
|
||||
({ token, role, userName }) => {
|
||||
const d = new Date();
|
||||
d.setFullYear(d.getFullYear() + 1);
|
||||
const attrs = `; path=/; domain=.moicen.com; expires=${d.toUTCString()}`;
|
||||
document.cookie = `HtyTeacherToken=${encodeURIComponent(token)}${attrs}`;
|
||||
document.cookie = `CurrentUserRole=${encodeURIComponent(role)}${attrs}`;
|
||||
document.cookie = `CurrentUserName=${encodeURIComponent(userName)}${attrs}`;
|
||||
},
|
||||
{ token: jwt!, role: currentRole, userName: currentUserName },
|
||||
);
|
||||
await page.evaluate(
|
||||
({ orgId }) => {
|
||||
if (orgId) window.localStorage.setItem('CurrentOrgId', orgId);
|
||||
|
||||
Reference in New Issue
Block a user