Hey guys! I been wanting to start e2e testing for a crucial project for work (in fact I have a basic setup already). The thing is that there are things that are not clear to me so I wanted to ask you for advice.
For now these are the things that I don't know and prevents me for starting to write tests.. I have a lot of experience developing but never in my life felt the need to test something or even learn testing.. but in this project in particular I really feel the need of some form of automated testing since manual testing really takes a lot of our time and been wanting to do something about it.
If there's more context that I can give please let me know. Thanks in advance ๐ค
This thread is trying to answer question "Does the user need a special setup for a react web app with i18n, and do they need to test internationalization specifically? Can they use mocking in Playwright to test the frontend without depending on the backend response?"
Related Ask AI answer for "What is the process of setting up and testing internationalization in a React web app using Playwright?".
First, you'll need to set up your React app for internationalization (i18n). This involves adding libraries like react-i18next
or react-intl
.
// Install the library
npm install react-i18next i18next
Next, create translation files or use an online service for your app's text content.
// Example of a translation file
{
"welcome": "Welcome to our app!",
"logout": "Log out"
}
With @playwright/test, you can mock different language settings and check if the correct translations are displayed.
import { test } from '@playwright/test';
test('displays correct translation', async ({ page }) => {
await page.goto('https://ray.run');
// Mock network requests or modify browser settings here
// Check if the correct translation is displayed
});
You can also mock backend responses, allowing you to test the frontend without depending on the backend.
test('mocks backend response', async ({ page }) => {
await page.route('https://ray.run/api/user', route => {
route.fulfill({
status: 200,
body: JSON.stringify({ name: 'John Doe' }),
});
});
await page.goto('https://ray.run');
// Check if the frontend handles the mocked response correctly
});
This way, you can thoroughly test your app's i18n features without relying on real backend services. For more tips on efficient testing with Playwright, check out this blog post.
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].