Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid cookie fields when i run authorization tests #8344

Open
silkdemon opened this issue Nov 21, 2024 · 1 comment
Open

Error: Invalid cookie fields when i run authorization tests #8344

silkdemon opened this issue Nov 21, 2024 · 1 comment
Labels
STATE: Need clarification An issue lacks information for further research. TYPE: bug The described behavior is considered as wrong (bug).

Comments

@silkdemon
Copy link

silkdemon commented Nov 21, 2024

What is your Scenario?

this looks like the same issue as here: #8253

i run four tests with authorization where i get and set Cookies in parallel also using test.before hooks

What is the Current behavior?

i get an error when i remove page function in fixture, when i put it back error dissapears

  1) - Error in test.before hook -
      Error: Invalid cookie fields

What is the Expected behavior?

api test succesfully passed

What is the public URL of the test page? (attach your complete example)

sorry i cannot find good website example with Bearer token

What is your TestCafe test code?

import { fixture, t } from "testcafe";
import { Role as createRole } from 'testcafe';

interface ResponseCommonDto {
  token: string;
  isAccountVerified: boolean;
}

 const initPage = 'https://example.com';

 const postJsonWithResult = async <T, R>(requestUrl: string, value: T): Promise<R> => {
  await initAccessToken(this._useAuth);

  const response = await t.request({
      url: requestUrl,
      method: 'POST',
      body: value,
      headers: this._authProvider.getHeaders(),
  });

  const result = (await response.body) as unknown as R;

  return result;
};

const registerUser = async (body): Promise<ResponseDto> => {
  return this._coreProvider.postJsonWithResult('/register', body);
}

const commonUser = createRole(initPage, async (t) => {
  const requestUserCredentials = {}

  const registerUserResult = await registerUser(requestUserCredentials);
  const token = registerUserResult;

  await t.setCookies({ name: 'EMAIL_COOKIES', value: email });
  await t.setCookies({ name: 'PASSWORD_COOKIES', value: password });
  await t.setCookies({ name: 'TOKEN_COOKIES', value: token });
});

const getCommonUserCredentials = async (t: TestController): Promise<UserCredentials> => {
  await t.useRole(commonUser);

  const tokenCookies = await t.getCookies(TOKEN_COOKIES);
  const emailCookies = await t.getCookies(EMAIL_COOKIES);
  const passwordCookies = await t.getCookies(PASSWORD_COOKIES);

  if (!tokenCookies[0] || !emailCookies[0] || !passwordCookies[0]) {
      throw new Error('error');
  }

  if (!tokenCookies[0].value || !emailCookies[0].value || !passwordCookies[0].value) {
      throw new Error('error');
  }

  const token = tokenCookies[0].value;
  const email = emailCookies[0].value;
  const password = passwordCookies[0].value;

  return { token, email, password };
};

fixture("Getting Started")
// .page("https://playwright.dev/");

test.before(async (t)=> {
  const { token } = await getCommonUserCredentials(t);
  t.ctx.token = token;
})("My first test", async (t) => {
  const { token } = t.ctx;
// ...test
});

test.before(async (t)=> {
  const { token } = await getCommonUserCredentials(t);
  t.ctx.token = token;
})("My first test", async (t) => {
  const { token } = t.ctx;
// ...test
});

test.before(async (t)=> {
  const { token } = await getCommonUserCredentials(t);
  t.ctx.token = token;
})("My first test", async (t) => {
  const { token } = t.ctx;
// ...test
});

Your complete configuration file

no

Your complete test report

No response

Screenshots

image

Steps to Reproduce

  1. Write tests with next structure: fixture WITHOUT page() initialization, test.before() hook with classic registration scenario inside using t.setCookies and t.getCookies functions
  2. Run it in parallel on latest chromium (131) in headless mode

TestCafe version

3.7.0

Node.js version

v20.14.0

Command-line arguments

npx testcafe edge:headless .\test.ts -c 4

Browser name(s) and version(s)

Edge or Chrome 131.0.0.0

Platform(s) and version(s)

Windows 11

Other

it is strange that everything works when i add fixture.page() function to my api tests, when i remove it i receive this error

@silkdemon silkdemon added the TYPE: bug The described behavior is considered as wrong (bug). label Nov 21, 2024
@testcafe-need-response-bot testcafe-need-response-bot bot added the STATE: Need response An issue that requires a response or attention from the team. label Nov 21, 2024
@Bayheck Bayheck added STATE: Need simple sample A simple sample is required to examine the issue. and removed STATE: Need response An issue that requires a response or attention from the team. labels Nov 25, 2024
Copy link

Thank you for submitting a bug report. We would love to help you investigate the issue. Please share a simple code example that reliably reproduces the bug. For more information, read the following article: How To Create a Minimal Working Example When You Submit an Issue. We look forward to your response.

@github-actions github-actions bot added STATE: Need clarification An issue lacks information for further research. and removed STATE: Need simple sample A simple sample is required to examine the issue. labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATE: Need clarification An issue lacks information for further research. TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

2 participants