So this is an automated test, maybe running as part of CI or something like that. You really didn't have control over where the cursor was happened to have landed and therefore now your deployment is blocked, not what you want.
Here's another one, who can see why this one failed? Yep, because of that cursor behind the word bad. Cursors blink. So if it happens to take the screenshot when the cursor is solid and then happens to take a regression screenshot when it's not, that can cause a failure as well.
You don't want your deployments blocked for this and having to investigate why that happened, nor do you wanna write automation code that tries to stop this sort of thing, right? Fortunately, Applitools has come out with a better approach to doing this using machine learning. So it mimics the human eye and brain and is able to highlight and detect only what matters in the test.
So I have another game here. You all don't get to play because you let the dead man walk in the first game. But in this one, I ran this through pixel to pixel and I ran it through Applitools machine learning algorithm to just see like, what's the difference and how does it detect. And this is the one with the pixel to pixel, notice everything is highlighted here, like every little white shift change, it's not met for testing. Versus when I ran it through the Applitools algorithm, it highlighted the things that I would have highlighted as a human being, right?
So okay, let's add this to a test, an existing test. So here's our application in the test, single page app, very simple, eight of my favorite books on test automation. You enter some text into that field and that will filter down the books, so the ones that have tests in the title, all right? So here's the test to do this. This is written in Cypress with JavaScript, but Applitools has SDKs for all of the different automation tools and all of the different programming languages. So if you use something different, good for you, but this is JSConf, right?
So, okay, so this is Cypress JavaScript. We are querying the word test. We are expecting these five books to come back. We enter that into the field, and then we have two validations here. One validates that the number of books that are visible is the same as what we expect, and each of those titles that's in the expected books array actually is visible, all right?
Great, so now I get a little wonky with the CSS and I want to add a bouncy effect, but I don't really know what I'm doing, but that's okay because I have test, which means I can do whatever I want. So I add line six here to this CSS and I check it in, right? My test will let me know if anything's wrong. Again, here's my test, look at it carefully. And this is what the application looks like with that new CSS. Will my test catch this? Let's see. I run this with Cypress again, notice all the green here. There's no red, even though I have literally flipped my application upside down. That's problem. That's why we need visual testing.
So how do we add it? Very simple. Three lines of code, almost like poetry, right? Starting on line three, we use the Applitude's eyes API and it integrates so nicely with Cypress.
Comments