Automation Concepts

Pain of an Automation Engg and Best practices to avoid

Automation best practices

Pain of an automation engineer

If you are working with any automation tool then you can relate this term OR if you are starting with Automation testing then be ready with this pain.

When I started with automation testing I was going through this stage and I used to think that why I am not able to write good automation scripts, why my automation script is not stable.

I have  listed down what used to happen with me and how I overcome through this.

When I used to create automation script

  • My script used to work fine sometimes and sometimes it used to fail.
  • When I run the script in my local machine it works fine but when I run in remote or another browser it fails.
  • Scripts work fine in one browser and it fails in other browsers.
  • Scripts work fine for current release, but it fails when new release come for my applications.
  • Earlier I used to create scripts without any framework so even if small changes in the application then I used to make the changes in each script.

 

Story-  I would like to tell you a scenario that happens with almost everyone. I created some sample script for my application and executed in all browser and next day when I was about to show the demo it failed due to some locator issue and when I came back to my desk and executed the same test cases it got passed.

This was the repeated scenario for me and finally I followed some best practices and got very good results.

 

Best practice to overcome this pain.

I will list down mainly for Selenium, but you can follow for other tools as well.

 

Stat writing your own xpath using xpath methods

I used to copy the default xpath generated by firebug and file path and was using in my script. It takes less time but trust me this xpath will not help you in the long run.

Find some pattern in element and write your own Xpath. Follow below link for xpath

Dynamic xpath in Selenium

 

Start using a design/framework

You can directly start writing your automation script without any framework that fine but maintenance task will be a big headache once test case size will grow even if a small change in the application then you have to modify all script.

You can start using any framework, but it should have below characteristic.

  • Reusable 2- Easy to use    2- Easy to maintain      4- Robust in nature

 

         

Most important

Execute your script multiple times 

 It sounds crazy but trust me it will stable your script and you will get to know what’s your script behavior.

I will tell you my scenario which I follow in my organization and will highly suggest to all of you to follow if suites you.

I execute each script almost 10 times and check how the history is. If script pass ratio is 80 % then you are on the right path but still you need to find out why it failed 2 times. If you ignore this failure then trust me in future your script will fail again due to the same reason. So have a look to that failure and fix it permanently.

If you do want to execute the script manually then take help of Jenkins and schedule it for every one hour or 30 minutes.

Selenium Integration with Jenkins and Schedule your test

It may take some time but your script will be highly stable and you will get good ROI from your script.

 

Use Smart wait in your script

Selenium and I guess all automation tools having some smart wait which will allow you to wait for an element.

90 % automation script failure reason is Sync issue and locator changes only.

 

I have followed above best practices but if you have some more suggestion or any practice that you have followed then please let me know I will add in this post.

Please share with your friends who also facing this pain 😉

 

 

 

 

 

 

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

27 thoughts on “Pain of an Automation Engg and Best practices to avoid

  1. Vienna says:

    Hi Mukesh,

    Thanks a lot for your post. That’s all helpful practices to follow.

    I’m just a beginner in this field, so I don’t really understand why we should create our own xpath instead of using xpath provided by Chrome ( I use Chrome driver for testing purposes).

    Hope to hear from you. Thank you.

    1. Hi Vienna,

      Own XPath, I would rather say it as Relative XPath. Based on application UI and textual changes, you can create your own XPath which I think remains more stable than what Chrome provides while inspecting an element because Chrome provides Absolute XPath which are very lengthy and very unstable if application is under development

      1. Vienna says:

        Thank you for your reply. Hope to see new contents from you. Wish you all the best.

  2. carlo mario says:

    cuanto te sale uStaleElementReferencen que puedes teniendo en cuenta que los wait no me corrige este error

    1. Hi Carlo,

      Kindly comment in english so that other readers can also understand your requirement

  3. vinod singh says:

    Hi Mukesh,

    I am a beginner for Selenium webDriver. this post will help lot for me to explore my automation skills.
    thank you so much.

    1. Hi Vinod,

      I am happy to read from you.

  4. charan says:

    How we can automate the browsers which are opening via citix ?

  5. Prabhu says:

    Thank you so much Mukesh! Your post is simply awesome!!

    1. Thanks Prabhu. I am glad you liked the post.

  6. MIrza says:

    Hey,
    I have one scenario where i have to upload the file .but i don’t want to upload file using Auto It or Robot class.Is there any way to keep this file in eclipse and upload this file from eclipse .And in our eclipse only browse button available .When i click on that button it redirect to windows .
    But my requirement is to send this project exe to my client .So what should i do now.

    1. Hi Mirza,

      You can use Sikuli also in this case.

  7. veer singh says:

    hi sir thanks

    1. Your welcone Veer

  8. Mike says:

    Hello, have you ever faced with that problem “Vector smash protection is enabled.”. And how to handle with that one

    1. Hi Mike,

      I never faced above issue 🙁 this is completely new for me.

  9. Akshatha says:

    Hi,
    Can u please share custom methods u created to avoid sync issues and timeouts.

    Thank you.

    1. Hi Akshatha,

      will update sync method soon.

  10. Hakan Uzunkaya says:

    Hi Mukesh ,

    Thanks for sharing your experiences,

    Maybe it is worth to add your list that sometimes it is hard to find that where the script fail , which step did not work and so on. Taking screen shot can be a solution but sometimes it is not enough.

    My solution is that adding basic console logs before and after of each methods.

    When you check console directly , you can easily figure out which method is not completed so you can earn time 🙂

    As an example ;

    public void login(….)
    {
    System.out.println(“Login started”);

    //Codes here

    System.out.println(“Login finished”);
    }

    1. Hi Hakan,

      True I totally agree that we should have log feature in our script to keep track of our execution.

      Thanks

  11. pavankumar says:

    Mukesh,

    Me also faced this kind of hickups with selenium. Many times i faced no such element exception due to nonsync. Is this good to use Expected conditons for sync. Please advise me

    1. Hi Pavan,

      We use explicit wait and fluent wait to avoid sync issues. We also created our own method to avoid this and now we have very stable scripts.

      Thanks
      Mukesh

      1. pavankumar says:

        Is it possible to share the custom method which you have created

        1. Hi Pavan will share soon..

  12. Satnam Singh says:

    Thanks for sharing this (PAIN OF AN AUTOMATION ENGG AND BEST PRACTICES TO AVOID) Indeed a biggest challenge for automation projects have been well pointed out in your post.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.