Skip to main content

How to write bad UI automation code (a formal guide)

You might find umpteen resources on learning to write UI automation. But rarely you find any guide on writing bad automation code. Bad automation code is not actually "bad" especially when you consider following -
  • Bad automation code keeps you job safe. Well who can understand the code other than you.
  • Gives you an opportunity to ask for more raise as you are the only one who can maintain the code you write
  • Lets you keep your head up as you the geek of your company who knows that abstruse code
 Now coming to writing bad automation code, here are some silver bullets -
  • Record and Replay is the core or writing good (read bad) automation code. It has so many advantages which just out do many others. Biggest being you don't have to write any good code (read bad), tool does it for you. The way to convince decision owners in to enlightening is to let them know that record and replay does not require any special skills. Even your HR can do this. And you know once you have Record and Replay suite ready, only you the super automation engineer and no one else would be able to manage it. But if you don't succeeds in convincing (read fooling) management about Record and Replay, there are still many other ways. Keep reading.
  • Choose a language which is more and more dead. VB script being one of them (do I still need to name the tool you should pick?)
  • Checking multiple conditions in one test methods and never have that foolish mechanism of logging which might indicate others about what is going wrong. Have them run to you when there is a test failure and become the super star of testing 
  • Make sure you have application locators scattered all over your test scripts. You just can not imagine how much work it would generate for you (and keep your job safe) when application under goes slightest of change
  • Never never never write methods which could be used across code base, whether they are application dependent or independent. More code is good code because more code means more maintenance mean more work means more opportunity to save your a**
  • One special suggestion is for you to learn those terms (just mug up the namea and nothing more) like polymorphism, abstraction etc. You never have to use them in your test code but instead use them to scare any new joiner in you team.   
  • Never ever use text based locators. If there are 10 radio buttons on a page then you should always use them using their ids not the text bases locator. The biggest disadvantage of text based locator is that you might end up in writing three lines of code which could easily be extended to 50 lines. Say no to -

    public String getThatRadioButton(String buttonName) {
        return "//input[text()='" + buttonName + "']";
    }

  • This trick is special and works like black magic. If you don't know how to automate then don't worry it is not tough to bring that green symbol in test report. There must be assertTrue(true) available in almost all modern languages. Now you just need to have your test methods fill with this magic statement. Remember all green always makes management happy and earns you accolades
 Follow these rules and be a rock star. I am sure there are more to this list, could you add any?


Comments

Post a Comment

No spam only genuine comments :)

Popular posts from this blog

Using xPath to reach parent of an element

Note: If you are new to java and selenium then start with selenium java training videos .   I prefer css locator over xPath but there are times when css locators don't fit requirement. One such requirement is when you want to navigate to parent element of an element and may be parent of parent and even more. Unfortunately css locators don't provide any mechanism to navigate to parent of an element. See this for more. Of late I came across a scenario when I wanted to click on a link depending upon the text in a text box. Herein parent of text box and parent of link were at the same location. More over there could have been many such combinations in application. Fortunately I just need to pick first such instance and Web Driver any way considers only first instance when multiple locators are found matching an element. Element in question is in following html - Here I need to click on highlighted anchor on the basis of input element (which is also hig...

Verify email confirmation using Selenium WebDriver

Note: If you are new to java and selenium then start with selenium java training videos .   How to Verify Email Confirmation Using Selenium 4 and JavaMail (2026 Guide) Email confirmation is a critical part of most registration flows — account activation, password reset, multi-factor authentication, and onboarding. Every automation engineer eventually faces the same challenge: How do you verify an email confirmation link inside a Selenium test without making it slow and flaky? The wrong instinct is to automate Gmail's UI with Selenium. It's fragile, slow, and breaks constantly. The right approach: Use Selenium for browser automation Use JavaMail (IMAP) to read the email directly Extract the confirmation link Continue the test in Selenium Why Not Automate Gmail UI With Selenium? Automating the Gmail UI means logging in, searching, clicking a message, and parsing content from a third-party interface that changes frequently. This leads to: Flaky...

Real Time JMeter Result Using Backend Listener

Since JMeter 2.13 Backend Listener has been available to create real time graph of JMeter Test. Following tutorial explain the entire process in detail. At the end of this tutorial you would be able to create JMeter Live Test Result dashboard similar to following - This tutorial borrows information from many sources and my own experiments with JMeter live reporting dashboard. I have added source of information wherever applicable But before we can build such a snazzy JMeter Live Reporting dashboard we need to understand two more components - influxDB (a time series database) and Grafana Dashboard This is a big tutorial, so take deep breath :-) and follow on. Once you complete set up specified in this tutorial then you can watch JMeter Training Video Tutorial to watch this in action. What is Time Series Database? A time series is a sequence of data points , typically consisting of successive measurements made over a time interval . Examples of time ...