How to Test Hindi & Indian Language Layouts in Chromatic
In this article
This guide walks you through testing Hindi and other Indian language keyboard layouts in Chromatic, a visual testing tool for UI components. You'll learn how to set up a test that captures screenshots of your app with Indian language input, verify that text renders correctly, and catch layout issues before they reach production. No prior Chromatic experience is needed, but you should have a basic understanding of your project's component structure.
What You'll Need
- A Chromatic account and a project connected to Chromatic (free tier works).
- Your project's repository cloned locally, with Chromatic CLI installed (usually as a dev dependency).
- A component or page that accepts text input (e.g., a search bar, form field, or text area).
- Access to a browser that supports Indian language input (Chrome, Firefox, or Edge all work).
- Basic familiarity with your test runner (like Storybook or Cypress) if you're using visual tests.
Step-by-Step
- Set up a Story for your input component. If you're using Storybook, create a story that renders your input component with a placeholder or default value. For example, in
Input.stories.js, add a story namedHindiInputthat passes a Hindi string likeनमस्तेas the value. This ensures Chromatic has a baseline to compare against. - Enable Indian language support in your test environment. If you're testing in a browser, ensure the browser's language settings include Hindi (hi-IN) or another Indian language. In Chrome, go to Settings > Languages and add Hindi. For automated tests, you can set the
accept-languageheader or use Playwright'slocaleoption when launching the browser context. - Write a test that types Indian language characters. Use your testing tool to simulate typing. For example, in Playwright, you can use
page.fill('input', 'नमस्ते')orpage.type('input', 'नमस्ते'). If you're testing a complex script like Hindi, ensure the test types the full string, not just individual characters, to trigger proper shaping. - Capture a snapshot in Chromatic. Run your test suite with Chromatic's CLI. For Storybook, run
npx chromatic --storybook-config-dir .storybook. For Cypress, use the Chromatic Cypress plugin. This will upload the rendered component as a snapshot to Chromatic's cloud. - Review the snapshot for rendering issues. Once the test runs, open Chromatic's web app. Look for the snapshot of your component with the Hindi text. Check for common issues: broken glyphs (boxes or question marks), overlapping text, incorrect line height, or text clipping outside the input field.
- Set a baseline and compare. After the first successful snapshot, Chromatic will treat it as a baseline. Any future changes to the component or its styles will be compared against this baseline. If you update the Hindi text or the component's styling, Chromatic will flag the difference for review.
- Automate for other Indian languages. To test multiple languages (e.g., Tamil, Telugu, Bengali), create multiple stories or test cases, each with a representative string. For example, add a story
TamilInputwithவணக்கம்andBengaliInputwithনমস্কার. Run them all in the same Chromatic test run.
Common Mistakes
- Not setting the correct locale. If the browser or test environment doesn't have the Indian language locale, the text may render with default Latin font, causing incorrect shaping.
- Using only a few characters. Hindi and other Indic scripts have conjuncts and vowel signs that only appear in longer words. Testing with a single letter won't catch shaping issues.
- Ignoring font loading. If your web font doesn't include Devanagari or other Indic glyphs, the browser will fall back to a system font, which may look different across platforms. Ensure your font is loaded before the snapshot.
- Forgetting to update baselines. When you intentionally change the layout or text, you must accept the new baseline in Chromatic; otherwise, it will keep flagging the same diff.
Tips
- Use realistic sample text. For Hindi, use a sentence like "नमस्ते, आप कैसे हैं?" to cover common conjuncts and matras. For Tamil, use "வணக்கம், எப்படி இருக்கிறீர்கள்?".
- Set a viewport size. Test at both mobile and desktop widths, as Indian language text may wrap differently on narrow screens.
- Leverage Chromatic's UI review. Use the side-by-side comparison to see exactly what changed, and annotate the snapshot to communicate with your team.
- Integrate with CI. Run Chromatic tests on every pull request to catch regressions early. Add a GitHub Action or similar that runs the Chromatic CLI.
Troubleshooting
- Text appears as boxes or question marks. This usually means the font doesn't support the script. Check that your CSS includes a fallback font stack with system fonts like 'Noto Sans Devanagari' or 'Mangal'. In your test, wait for the font to load using
document.fonts.readybefore taking the snapshot. - Chromatic shows a diff even when nothing changed. This can happen if the font loads differently between runs. Use Chromatic's 'Accept baseline' button to update the baseline, or ensure your test waits for fonts to load consistently.
- Test fails to type Indian characters. Some testing tools may not handle IME input. Use the
page.fill()method instead ofpage.type()to set the value directly, as it bypasses keyboard events. - Snapshot doesn't include the input value. Ensure you're passing the value as a prop or state, not just typing it. If you're using Storybook, set the story's args to include the value.
- Chromatic times out. If your test takes too long, increase the timeout in your test configuration. Also, make sure your test doesn't wait for network requests that never resolve.
Frequently Asked Questions
Do I need a physical Indian keyboard to test?
No, you can simulate input using your testing tool's API. You don't need to install any keyboard drivers.
Can I test Indian languages in Chromatic without Storybook?
Yes, Chromatic supports Cypress and Playwright. You can write a test that navigates to your app, types Indian text, and captures a screenshot.
Will Chromatic automatically detect layout issues like text overflow?
Chromatic captures visual snapshots, so any visual difference is flagged. However, it won't tell you why the layout is broken; you'll need to inspect the screenshot.
How do I add a new Indian language to my existing tests?
Simply create a new story or test case with a sample string in that language. Run Chromatic to generate a new baseline snapshot for that test.
What if my app uses a custom font that doesn't support Hindi?
Chromatic will show the fallback font in the snapshot. You should either include a web font that supports Devanagari or accept the fallback as part of your design.
Can I test right-to-left (RTL) languages like Urdu in the same way?
Yes, the process is identical. Just set the appropriate dir="rtl" attribute on your component and use a sample string like "السلام علیکم". Chromatic will capture the RTL layout.