Posts

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:" } ...

Fillo Excel API - Excel Read Write

Image
FILLO API Fillo is an Excel API for Java. Using Fillo API, we can consider excel sheet as data base and fetch data from excel [ .xls OR .xlsx ] by passing SQL query. Using Fillo API, we can insert new data and update existing data in Excel File. Fillo API supports below queries SELECT SELECT WITH WHERE CONDITION SELECT WITH LIKE OPERATOR INSERT UPDATE DELETE DOWNLOAD FILLO API https://codoid.com/fillo/ Fillo Libray can be downloaded from the above URL and configured in the JAVA project to start using it. If you are using MAVEN project then you can add below dependency in the pom.xml file and start using it. 1 2 3 4 5 <dependency>    <groupId> com.codoid.products </groupId>    <artifactId> fillo </artifactId>    <version> 1.21 </version> </dependency> Package Structure : pom.xml : ...

How to handle calendar or date picker using dynamic XPATH?

Image
Most of the times selecting a particular date from a date picker is a tedious job. We can easily automate this scenario with the help of dynamic XPATH. AUT : https://www.spicejet.com/ Test Steps : Navigate to  https://www.spicejet.com/ Enter Departure City Enter Arrival City Click on "Depart Date" date picker and select an appropriate date of departure Click on 'Flights' icon to view the available flights Test Script : package seleniumwebdriverbestpractices; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class HandleCalendarUsingDynamicXPATH { static WebDriver driver; public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub System.setProperty("webdriver....

How to do Page Scroll Using JavascriptExecutor?

package seleniumwebdriverbestpractices; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class ScrollPage { WebDriver driver; @Test public void scrollingPageTest() throws Throwable{ System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\drivers\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // driver.get("https://www.spicejet.com/"); driver.get("https://www.w3schools.com/"); driver.manage().window().maximize(); JavascriptExecutor js = (JavascriptExecutor)driver; // Scroll Down js.executeScript("window.scrollBy(0,1000)", ""); Thread.sleep...