We keep validation throughout our automation code, but do we really need so many IFs and Exceptions (first we check a condition and then throws an exception)?
For example, we verify that a page is displayed with the expected title or not. And for that, most of us use the below shown first method (testUsingIf), isn't it?
Anything wrong with this code? Of course not, but what if we can use the easier way i.e. by using the Apache Commons library that has a class that can
simplify the validation as I have shown in the second method (testUsingValidate).
P.S. Anyone can write a code that a computer can understand. Good programmers write code that humans can easily understand.
Do comment, which version do you like more?
seleniumautomation automationtesting tipsandtricks easier Validation apiautomation
1) Using Java (Lengthy way) : Create a utility and use it:>> import java.io.BufferedOutputStream; import org.openqa.selenium.io.Zip; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class UnzipUtil { private static final int BUFFER_SIZE = 4096; public void unzip (String zipFilePath, String destDirectory) throws IOException { File destDir = new File(destDirectory); if (!destDir.exists()) { destDir.mkdir(); } ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); ZipEntry entry = zipIn.getNextEntry(); // to iterates over entries in the zip folder while (entry != null) { String filePath = destDirectory + File.separator + entry.getName(); if (!entry.isDirectory()) { extractFile (zipIn, filePath);
Comments
Post a Comment