0% found this document useful (0 votes)
44 views15 pages

SPM Lab Manual

The document outlines a series of software testing experiments focusing on various methodologies, including GUI checkpoints, database checkpoints, and data-driven tests using Selenium and other tools. It provides example programs for each experiment, demonstrating how to implement tests for web applications, database interactions, and even a Windows calculator application. The experiments cover a range of testing techniques, including silent mode execution and batch testing, aimed at enhancing the testing process.

Uploaded by

raios1747
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views15 pages

SPM Lab Manual

The document outlines a series of software testing experiments focusing on various methodologies, including GUI checkpoints, database checkpoints, and data-driven tests using Selenium and other tools. It provides example programs for each experiment, demonstrating how to implement tests for web applications, database interactions, and even a Windows calculator application. The experiments cover a range of testing techniques, including silent mode execution and batch testing, aimed at enhancing the testing process.

Uploaded by

raios1747
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SOFTWARE TESTING METHODOLOGIES LAB

List of Experiments
1. Recording in context sensitive mode and analog mode
2. GUI checkpoint for single property
3. GUI checkpoint for single object/window
4. GUI checkpoint for multiple objects
5. a. Bitmap checkpoint for object/window
b. Bitmap checkpoint for screen area
6. Database checkpoint for Default check
7. Database checkpoint for custom check
8. Database checkpoint for runtime record check
a. Data driven test for dynamic test data submission
b. Data driven test through flat files
c. Data driven test through front grids
d. Data driven test through excel test
9.a. Batch testing without parameter passing
b. Batch testing with parameter passing
10. Data driven batch
11. Silent mode test execution without any interruption
12. Test case for calculator in windows application

1. Recording in context sensitive mode and analog mode


In Selenium, there isn't a built-in feature specifically labeled as "context sensitive mode" or "analog
mode" for recording. However, Selenium IDE, a tool for recording and playing back interactions with
the browser, does provide functionalities for recording user actions and generating corresponding
test scripts.

1. Recording User Actions: Selenium IDE allows you to record various user actions such as
clicks, typing, selections, etc., while you navigate through a website.

2. Generating Test Scripts: As you interact with the website, Selenium IDE captures these
actions and generates corresponding test scripts in various programming languages such as
Java, Python, C#, etc.

3. Context-Sensitive Recording: While recording with Selenium IDE, it captures the context of
the user actions within the DOM (Document Object Model) of the web page. This means it
records actions relative to the elements on the page, making the recorded script more
robust against changes in the layout or structure of the page.

4. Analog Mode: The term "analog mode" isn't a standard term in Selenium or Selenium IDE. If
you mean simulating user interactions such as mouse movements or keyboard inputs in a
human-like manner, Selenium IDE doesn't have built-in features for this. However, Selenium
WebDriver (the programmatic interface to Selenium) allows you to perform such actions
programmatically using third-party libraries or extensions.

To summarize, Selenium IDE records user actions in a context-sensitive manner, but it doesn't
directly support an "analog mode" for simulating human-like interactions. For more complex
interactions or custom behaviors, you might need to combine Selenium WebDriver with other tools
or libraries.

2. GUI checkpoint for single property

Program

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstTest {

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

System.setProperty("webdriver.chrome.driver", "C:\\TestingEssentials\\
chromedriver\\chromedriver-win64\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.navigate().to("https://www.facebook.com");
driver.manage().window().maximize();

//driver.findElement(By.name("username")).sendKeys("mercury");

WebElement username =driver.findElement(By.name("username"));


username.sendKeys("mercury");// enter username

driver.findElement(By.name("Log In")).click();

String exptitle="facebook";
String acttitle= driver.getTitle();//return actual title of the page

//comparing two strings//validation


if(exptitle.equals(acttitle))
{
System.out.println("Test is passed");

}
else
{
System.out.println("Test is failed");
}

driver.quit();
}

}
OUTPUT

2.GUI checkpoint for single object/window


program

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstTest {

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

System.setProperty("webdriver.chrome.driver", "C:\\TestingEssentials\\
chromedriver\\chromedriver-win64\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.navigate().to("https://www.facebook.com");

driver.quit();
}

OUTPUT

4. GUI checkpoint for multiple objects


Program

package mycode;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class PRGM {

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

System.setProperty("webdriver.chrome.driver", "C:\\TestingEssentials\\
chromedriver\\chromedriver-win64\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.navigate().to("https://www.facebook.com");

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

//driver.findElement(By.name("username")).sendKeys("mercury");

WebElement username =driver.findElement(By.name("username"));


username.sendKeys("mercury");// enter username

driver.findElement(By.name("password")).sendKeys("mercury");//enter password
driver.findElement(By.name("Log In")).click();

String exptitle="facebook";
String acttitle= driver.getTitle();//return actual title of the page

//comparing two strings//validation


if(exptitle.equals(acttitle))
{
System.out.println("Test is passed");

}
else
{
System.out.println("Test is failed");
}

driver.quit();
}
}

Output

5.a. Bitmap checkpoint for object/window

Program
from selenium import webdriver

# Initialize the WebDriver (assuming Chrome in this example)


driver = webdriver.Chrome()

# Open a webpage
driver.get('https://example.com')

# Find the element you want to capture (e.g., a button, a div, etc.)
element = driver.find_element_by_xpath("//button[@id='example_button']")

# Take a screenshot of the element


element.screenshot('element_screenshot.png')

# Take a screenshot of the entire window


driver.save_screenshot('window_screenshot.png')

# Close the browser


driver.quit()
output
b. Bitmap checkpoint for screen area

Program

from selenium import webdriver

# Initialize the WebDriver


driver = webdriver.Chrome()

# Open the webpage


driver.get("https://example.com")

# Find the element you want to capture (e.g., an image, a section of text, etc.)
element = driver.find_element_by_xpath("//div[@id='example']")

# Get the location and size of the element


location = element.location
size = element.size

# Take a screenshot of the entire screen


driver.save_screenshot("screenshot.png")

# Calculate the coordinates of the element


left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']

# Crop the screenshot to the area of the element


from PIL import Image
screenshot = Image.open("screenshot.png")
area = (left, top, right, bottom)
cropped_image = screenshot.crop(area)
cropped_image.save("element_screenshot.png")

# Close the browser


driver.quit()

Output:

6. Database checkpoint for Default check

Program
from selenium import webdriver
from sqlalchemy import create_engine, select, text
from sqlalchemy.orm import sessionmaker
from your_application import models # Import your SQLAlchemy models

# Set up Selenium WebDriver


driver = webdriver.Chrome()
driver.get("http://your_web_application.com")
# Perform check-in action using Selenium
# (code to interact with the web application)

# Database interaction using SQLAlchemy


engine = create_engine('sqlite:///your_database.db')
Session = sessionmaker(bind=engine)
session = Session()

# Retrieve data from the database


check_ins = session.execute(select(models.CheckIn).where(models.CheckIn.user_id ==
user_id)).fetchall()

# Assert the expected data


assert len(check_ins) > 0 # Assuming at least one check-in is expected

# Close Selenium WebDriver


driver.quit()

# Clean up (if necessary)


# (code for cleanup tasks)

# Close SQLAlchemy session


session.close()

7. Database checkpoint for custom check

Program

import pymysql
from selenium import webdriver

# Function to query the database and return results


def get_user_details_from_db(user_id):
connection = pymysql.connect(host='localhost',
user='user',
password='password',
db='database_name',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = "SELECT * FROM users WHERE id = %s"
cursor.execute(sql, (user_id,))
result = cursor.fetchone()
return result
finally:
connection.close()

# Initialize Selenium WebDriver


driver = webdriver.Chrome()

# Open the website


driver.get("https://example.com")

# Perform actions in the UI using Selenium


# ...

# Assuming you've performed some action and retrieved user ID from the UI
user_id = "123"

# Retrieve user details from the UI using Selenium


# ...

# Compare UI data with Database data


ui_data = ... # Extracted UI data, fill this part accordingly
db_data = get_user_details_from_db(user_id)

# Example assertion
assert ui_data == db_data, "Data mismatch between UI and Database"

# Close the WebDriver


driver.quit()

8. Database checkpoint for runtime record check

Program
from selenium import webdriver
from sqlalchemy import create_engine, text

# Set up Selenium WebDriver


driver = webdriver.Chrome()

# Set up SQLAlchemy engine


engine = create_engine('database_connection_string')

# Open the web page


driver.get('http://example.com')

# Query the database


with engine.connect() as connection:
query = text("SELECT * FROM records WHERE condition = :condition")
result = connection.execute(query, condition='some_condition')
records_from_db = result.fetchall()

# Perform assertions
# Example assertion
assert len(records_from_db) == expected_number_of_records

# Close the browser


driver.quit()

Output

9.Batch testing without parameter passing

Program:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class MyTests {


WebDriver driver;

@Test
public void test1() {
// Your test logic here
System.out.println("Test 1 executed");
}

@Test
public void test2() {
// Your test logic here
System.out.println("Test 2 executed");
}

// More test methods...


}

Output

10. Data driven batch

Program

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataDrivenTest {

@DataProvider(name = "testData")
public Object[][] testData() {
// Here you would read your test data from a file or database
return new Object[][] {
{"username1", "password1"},
{"username2", "password2"},
// Add more data sets as needed
};
}

@Test(dataProvider = "testData")
public void loginTest(String username, String password) {
// Your test logic here, using the provided username and password
System.out.println("Logging in with username: " + username + " and password: " +
password);
// Example Selenium code to interact with the login page
// driver.findElement(By.id("username")).sendKeys(username);
// driver.findElement(By.id("password")).sendKeys(password);
// driver.findElement(By.id("loginButton")).click();
}
}

Output
11. Silent mode test execution without any interruption

Program

from selenium import webdriver


from selenium.webdriver.chrome.options import Options

# Configure Chrome options for headless mode and silent execution


chrome_options = Options()
chrome_options.add_argument("--headless") # Run Chrome in headless mode
chrome_options.add_argument("--disable-gpu") # Disable GPU acceleration
chrome_options.add_argument("--no-sandbox") # Disable sandbox mode (Linux)

# Initialize WebDriver with Chrome options


driver = webdriver.Chrome(options=chrome_options)

# Example test
driver.get("https://www.example.com")
print("Title: ", driver.title)

# Clean up
driver.quit()

12. Test case for calculator in windows application

Program

from selenium import webdriver


from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

# Start the WinAppDriver before executing this script

# Desired capabilities for WinAppDriver


desired_caps = {
"app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
}

# Initialize the WebDriver


driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723',
desired_capabilities=desired_caps
)

# Wait for the calculator to load


time.sleep(5)

# Function to perform a calculation


def perform_calculation(expression):
# Clear the calculator
clear_button = driver.find_element(By.NAME, "Clear")
clear_button.click()

# Enter the expression


for char in expression:
driver.find_element(By.NAME, char).click()

# Get the result


result_button = driver.find_element(By.NAME, "Equals")
result_button.click()
result = driver.find_element(By.ID, "CalculatorResults").text

return result

# Test case
def test_calculator():
# Test addition
assert perform_calculation("1+1") == "2"

# Test subtraction
assert perform_calculation("5-3") == "2"

# Test multiplication
assert perform_calculation("2*3") == "6"

# Test division
assert perform_calculation("6/2") == "3"

# Test complex expression


assert perform_calculation("4*5-3+8/2") == "21"

# Execute the test case


test_calculator()
# Close the WebDriver session
driver.quit()

Output

You might also like