# Igor Luchenkov > Personal blog of Igor Luchenkov, a staff software engineer. Full text of every article follows. --- # Do not write Storybook tests manually, do this instead! Source: https://igorluchenkov.com/blog/storybook-test-codegen [Storybook](https://storybook.js.org/docs) is one of the best tools for building client components. It allows us to create UI in isolation, document it, and even cover it with [automated tests](https://storybook.js.org/docs/7/writing-tests/interaction-testing). I explained why automated tests are worth pursuing in [Why You MUST Have Automated Tests](https://hackernoon.com/stable-software-learn-about-the-power-of-automated-tests). In this post, we'll go deeper into how to write them efficiently with Storybook. ## Let's write a test We have a form with an email, password fields and a submit button. The user enters their credentials, submits the form and sees the confirmation message. Here is what the form looks like: ![Form](/assets/blog/storybook-test-codegen/form.png) And this is the HTML structure of the form: ```html
``` ### How to test? Here are the steps we need to take to write a test for this story: * Pick an element to interact with. * Find a user-friendly selector for it (e.g. by aria-role, label, placeholder, text, title, test-id) according to [Testing Library's guiding principles](https://testing-library.com/docs/guiding-principles/). * Write the interaction code (e.g. `userEvent.click(selector)`) * Return to step 1 to perform the next interaction until the test is ready. ### The actual test There are four elements to interact with. Here is how we can do it: * Email and password: * Both fields use an `input` tag, which translates to `role=textbox` in Testing Library. They also have a `