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

Appium and android mobile app automation

Next appium and Android mobile app automation video tutoria l is live. If you are new to appium then please check - appium-tutorial This video tutorial covers - Start vysor (Just for this session and not mobile automation :)) Start appium and start appium inspector Desired Capabilities platformName - Android deviceName - L2N0219828001013 (as seen on "adb devices") Saved Capability Sets Start Session Scan app elements using appium inspector Get appPackage and appActivity using "APK info" app Install "APK info" app and open app whose appPackage and appActivity are required i.e. calculator Check top section of app icon com.android.calculator2 is app package com.android.calculator2.Calculator is app activity testng.xml file settings for running Android app tests Test details com.seleniumtests.tests.mobile.AndroidAppTest and CalculatorScreen class View beautiful STF test report  

Verify email confirmation using Selenium

Note: If you are new to java and selenium then start with selenium java training videos .     Email confirmation seems to be integral part of any registration process. I came across an application which lets you provide your email address. You can follow the sign up link in you mail and then complete the registration process. Lets consider we provide GMail address for it. Now if were to use only Selenium then we would have to follow following steps - Launch GMail using Selenium; Some how search for new mail in the list of available mails; Some how click on it; Parse the mail message; Get the registration link; Follow up with registration process What do you think of an approach in which you can

Selenium Tutorial: Ant Build for Selenium Java project

Ant is a build tool which could be used to have your tests running either from command line or from Hudson CI tool. There is detailed documentation available for ant here but probably you need to know only a little part of it for you selenium tests. The essentials which are needed to know are: Project Target (ant execution point and collection of tasks) Tasks (could be as simple as compilation) And there would usually be following targets for Selenium tools - setClassPath - so that ant knows where you jar files are loadTestNG - so that you could use testng task in ant and use it to execute testng tests from ant init - created the build file clean - delete the build file compile - compiles the selenium tests run - executes the selenium tests Here is my project set up for ant -