Posts

Showing posts from 2020

Parallel Execution In TestNG Framework Using ThreadLocal Concept

  Parallel Execution We can achieve parallel execution In TestNG Framework by implementing ThreadLocal Concept. We can execute the independent test methods in parallel resulting in reducing the test execution time. BrowserUtility.java This class file contains a methods named by "createDriverInstance" which returns the reference variable of WebDriver Type based on the browser type (chrome or firefox or IE or edge) provided in the parameter. package parallelExecution; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.ie.InternetExplorerOptions; public class BrowserUtility { public static WebDriver createDriverInstance(String browserType ) { WebDriver driver = null ;...

Encoding and Decoding in Selenium using Base64 Class of Java

What is Base64? Base64 is an encoded scheme that converts binary data in to text format so that encoded textual data can be easily transported over network un-corrupted and without any data loss. Simple Program: package encodeAndDecode; import java.util.Base64; public class EncodeText { public static void main(String[] args) { // TODO Auto-generated method stub String username = "mercury" ; // Encode Username byte [] encodedByte = Base64.getEncoder().encode( username .getBytes()); String encodedText = new String( encodedByte ); System.out.println( "Encoded Username : " + encodedText ); //Decode Username byte [] decodedByte = Base64.getDecoder().decode( encodedByte ); String decodedText = new String( decodedByte ); System.out.println( "Decoded Username : " + decodedText ); } Output: Encoded Username : bWVyY3VyeQ== Decoded Username : mercury Usage In Selenium: We can keep the encoded data ...

Data Driven Testing Using JSON File and TESTNG Data Provider

If you want to parameterize your test with multiple sets of data then it is obvious that you have to take the help of @DataProvider annotation of TestNG. In this article, we are going to see how can we fetch data from a JSON File and do parameterization using @DataProvider annotation. Dependency Require d: <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple --> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> JSON File: { "url" : "http://newtours.demoaut.com" , "loginCredentials" : [ { "username" : "mercury" , "password" : "mercury" , "loginSuccessTitle" : "Find a Flight: Mercury Tours:" }, { "username" : "mercury" , "password" : "!@#$%^...

Data Driven Testing using JSON File In Selenium WebDriver

Data Driven Testing is nothing but fetching test data from an external data source and use it in the test script. External data source can be an excel file or a properties file or a text file or a database or a JSON file. In this article, we are going to learn how to fetch test data from a JSON file and use it in the test program. Dependency Required : <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple --> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> Add the above dependency to the pom.xml file of your Maven Project. JSON File: { "url" : "http://newtours.demoaut.com" , "username" : "mercury" , "password" : "mercury" , "loginSuccessTitle" : "Find a Flight: Mercury Tours:" } ...