So it performs actions such as clicks text entry that a user would do and allows you to validate that the application as a whole behaves as expected. And in my experience of writing these tests as a developer, we ended up using Cypress way back when we used Protractor for Angular, which thankfully is no longer in existence.
The other thing is synthetic monitoring, which is more from the SRE side of things. And synthetic monitoring refers to the ability to, on a regular schedule, run scripts against a particular application to validate that it's up and it is alive. And this can be as simple as a simple ping on an endpoint to make sure that a health service is up to something as complicated as simulating user clicks and action to make sure that the application is responsive for users who are going to go in and use the application. And you've probably guessed the thing that's common between both of these things is, in fact, the user perspective.
But these things are often built by different audiences, developers and testers, compared to SREs and production management individuals. And they always use different tools as well. So, my last engagement in the bank, I used Cypress for N10 testing, but my colleagues who were writing monitors were using a PICA and Zebra tester. And the reality is, if we want to come together and try and work together to make more maintainable, more reliable systems, and also share the road when it comes to writing these automations, we need to use a common tool set that we all can understand.
And I'm going to walk through an example, which you can check the QR code to go and have a nosy through afterwards if you'd like, using Playwrights, which is an end-to-end testing and automation framework maintained by Microsoft, GitHub Actions for CI, and Elastic Synthetics to show how a combination of these technologies can allow us to use the same scripts as an end-to-end test and local development in CI, and then again as a monitor in production. The way that these tools interact is similar to the flow that I have up here. So bringing out my mouse, what you'll see is that we have a project using Elastic Synthetics and TypeScript journey files, which have Playwright interactions within them. And these sit alongside those vanilla heartbeat monitors, which are specified in YAML. And one of the great advantages is, this effectively gives us monitors as code. We have configuration in a repository, instead of having it manually configured in a UI and observability platform. So we can run these locally against a version of the web app to see that everything is running as expected when we build out features. And then we can push them up into source control, raise that PR, and then actually execute them as end-to-end tests to validate on the potential merge that everything's working as we expect. Then, when we deploy our app at the same time, we are going to take those same journeys, those monitors, those tests, and we're going to use API key authentication to push them to the location in which we're going to run them, and then they are going to ping against the production web app instead, and then process the results into observability platform so we can see what's going on.
So let's dig into an example, shall we. So this is a vanilla Playwright test that I've written just to show how Playwright works on its own before we try and integrate Elastic Synthetics together. So you'll see that I'm using Playwright tests so I've got that installed within my web app project, and you'll see here that what I'm doing is I have two tests, I've got one where I'm moving to the order page in this little ecommerce app that I've built, and I have another one where I'm adding an item to the order. So I can use the page object within Playwright to navigate, so going to the home page for example, I can use various locators to pull out the particular elements in the page that I want. So for example here I'm asynchronously pulling out the order button using the get by test ID shorthand. Important to note that this means that I have separated my styling and all those other changes from the logic that pulls out my elements because in this particular occasion I'm using the data test ID attribute which I recommend you do as well if you're not already. So then I can click on that button, I can check that I've navigated to the order page as expected and I can also pull back all of the menu item cards to see that I have a few of those. And then on my adding order I'm going to the order page instead. I'm pulling out all of the add item buttons off of my menu cards, checking that I've got a few of them again and then I'm getting the cart count label and then I'm checking with the clicks of individual add item buttons that this particular value is incrementing each time. It's a relatively straightforward test. So if we want to now make use of Elastic Synthetics on the top, we need to install it.
Comments