Automation is fun !!!

The other day, I was thinking, does learning new technology really has to be hard with no fun. I have seen lot of people who wants to add automation skill set sometimes gives up , may be they just need more time or some way to make learning a fun.

So how about, we pick a game and automate it. I stumbled upon a game fastest 1 to 50.

The objective of the game is to click from 1 to 50 as fast as possible.

https://zzzscore.com/1to50/

Tools Used: Selenium (Java)

Approach:- In layman language, UI automation is all about identify the target element , perform an action and validate it. So, the first step is to find the element "1" , since thats what we need to click first, Lets also look at the DOM for element "2" and "3" too to figure out if we can identify a pattern out of it

<div style="opacity: 1;"><span class="box" style="z-index:99"></span>1</div>
<div style="opacity: 1;"><span class="box" style="z-index:98"></span>2</div>
<div style="opacity: 1;"><span class="box" style="z-index:97"></span>3</div>

There are 2 things that we observed.

  • The span consists of the digits
  • style=z-index:100-x, where x starts from 1

So, based on above observation, we can create xpaths (below), create a loop from 1 to 50 , find the element and then click.

"//div[text()='1']"

OR

"//span[@style='z-index:99']"

Learning:-

For people who are beginners, you would learn how to create locators , make them generic and use loops to iterate to all the numbers in the grid.

For people who know automation, probably a good opportunity to use some design patterns or logic , to beat your own fastest time.

For me, I started out with 4 seconds and then 3.2 and with more code refactoring, so far reached to 2.753 seconds.

What's next:- I tried Selenium Java for the above challenge. Next I am gonna try Cypress ,wdio and platwright and compare the easy fo writing code as well as the execution time.

PS:- By the way, with Selenium-Java, my time was 2.753 seconds.( I am sure lot many would be beat this score comfortably, so no where I want to claim this is the lowest one)

No alt text provided for this image

Playwright:- A new tool in the market from the stable of Microsoft. Playwright is a Node library to automate ChromiumFirefox and WebKit with a single API . For more details , pls see https://github.com/microsoft/playwright

I am very new to playwright (first attempt) and below are the stats when I used it against our 1to50 score challenge game. Code snippet for the same is pushed at

https://gist.github.com/sunnysachdeva99/b57c0cc81a630d736d13ee6ff03c416b

No alt text provided for this image


Comments

Popular posts from this blog

How to mock a response in Selenium

Some useful links for testing

Generic Checklist in case you want to consider Cypress