USA +1-347-270-8720 | INDIA +91-7993648720 training@absofttrainings.com

Use SOLID Principles To Become Better Automation Tester

Are you using most recommended and fundamental SOLID principles in your automation? Why You Need To Use SOLID Principles? Like any development work, automation also needs to be planned, designed, developed, maintained and extended over time. Your automation code or automation framework is an application which is testing your actual application. That’s why SOLID principles are highly recommend for your automation to make it easy to understand, use, maintain and extend over time. When SOLID principles are not applied, your automation might become fragile, hard to maintain and hard to extend very soon. This is the first post in a series of posts that describe & apply the SOLID principles of object-oriented design and programming to web automation using Selenium & Java. Even if you are using different programming language like C#, Python or automation tool like HP UFT/QTP for automation, you should definitely consider applying SOLID principles to make your automation tester life easy. Please note that we will be discussing about applying SOLID principles to web automation using Selenium & Java. But, once you learn the concepts, you can easily apply them to any object-oriented development. In this post, we will be exploring what SOLID principles stands for. We will be having one post for each principle with real life examples from web automation using Selenium & Java. What Are The SOLID Principles? SOLID principles are the first five object-oriented design principles by Robert C. Martin, popularly known as Uncle Bob. SOLID is an acronym where:- S stands for Single Responsibility Principle (SRP) O stands for Open Closed Principle (OCP) L stands for Liskov Substitution Principle (LSP) I stands for Interface Segregation...

How to get a number (int or double) in a string message?

JAVA Code public class ExtractIntAndDouble { public static void main(String[] args) { //*************** Extracting int values ************************* String searchCountStr = “There are 280 search results”; // or String cartCountStr = “There are total 6 items in your cart”; int searchCount = Integer.parseInt(searchCountStr.replaceAll(“\\D”, “”)); System.out.println(searchCount); //*************** Extracting double values ************************* String totalPriceStr = “Your have paid £154.75 for this order”; // or String totalPriceStr = “Total Price: £154.75”; double totalPrice = Double.parseDouble(totalPriceStr.replaceAll(“[^0-9\\.]+”, “”)); System.out.println(totalPrice); } } In searchCountStr.replaceAll(“\\D”, “”), “\\D” is a regular expression to represent all non-digit characters and “” represents blank string. searchCountStr.replaceAll(“\\D”, “”) gives string with only digits like “280” by replacing all non-digit characters with blank string. In totalPriceStr.replaceAll(“[^0-9\\.]+”, “”), “[^0-9\\.]+” is a regular expression to represent all characters except digits 0-9 and dot character (.). Also, “” represents blank string. totalPriceStr.replaceAll(“[^0-9\\.]+”, “”) gives string with only double value like “154.75” by replacing all characters with blank string except digits 0-9 and dot character (.) . This is more effective than using split function (mentioned below) as we don’t need to worry about our int or double value position and  currency symbols before price values String[] tempArray = searchCountStr.split(” “); int searchCount = Integer.parseInt(tempArray[2]); System.out.println(searchCount); The above code will work for string “There are 280 search results” but will not work for string “There are total 6 items in your cart”. This is because int value position changes in both...
Get our welcome pack, free videos, hot offers and latest news!

Get our welcome pack, free videos, hot offers and latest news!

Hurray! You will get our email with your welcome pack in few minutes and you are Successfully Subscribed.


Copyright © 2016 ABSoft Trainings. All rights are reserved.
Registered in England & Wales under Company No: 09166392
Back To Top | Terms of Use | Privacy Policy | Refund & Cancellation Policy | Site Map