Integration testing in Testing Fundamentals - Build an Automation Script
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class LoginPage: def __init__(self, driver): self.driver = driver self.username_input = (By.ID, 'username') self.password_input = (By.ID, 'password') self.login_button = (By.ID, 'loginBtn') def enter_username(self, username): WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.username_input)).send_keys(username) def enter_password(self, password): WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.password_input)).send_keys(password) def click_login(self): WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(self.login_button)).click() class DashboardPage: def __init__(self, driver): self.driver = driver self.welcome_message = (By.ID, 'welcomeMsg') def get_welcome_text(self): return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.welcome_message)).text class TestIntegrationLoginDashboard(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_login_and_dashboard_integration(self): login_page = LoginPage(self.driver) login_page.enter_username('testuser') login_page.enter_password('Test@1234') login_page.click_login() # Verify URL changed to dashboard WebDriverWait(self.driver, 10).until(EC.url_contains('/dashboard')) self.assertIn('/dashboard', self.driver.current_url) dashboard_page = DashboardPage(self.driver) welcome_text = dashboard_page.get_welcome_text() self.assertEqual(welcome_text, 'Welcome, testuser!') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test uses Selenium with Python's unittest framework to automate the integration test.
We define two page objects: LoginPage and DashboardPage. This keeps code organized and easy to maintain.
In test_login_and_dashboard_integration, we open the login page, enter username and password, and click login.
We then wait until the URL contains '/dashboard' to confirm navigation.
Finally, we verify the welcome message text matches the expected string.
Explicit waits ensure elements are ready before interacting, avoiding flaky tests.
Setup and teardown methods open and close the browser cleanly for each test run.
Now add data-driven testing with 3 different user credentials to verify login and dashboard integration for multiple users.
Practice
integration testing in software development?Solution
Step 1: Understand integration testing scope
Integration testing focuses on testing combined parts or modules of software to ensure they work together.Step 2: Differentiate from other testing types
Unit testing checks individual parts, system testing checks the whole system, and performance testing checks speed/load.Final Answer:
To check if different modules work together correctly -> Option DQuick Check:
Integration testing = module interaction check [OK]
- Confusing integration testing with unit testing
- Thinking integration testing is the final system test
- Mixing integration testing with performance testing
Solution
Step 1: Recall testing order
Unit testing is done first on individual parts, then integration testing checks combined parts, finally system testing checks the whole system.Step 2: Match sequence with options
Only Unit testing -> Integration testing -> System testing correctly shows Unit testing -> Integration testing -> System testing.Final Answer:
Unit testing -> Integration testing -> System testing -> Option BQuick Check:
Testing order = Unit -> Integration -> System [OK]
- Mixing up the order of testing phases
- Thinking integration testing comes after system testing
- Assuming unit testing is last
ModuleA returns a number, and ModuleB doubles that number. Which integration test output is correct if ModuleA returns 5?Solution
Step 1: Understand module behavior
ModuleA returns 5; ModuleB doubles input, so it should return 5 * 2 = 10.Step 2: Determine integration output
When ModuleB receives 5 from ModuleA, output is 10, so integration test should expect 10.Final Answer:
10 -> Option AQuick Check:
5 doubled = 10 [OK]
- Confusing input and output values
- Multiplying instead of doubling
- Expecting original value without processing
Solution
Step 1: Analyze null pointer error in integration
Null pointer errors usually happen when one module expects data from another but receives nothing or null.Step 2: Connect error to module interaction
If modules are not properly connected or data is missing, integration test fails with null pointer.Final Answer:
Modules are not properly connected or data is missing between them -> Option AQuick Check:
Null pointer = missing data between modules [OK]
- Assuming unit tests guarantee integration success
- Blaming system testing for integration errors
- Ignoring environment issues unrelated to null pointers
Auth, Profile, and Notifications. Auth sends user info to Profile, which then triggers Notifications. Which integration test scenario best checks the full flow?Solution
Step 1: Identify integration points
The flow involvesAuthsending data toProfile, thenProfiletriggeringNotifications. Testing this chain checks integration.Step 2: Choose scenario covering full module interaction
Only TestAuthsending data toProfileandProfiletriggeringNotificationstests the full flow of data and triggers across all three modules together.Final Answer:
Test Auth sending data to Profile and Profile triggering Notifications -> Option CQuick Check:
Full flow test = Auth -> Profile -> Notifications [OK]
- Testing modules in isolation only
- Skipping intermediate module triggers
- Ignoring data flow between modules
Ready to prove it?
Pass the test and this pattern moves unknown
