Rayrun

How do I send multiple post requests within a single test block in Playwright Test?

Answer

Sure, you can send two post requests in a single test block with @playwright/test. It has a built-in request fixture that respects configuration options like baseURL or extraHTTPHeaders.

Here's how you can do it:

First, define two separate tests within the same test block. Each test should contain its own post request with unique data for each issue type. For example, one post request could be for a bug report and another for a feature request.

import { test } from '@playwright/test';

test('create issues', async ({ request }) => {
  const bugReport = await request.post('https://ray.run/api/bug-report', { json: { title: 'Bug report' } });
  const featureRequest = await request.post('https://ray.run/api/feature-request', { json: { title: 'Feature request' } });

  // Assertions to verify the success of the requests
  expect(bugReport.ok()).toBeTruthy();
  expect(featureRequest.ok()).toBeTruthy();
});

After sending both requests, use assertions to verify their success. Check if each response was ok() and then use expect.objectContaining() to ensure the expected data was returned.

Remember, when making multiple requests within a single test block, keep them logically related to avoid unnecessary complexity.

For more insights on efficient testing with Playwright, check out Tips for Writing Efficient Playwright Test Scripts.

References

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Questions

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].