Automated Testing in a DevOps World
Automated Testing in a DevOps World
Automated testing is a huge part in simplifying processes for DevOps. Here are five steps how to get up and running (the right way) with automation.
Join the DZone community and get the full member experience.Join For Free
Read why times series is the fastest growing database category.
The objective of automated testing is to simplify as much of the testing effort as possible with a minimum set of scripts. Automated testing tools are capable of executing repeatable tests, reporting outcomes, and comparing results with faster feedback to the team. Automated tests perform precisely the same operation each time they are executed, thereby eliminating human errors – and can be run repeatedly, at any time of day. Below I’ve outlined five steps on how to get up and running (the right way) with automation.
Step 1: Laying the Foundation
The foundation is the most important element of any building, be it a house or a high-rise. It may seem like a simple part of the overall construction process, but getting the foundation right is incredibly important. Mistakes made in the foundation will only get worse as you go up. It’s known as compounding defects and it means that mistakes grow. Wait! How does this relate to automation? Proper planning will lay a solid automation foundation for project success; without it your project will be shaky and a maintenance nightmare.
To avoid these potential pitfalls and keep on task, you need a good road map – start by:
- Planning your automation objective;
- Design the architecture;
- Training the team;
- Begin developing test scripts;
- Releasing to the wild.
Throughout the onboarding process, it is important educate everyone. One of the common misconceptions of automation is that automation is a magic bullet – the initial setup and step creation will take time and effort. Automation requires effort to maintain. This needs to be factored into any planning and estimation. The principles of good programming are closely related to principles of good design and engineering. By enforcing standards, you can help developers become more efficient and to produce code which is easier to maintain with fewer defects. It’s a great opportunity to start shaping your new testing portfolio by educating everyone – they need to understand what type of testing belongs at unit, integration, and api layers when having those conversations during the sprint planning phase.
Step 2: Selecting a Technology
You’ve found the perfect plan and know where you want to build. The excitement is building. It’s time to start thinking about the details that can make all the difference. Choosing the right products and materials for your new home can be overwhelming. The same applies when choosing a testing framework for your automation. It is a critical part of the process. Since there are so many different testing frameworks available, it’s important to create a list of requirements to review when evaluating a framework. To help you, here are some questions to ask as you round out your requirements:
- Are you looking for Behavior Driven Development (BDD) framework for unit and front-end UI testing?
- Do you need to support browsers, mobile web, or mobile native apps?
- Are you looking to run your selenium test locally or in the cloud?
- Do you need cross-browser testing?
- Do you need keyword driven framework for non-technical resources?
- Does your team have sufficient programming knowledge for automation development?
- Are you practicing continuous integration and need a tool that integrates seamlessly?
Step 3: Configuration
Find the right pro who specializes in exactly the type of work you need done. You would never hire a plumber to do electrical work. Right?
This stage is critical and can be frustrating with a lack of experience. It would be ideal to find an automation expert to design your automation architecture, teach the team the fundamental skills how to write quality tests, and continuous mentoring. If hiring an expert is not an option, I strongly suggest finding an on-site training course for everyone planning to write tests.
Step 4: The Basics
Every construction trade require basic knowledge of the service. I couldn’t even imagine building interior framing wall without any basic knowledge. The framing basics of your wall include the sill plate on the bottom, the wall studs (which are the vertical beams), and the top sill plate (which is the beam running across the top). It sounds simple in theory, but to get a wall plumb and square takes basic knowledge and a lot of practice.
The same applies when writing automation scripts. One of the basic principles of automation is to understand how to find locators and NEVER use xPaths. It is critical that engineering teams are designing software with automation in mind. What does that mean exactly? Educate engineers how to define unique and predictable locators needed for automation. The most efficient way and preferred way to locate an element on a web page is by HTML element ID or CSS Selector. The ID and CSS are the safest and fastest locator option and should ALWAYS be the first choice. Let’s start with, only use xPath if that is the ONLY possible way, personally this is great opportunity to push back to engineering to provide predictable locators for your scripts. Here are example how to write an automation script from predictable HTML elements;
HTML Code With Well Defined Locators:
<div class="grid location-search-result js-store js-search-result" data-showclosed="true" data-substituted="false" data-delivery="false" data-carryout="true" data-online="true" data-orderable="Carryout Delivery" data-open="true" data-type="Carryout" data-storeid="4348" data-services="Carryout"> <a class="js-orderCarryoutNow js-carryoutAvailable btn btn--block" data-type="Carryout" data-ordertiming="current" href="#/section/Food/category/AllEntrees/">Order Carryout</a> </div>
Write a Script Using Capybara Testing Framework:
expect(page).to have_css('.js-orderCarryoutNow') find('.js-orderCarryoutNow').click
Step 5: Let’s Code
FINALLY, the construction begins! Here are my tips for getting started with writing great automation scripts.
Repeatable. Automated scripts must be repeatable. You must be able to measure an expected outcome.
Design Test for Scalability. The whole point of automation is to provide rapid feedback. Creating and executing large-scale automated tests need a thoughtful approach to elements in the process and a close eye on test design. Keep tests lean and independent.
Easy to Understand. Scripts should be readable. Ideally, your scripts also serve as a useful form of design and requirement documentation.
Speed. Your automated tests should run quickly. The end goal is to make the overall development process faster by establishing rapid feedback cycles to detect problems.
Sample Test Using Capybara:
describe "on the google homepage -", :google, :type => :feature do before :each do visit 'https://google.com/' end it "the search input field is present" do expect(page).to have_css('input#lst-ib.gsfi') end end
Your road to automation can be difficult, but it’s worth it. To it well you need the right attitude. Sometimes you will hit roadblocks. If something didn’t work, you really learn to problem solve here. The training phase is so important and incredible opportunity to master your new craft – pay attention, have the right attitude, adapt, be engaged, and never stop learning…
About the Author
Greg Sypolt (@gregsypolt) is a senior engineer at Gannett and co-founder of Quality Element. The last 5 years focused on creation and deployment of automated test strategies, frameworks, tools, and platforms.
Published at DZone with permission of Greg Sypolt , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.