Friday, March 24, 2023

Automating Image Upload using Selenium WebDriver: A Step-by-Step Guide

 package Practice;

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.Toolkit;

import java.awt.datatransfer.StringSelection;

import java.awt.event.KeyEvent;

import java.time.Duration;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class Get_Photo {

@SuppressWarnings("deprecation")

public static void main(String[] args) throws InterruptedException, AWTException {

System.setProperty ("webdriver.chrome.driver", "D:\\SURIYA\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));

driver.get("http://localhost:3000/SignUp");

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// identify image

WebElement ph = driver.findElement(By.xpath("//button[normalize-space()='photo']"));

ph.click();

Thread.sleep(2000);

Robot rb = new Robot();

StringSelection str = new StringSelection("C:\\Users\\Admin\\Surya.jpg");

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(str, null);

// press Contol+V for pasting

rb.keyPress(KeyEvent.VK_CONTROL);

rb.keyPress(KeyEvent.VK_V);

// release Contol+V for pasting

rb.keyRelease(KeyEvent.VK_CONTROL);

rb.keyRelease(KeyEvent.VK_V);

// for pressing and releasing Enter

rb.keyPress(KeyEvent.VK_ENTER);

rb.keyRelease(KeyEvent.VK_ENTER);

Thread.sleep(3000);

}

}

Thursday, March 23, 2023

Headless Browser Testing in Selenium: Best Tools and Frameworks to Use

 import java.io.IOException;

import org.openqa.selenium.NotFoundException;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;

public class Headless_Browser {

public static void main(String[] args) throws IOException, NotFoundException {

ChromeOptions options = new ChromeOptions();

options.addArguments("headless");

WebDriver driver = new ChromeDriver(options);

driver.get("https://suriyaparithy.blogspot.com/");

System.out.println("Title of the page is -> " + driver.getTitle());

}

}

The Power of API Testing: How it Can Save Your Business Time and Money

 1. Core Functionality Testing: 

  • This kind of testing provides access to the entire system without the need for a user interface. The functionalities of the application would be evaluated end-to-end without the need for GUI (Graphical User Interface) which helps in detecting issues that can prove to be bigger at the time of GUI testing.

2. Time and Cost Effectiveness: 

  • This is usually less time-consuming when compared to GUI testing. It also requires less code for testing the functionalities thereby making it easier to set up and get faster access to test coverage. It also results in effective cost savings for the project.

3. Language-Independent: 

  • The data transfer between the test platform to the applications is done utilizing XML or JSON and is completely independent of the languages used in developing the systems. The test automation suite can be developed in any language.

4. Ease of Integration with GUI:

  •  API testing provides highly flexible test suites that help in easier integration with the GUI tests. For instance, before the GUI test cases are initiated, employing API test cases, we can create sample users that can act as an initial base for the GUI tests.

The Power of Headless Browser Testing: Enhancing Your QA Strategy

What is Headless Testing?
  • Headless testing is a method for evaluating a website’s or online application’s functionality without having to use a web browser. The test script simulates operations like clicking buttons and filling out form fields by sending commands directly to the website’s source code rather than engaging with it through the UI. As a result, testing may be done more quickly and effectively because there is no need to load a full web browser; the test script can instead run in the background.

Advantages of Headless Testing:
  1.  Speed of Execution: Headless tests run substantially quicker than tests executed on a real browser. The primary reason for this is that your tests aren’t having to start up a browser UI each time. This means they can avoid the time it takes a real browser to load JavaScript, CSS, and render HTML on a website. I’ve seen estimated execution time savings in the range of 7-15%.
  2.  CICD: Because it is so much quicker, it makes it ideal for continuous integration and delivery (CI/CD) pipelines.
  3.  Server Testing: It can also be helpful for testing web applications in contexts without a UI, such as servers.
  4.  Multi-Tasking: The test script can run in the background and finish tests more rapidly because it does not need to open a full web browser.
  5.  Shift-Left: Because it runs so much quicker than real browser testing, you can get the results of your testing much faster.

Disadvantages of Headless Testing:
  1.  User Experience: Headless testing may not always correctly imitate the user experience, which is one potential problem. The test script may not always correctly reflect how a user would actually interact with the website or web application because it is engaging directly with the source code rather than through a UI.
  2.  UX or Visual Design: Additionally, headless testing might not be able to completely test specific features of a website or web application, including the user interface or visual design.
  3.  Debugging: Debugging with headless can be challenging. Typically you will need to run the traditional way to get to the bottom of failures.
  4.  Real-time test execution visual: When running headless you don’t get the option to watch your test running on the UI.

Headless Testing Use Cases:
  •  Simulating multiple browsers on a single machine.
  •  Running tests on a headless system without a UI.
  •  Element testing – since headless browsers render and interpret CSS & HTML like a real browser, you can use them to test style elements such as buttons, forms, links, etc…
  •  Extracting values from a page/scraping.
  •  Extracting a PDF.
  •  Generate test data.
  •  Performance issues such as SSL, front- and back-end code, and load considerations, as well as non-graphic elements such as response time, error handling, and access to remote resources, can all be evaluated using headless testing.

Common Headless Browsers:
  •  For headless testing, a number of tools and frameworks are available, including Headless Chrome, PhantomJS, HtmlUnit, Firefox, Puppeteer, and Splinter. These tools allow you to create and execute test scripts in a number of different computer languages, such as Java, Python, and JavaScript.

QR Access: Simplify Your Entry Process with Java Code Implementation

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import com.google.zxing.BinaryBitmap;

import com.google.zxing.LuminanceSource;

import com.google.zxing.MultiFormatReader;

import com.google.zxing.NotFoundException;

import com.google.zxing.Result;

import com.google.zxing.client.j2se.BufferedImageLuminanceSource;

import com.google.zxing.common.HybridBinarizer;

public class QR_Code_Scan {

public static void main(String[] args) throws IOException, NotFoundException {

File file = new File("D:\\SURIYA\\my_web.png");

BufferedImage bufferedimage = ImageIO.read(file);

LuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedimage);

BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

// To Extract information from QR code;

Result result = new MultiFormatReader().decode(binaryBitmap);

String decodedText = result.getText();

System.out.println(decodedText);

}

}