Skip to main content

Posts

Showing posts from November, 2024

How to Handle File Download using Playwright Java

   Purpose  When performing website testing, validating file upload functionality is crucial as users need to upload documents and images, such as in job portals, eCommerce websites, cloud storage systems, and others. Automating this process ensures reliability and efficiency in testing these functionalities, and automated testing tools like Selenium provide effective solutions for this task. In this blog, we delve into how to handle file upload in Playwright , exploring techniques to handle file upload and automate file upload functionality. Playwright – File Download Download objects are dispatched by page via the Page.onDownload(handler) event. All the downloaded files belonging to the browser context are deleted when the browser context is closed. Download event is emitted once the download starts. Download path becomes available once download completes. Playwright Method to  File Download / Wait for the download to start Download download = page.waitForDownload(...

How to Handle File Upload using Playwright Java

 Purpose  When performing website testing, validating file upload functionality is crucial as users need to upload documents and images, such as in job portals, eCommerce websites, cloud storage systems, and others. Automating this process ensures reliability and efficiency in testing these functionalities, and automated testing tools like Playwright provide effective solutions for this task. In this blog, we delve into how to handle file upload in Playwright, exploring techniques to handle file upload and automate file upload functionality. Playwright – File Upload You can select input files for upload using the Locator.setInputFiles() method.  It expects first argument to point to an input element with the type "file".  Multiple files can be passed in the array.  If some of the file paths are relative, they are resolved relative to the current working Playwright Method to  File Upload // Select one file page.locator("(//input[@type='file'])[1]").setInputF...

Automation Test Plan & Strategy

  Automation Test Plan & Strategy is a detailed document that outlines the approach and processes for automating the testing of a software application. This document acts as a roadmap to guide the testing team and ensure consistent execution. Below is a high-level overview of key components to include in an automation test plan and strategy: 1. Scope of Automation Identify the test cases or functionalities to be automated. Specify the extent of test coverage (e.g., UI, API, backend processes). Define what will not be automated and justify why. 2. Objectives and Goals State the primary purpose of automation (e.g., reduce manual testing time, improve test coverage, increase reliability). Set measurable goals like reducing testing time by a certain percentage or automating X number of test cases per release. 3. Automation Tools and Frameworks List the tools to be used (e.g., Selenium, Playwright, Appium, TestNG). ...

What is TestNG and Key Feature

 What is TestNG and Key Feature  What is TestNG ? TestNG is a testing framework for Java Programming Language Testing Official Website  : https://testng.org/ Details Answers for TestNG : TestNG is a testing framework which can be used for unit, integration, end-to-end , functional testing Installation of TestNG :: Add Dependencies - TestNG How To Install TestNG In IntelliJ? IntelliJ is yet another IDE for running the TestNG test cases other than Eclipse. Intellij requires dependencies to be downloaded externally or through a direct link ( if it is a Maven Project ). Since we will be running tests on Java, we need to download external TestNG Jar File onto our system. How To Download TestNG Jar? TestNG Jar is very easy to install. Visit   Maven Repositories  and search for   TestNG   in the search bar.  

What is HashMap and HashTable in Java and Sample Program

Map Key Features  Map does not inherit from the Collection interface.  Map doesn't allow duplicate keys, but you can have duplicate values Key-Value Pair Storage: Maps store data as key-value pairs. Unique Keys: Each key in a map must be unique, although multiple keys can map to the same value. Null Handling: Some implementations allow null keys and/or values, while others do not. What is HashMap  Uses a hash table to store the mappings. Allows one null key and multiple null values. Does not maintain any specific order of the keys. Not synchronized, making it suitable for single-threaded use. Use Case: When you don’t need sorted keys or thread safety, and you need efficient lookups and insertions.  Primary operations you can perform on the maps in Java are: Adding elements Removing elements Changing elements Iterating through the map package com.example ; import java.util.HashMap ; import java.util.Map ; public class HashMapExample { public static void main ( Str...

What is Set in Java Collection and simple program

Collection -Set Set interface includes all the methods of the Collection interface. Its because Collection is a super interface of List  Set does not allow duplicate elements.  Does not maintain insertion order HashSet –Operations with Example  Create   a HashSet Adding elements Removing elements Changing elements Iterating through the HashSet package com.example ; import java.util.HashSet ; import java.util.Iterator ; public class HashSetExample { public static void main ( String [] args ) { //Creating HashSet and adding elements HashSet < String > set = new HashSet< String >(); set .add( "Ravi" ); set .add( "Vijay" ); set .add( "Ravi" ); set .add( "Ajay" ); System . out .println( " Hash set is" + set ); //Removing specific element from HashSet set .remove( "Ravi" ); System . out .println( "After invoking remove(object) method...

How to Maximize a Browser window using Playwright Java

  Playwright itself does not have a direct maximize () method like some other browser automation tools, but you can achieve the effect by setting the viewport to the screen size of your display. Below are ways to handle Maximize a browser in Playwright Java  Ø   Setting the viewport to the screen size  o    setViewportSize(1920, 1080): This sets the browser window to a full HD resolution, effectively maximizing it. o    setHeadless(false): Ensures the browser runs in a visible mode so you can see the window being maximized.  Code Snapshot  Playwright playwright = Playwright. create ()   ;   Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));     // Create a new browser context   BrowserContext context = browser.newContext(new Browser.NewContextOptions()          .setViewportSize(1920, 1080));     ...

How to handle JS Alerts in Playwright?

 What are JS Alerts ? An alert box is often used if you want to make sure information comes through to the user. JavaScript has three kind of popup boxes:  Alert box,  Confirm box, and  Prompt box.  alert(), confirm(), prompt() dialogs ​ By default, dialogs are auto-dismissed by Playwright, so you don't have to handle them. However, you can register a dialog handler before the action that triggers the dialog to either  Dialog.accept()  or  Dialog.dismiss()  it. page.onDialog(dialog -> System.out.println(dialog.message())); Note :  If there is no listener for  Page.onDialog(handler) , all dialogs are automatically dismissed. For Prompt alert we need handle explicitly write page listener onDialog methods  page.onDialog(dialog -> {             System.out.println(dialog.message());             //dialog.accept("Accepting with Entered data");       ...

How to handle Playwright IFrame ?

 Playwright – Handling Iframe An iFrame is commonly known as an inline frame which is nothing but an HTML document embedded inside another HTML document. iFrames are a simpler way to embed a web page inside another web page.  iFrames are mostly used to display external information on the webpage like displaying advertisements and videos from third party sources.  iFrame is basically a tag used in HTML5 like <iframe></iframe>.  iFrame is a HTML document embedded inside an HTML document. iFrame is defined by an <iframe></iframe> tag in HTML. With this tag, you can identify an iFrame while inspecting the HTML tree. How to Identify  iFrames on Web Page ?   There are some methods from which we can identify if there is any iframe present on the webpage or not. Step 1: Search the iframe on the inspection box Step 2: Right-click on that web element Step 3: Through view page source Playwright Method to Handling Frames ? Get frame using the fr...