Tuesday, October 1, 2024

Run two browsers simultaneously in Selenium

 package TEST;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;


public class Selenium_Latest {


public static void main(String[] args) {

// Create and start two threads, one for each browser.

Thread chromeThread = new Thread(new BrowserRunnable("chrome"));

Thread firefoxThread = new Thread(new BrowserRunnable("firefox"));


chromeThread.start();

firefoxThread.start();

}


}


// Runnable class for launching a browser

class BrowserRunnable implements Runnable {

private String browserType;


public BrowserRunnable(String browserType) {

this.browserType = browserType;

}


@Override

public void run() {

WebDriver driver = null;


if (browserType.equals("chrome")) {

driver = new ChromeDriver();

} else if (browserType.equals("firefox")) {

driver = new FirefoxDriver();

}


if (driver != null) {

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


// Optionally, get the title and print it for each browser

String title = driver.getTitle();

System.out.println(browserType + " Browser - Page Title: " + title);


// Closing the browser after operation

driver.quit();

}

}

}

Tuesday, July 30, 2024

Difference Between Global, Environment, and Collection Variables in Postman

Global Variables:
  • Stored globally across all requests and collections.
  • It can be accessed from any request or collection.
  • Use cases: API keys, common headers, or base URLs
Environment Variables:
  • Stored within a specific environment (e.g., dev, staging, prod).
  • It can be accessed only from requests within the same environment.
  • Use cases: Environment-specific settings, such as URLs, credentials, or timeouts.
Collection Variables:
  • Stored within a specific collection.
  • It can be accessed only from requests within the same collection.
  • Use cases: Collection-specific settings, such as API endpoints, headers, or query parameters.

Monday, July 29, 2024

Selenium XPath in detail

What is XPATH?
  • It is an XML path.
  • It is one of the locator types in selenium.
  • It uses path expression to navigate in XML documents and to identify a node or number of nodes.
  • XPath is used to handle complex and dynamic paths.
 
Types of XPATH in Selenium:
  1. Absolute XPath
  2. Relative XPath
 
What is Absolute XPath?
  • Absolute path starts from <HTML> tag.
  • It uses / ( forward slash ).
  • It is used to identify any element direct way by consider all the tag starts from <HTML> tag.
  • It is much more faster than "Relative xpath" as it holds the direct path to the target node/tag/element from start <Html> tag.
  • But we will mostly use this one if it holds a long string path and is difficult to maintain or handle. It is not a shortend path.
 
What is Relative XPath?
  • It uses //  ("forward double slash") .
  • It will consider any node/element/tag as a refernce point from where either we can traverse forard or reverse direction to identify target node/tag.
  • It is mostly used as we are considering any node as a reference node (stable node) from a DOM.

Saturday, July 27, 2024

Java code to automate the extraction of two numbers from a web page

 package system;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;

public class Practice {

   WebDriver driver;

@BeforeMethod
public void setUp() {
  WebDriverManager.chromedriver().setup();
  driver = new ChromeDriver();
}

@Test(description = "extraction of two numbers from a web page")
public void test() throws InterruptedException {

driver.get("https://ultimateqa.com/complicated-page");

// Locate the element containing the CAPTCHA question
WebElement captchaElement = driver.findElement(By.className("et_pb_contact_captcha_question"));

// Extract the CAPTCHA question text
String captchaText = captchaElement.getText().trim(); // Example: "5 + 6"

// Split the text to get the operands
String[] parts = captchaText.split("\\+");
int firstNumber = Integer.parseInt(parts[0].trim());
int secondNumber = Integer.parseInt(parts[1].trim());

// Calculate the sum
int sum = firstNumber + secondNumber;

// Print the sum (for debugging purposes)
System.out.println("Extracted Numbers: " + firstNumber + " + " + secondNumber + " = " + sum);

// Enter the sum into the CAPTCHA input field
WebElement captchaInputField = driver.findElement(By.className("et_pb_contact_captcha"));
captchaInputField.sendKeys(String.valueOf(sum));
}
}

Tuesday, July 16, 2024

Real-Time Software Testing Interview Questions - Part 2

1. Retesting - Testing only the affected area.

2. Regression Testing - Testing the affected as well as the unaffected area.

3. When will you stop the Testing?
  • When every bug is fixed.
  • When all the test cases are executed and they are passed.
  • Minor bugs are deferred.
   
4. When will you start Testing?
  • Once the developer completes unit testing.
  • Once everything is ready (test environment, test cases, test data).
   
5. Alpha testing - Selective customers will test the new version/software in the development organization's environment.

6. Beta testing - Customers will use this newly developed software in their own environment.

7. Smoke testing - Focusing on Major functionalities in the software through positive test cases.

8. Sanity testing - Focusing on Major functionalities in the software through positive and negative test cases.

9. Quality Assurance - Process-oriented and Verification.

10. Quality Control - Product-oriented and Validation.

11. Waterfall Model :
  • When we have the software already and we want to implement new small features which are very clear- in these cases, we can go with the waterfall model.
  • Disadvantage: Once we moved to the next phase, we never come back to the previous phase.
    
12. Model - Implementation of SDLC.