Did you know that if the element variable name is the same with the element id or element name, it's not mandatory to use FindBy annotation as these are known as Direct Locators?
Like this:
public class FindByExample {
private WebDriver driver;
@FindBy(id = "username") //here the text box has the locator id=username.
private WebElement uname;
@FindBy(name = "password") //here the text box has the locator name=password.
private WebElement pwd;
public FindByExample(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
The above code can be written with NO FindBy annotations if the web element variables have the same name or ID:
public class FindByExample {
private WebDriver driver;
private WebElement username;
private WebElement password;
public FindByExample(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
selenium easierWay tipsAndTricks # testautomation seleniumAutomation FindBy PageFactory
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