Tuesday, July 30, 2024

Global vs Environment vs Collection Variables in Postman – Key Differences Explained

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 Selenium Script to Extract Two Numbers from a Web Page Automatically

 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.

Monday, July 15, 2024

Selenium Interview Questions and Answers - PART 2

1. WebDriver is interface or class?
  • WebDriver is an interface in Selenium.
2. If we do not add a driver exe file what will happen and what kind of exception will be generated?
  • If the driver executable is not added, Selenium won't be able to communicate with the browser, and a WebDriverException will be thrown.
3. What is the difference between close and quit?
  • close(): Closes the current browser window.
  • quit(): Closes all the browser windows and ends the WebDriver session.
4. Difference between get and navigate().to() ?
  • get(): Loads a new web page in the current browser window.
  • navigate().to(): This does the same as get() but allows for additional navigation options like back, forward, and refresh.
5. Difference between findElement and findElements?
  • findElement: Returns a single WebElement or throws  NoSuchElementException if not found.
  • findElements: Returns a list of WebElements. If no elements are found, it returns an empty list.
6. How do you get all the links on the current page? Which locator will you use other than XPath?
  • You can use the CSS selector a to find all links.
List<WebElement> links = driver.findElements(By.cssSelector("a"));

7. Methods of WebDriver?
  • Some common methods are: get() , getCurrentUrl() , getTitle(), findElement() , findElements() , getPageSource() , close() , quit(), navigate() , manage() .
8. What is the use of the getCurrentPageSource method?
  • It returns the source code of the current page.
9. When do we go for the findElements method and what is the return type?
  • Use findElements when you expect multiple elements. It returns a list of WebElements.
10. Why do we get WebDriverException?
  • This exception is thrown when WebDriver is unable to interact with the browser. Possible reasons include incorrect WebDriver setup, browser crashes, or network issues.
11. Absolute and Relative XPath?
  • Absolute XPath: Starts from the root and follows a complete path (e.g., /html/body/div ).
  • Relative XPath: Starts from the middle of the HTML DOM structure (e.g., //div[@id='example'] ).