Posts

Showing posts from January, 2026

How to validate broken link on the webpage using playwright?

1) Handle broken links in Playwright, typically follow a three-step  1)  Extract all links from the page use a locator to find all anchor ( <a> ) tags and then extract their  href  attributes.   2) Filter out invalid or repetitive URL Use Set collection to automatically remove duplicate links and filter out non-HTTP links. 3)  Then verify each URL by sending an HTTP request to check its status code. 2. Implementation Playwright, JS/TS This script uses page.request.get() to check links.  instead navigating to each page. it only fetches the HTTP response without rendering the full UI. 3. Key Strategies for Robust Testing Soft Assertions: Use expect.soft(),  test continues to check the remaining validation even if previous validation. Ex :  if one link is broken (e.g., a 404) , it will continue checking another link. HEAD vs. GET: Use page.request.head() if you only need the status code; it is faster as it doesn't download the entire p...

Java Program Input - "Welcome1","round4","1st3","to2" => output - "Welcome1","to2","1st3","round4"

  import java.util.Arrays ; import java.util.Comparator ; import java.util.regex.Matcher ; import java.util.regex.Pattern ; public class sortingStringUsingLastChar { public static void main ( String [] args) { String [] inputArray = { "Welcome1" , "round4" , "1st3" , "to2" }; System . out .println( "Original Array: " + Arrays . toString ( inputArray )); // Sort the array using a custom comparator Arrays . sort ( inputArray , new NumericStringComparator()); System . out .println( "Sorted Array: " + Arrays . toString ( inputArray )); } /** * A custom Comparator for sorting alphanumeric strings by the integer value they contain. */ static class NumericStringComparator implements Comparator < String > { // Pattern to find the first sequence of digits in a string private static final Pattern intsOnly = Pattern . compile ( " \\ d+ " ); ...

Java Program to remove duplicate char from String,

package RemoveDuplicaeCharFromSttring ; import java.util.LinkedHashSet ; import java.util.Set ; public class RemoveDuplicateCharFromString { public static String removeDuplicateCharsFromSring ( String inputSring) { if (inputSring == null || inputSring.isEmpty()) { return inputSring; } // A LinkedHashSet stores unique characters and maintains insertion order. Set < Character > seen = new LinkedHashSet<>(); // Use a StringBuilder for efficient string building. StringBuilder result = new StringBuilder(); // Iterate through the input string for ( char ch : inputSring.toCharArray()) { // If the character is not already in the set, add it to both the set and the result string if ( seen .add( ch )) { result .append( ch ); } } // Convert the StringBuilder to a String and re...