Using snaplet seed to seed your Playwright tests

Snaplet seed plays right with Playwright

“If you want to write better software, write better tests.” This line gets trotted out with regularity by developers, but it’s easier said than done though, when having access to realistic data for testing is often such a chore.

That's where Snaplet seed comes into play, redefining how we seed databases for development and testing, making it declarative, minimalistic, and maintainable. We’re going to show you with a real, practical example, just how easy it is to use Snaplet seed along with Playwright to make getting better data and writing better tests that much easier.

To do: write a better todo app

Our journey begins with a basic todo application, something many developers have cut their teeth on when learning. In our hypothetical case, let’s imagine we’ve taken a very basic todo app and we've upgraded it with a new feature: the ability for teams to upvote and downvote a todo item. These enhancements not only make the app more complex but also introduce new challenges in ensuring it works flawlessly with every update.

Let’s plant a seed

Enter Snaplet seed, a tool designed to eliminate the hurdles of seeding your database with realistic test data. Unlike traditional methods that rely on manual scripting or synthetic data generation, seed offers a declarative, maintainable, and efficient approach to generating data that mirrors your production environment.

How seed works

Snaplet seed stands out from alternative seeding methods by its ability to introspect your database schema and automatically generate realistic, related data. This eliminates the need for cumbersome manual scripts, saving time and ensuring the data used for testing reflects real-world scenarios closely.

Follow along as Snaplet developer Khaya Zulu shows you just how easy it is to use Snaplet seed to get realistic test data.

The magic of seed

The video shows a moment of pure magic where Snaplet seed fills the database with realistic todos, users, and associated votes. This process, which could traditionally span hundreds of lines of code, is accomplished with minimal configuration, showcasing both the power and simplicity of seed.

Seeding Playwright tests with seed

The integration of Snaplet seed with Playwright, an E2E testing framework, is seamless. By generating and seeding databases with realistic data, developers can create more robust E2E tests. This ensures that the application behaves as expected, not just in theory but under conditions that closely mimic real user interactions.

The outcome: better tests, reliable results

Tests seeded with seed's realistic data result in a higher quality of testing. They significantly reduce the occurrence of false positives, ensuring that when a test passes, it does so because the application truly works as intended. This confidence in testing translates into fewer bugs and a better end-user experience.

Things go right with Snaplet seed and Playwright

If you’re looking to improve the reliability of your E2E and unit tests, particularly with tools like Playwright, reaching for Snaplet seed makes perfect sense. By providing a straightforward way to seed tests with data that closely mirrors real-world scenarios, seed empowers developers to write, test, and deploy with confidence, in a fraction of the time associated with manually writing seed data.

If you want to try it for yourself, we have the todo app as an example app on the Snaplet repo, so you can fork it and try it for yourself. Give it a go here. To dive straight into using seed for your projects, check out our docs.

Jian Reis
January 24, 2022