Bird
Raised Fist0
Testing Fundamentalstesting~15 mins

Integration testing in Testing Fundamentals - Build an Automation Script

Choose your learning style10 modes available
Verify integration between User Login and Dashboard modules
Preconditions (2)
Step 1: Open the application login page
Step 2: Enter 'testuser' in the username field
Step 3: Enter 'Test@1234' in the password field
Step 4: Click the 'Login' button
Step 5: Wait for the dashboard page to load
Step 6: Verify that the dashboard displays the welcome message 'Welcome, testuser!'
✅ Expected Result: User successfully logs in and the dashboard shows the correct welcome message confirming integration between login and dashboard modules
Automation Requirements - Selenium with Python
Assertions Needed:
Verify current URL is the dashboard URL after login
Verify welcome message text matches 'Welcome, testuser!'
Best Practices:
Use explicit waits to wait for elements to be visible or clickable
Use Page Object Model to separate page interactions
Use clear and maintainable locators (id or name preferred)
Include setup and teardown methods to open and close browser
Automated Solution
Testing Fundamentals
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.

Common Mistakes - 3 Pitfalls
{'mistake': 'Using time.sleep() instead of explicit waits', 'why_bad': 'Fixed waits can slow tests and cause failures if elements load slower or faster than expected.', 'correct_approach': "Use Selenium's explicit waits like WebDriverWait with expected conditions to wait only as long as needed."}
Using brittle XPath locators that break easily
Mixing page interaction code directly in test methods
Bonus Challenge

Now add data-driven testing with 3 different user credentials to verify login and dashboard integration for multiple users.

Show Hint

Practice

(1/5)
1. What is the main purpose of integration testing in software development?
easy
A. To test the software's performance under load
B. To test individual functions or methods in isolation
C. To verify the final system meets user requirements
D. To check if different modules work together correctly

Solution

  1. Step 1: Understand integration testing scope

    Integration testing focuses on testing combined parts or modules of software to ensure they work together.
  2. Step 2: Differentiate from other testing types

    Unit testing checks individual parts, system testing checks the whole system, and performance testing checks speed/load.
  3. Final Answer:

    To check if different modules work together correctly -> Option D
  4. Quick Check:

    Integration testing = module interaction check [OK]
Hint: Integration testing checks module connections, not single parts [OK]
Common Mistakes:
  • Confusing integration testing with unit testing
  • Thinking integration testing is the final system test
  • Mixing integration testing with performance testing
2. Which of the following is the correct sequence of testing phases including integration testing?
easy
A. Integration testing -> Unit testing -> System testing
B. Unit testing -> Integration testing -> System testing
C. System testing -> Integration testing -> Unit testing
D. System testing -> Unit testing -> Integration testing

Solution

  1. 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.
  2. Step 2: Match sequence with options

    Only Unit testing -> Integration testing -> System testing correctly shows Unit testing -> Integration testing -> System testing.
  3. Final Answer:

    Unit testing -> Integration testing -> System testing -> Option B
  4. Quick Check:

    Testing order = Unit -> Integration -> System [OK]
Hint: Remember testing flows from small parts to whole system [OK]
Common Mistakes:
  • Mixing up the order of testing phases
  • Thinking integration testing comes after system testing
  • Assuming unit testing is last
3. Consider two modules: ModuleA returns a number, and ModuleB doubles that number. Which integration test output is correct if ModuleA returns 5?
medium
A. 10
B. 5
C. 25
D. Error

Solution

  1. Step 1: Understand module behavior

    ModuleA returns 5; ModuleB doubles input, so it should return 5 * 2 = 10.
  2. Step 2: Determine integration output

    When ModuleB receives 5 from ModuleA, output is 10, so integration test should expect 10.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    5 doubled = 10 [OK]
Hint: Multiply ModuleA output by 2 for ModuleB result [OK]
Common Mistakes:
  • Confusing input and output values
  • Multiplying instead of doubling
  • Expecting original value without processing
4. You wrote an integration test for two modules, but the test fails with a null pointer error. What is the most likely cause?
medium
A. Modules are not properly connected or data is missing between them
B. Unit tests for each module passed successfully
C. The system testing phase was skipped
D. The test environment has too much memory

Solution

  1. 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.
  2. Step 2: Connect error to module interaction

    If modules are not properly connected or data is missing, integration test fails with null pointer.
  3. Final Answer:

    Modules are not properly connected or data is missing between them -> Option A
  4. Quick Check:

    Null pointer = missing data between modules [OK]
Hint: Null pointer in integration means missing connection/data [OK]
Common Mistakes:
  • Assuming unit tests guarantee integration success
  • Blaming system testing for integration errors
  • Ignoring environment issues unrelated to null pointers
5. You have three modules: Auth, Profile, and Notifications. Auth sends user info to Profile, which then triggers Notifications. Which integration test scenario best checks the full flow?
hard
A. Test Auth alone for correct login
B. Test Profile updates without Auth
C. Test Auth sending data to Profile and Profile triggering Notifications
D. Test Notifications independently for message format

Solution

  1. Step 1: Identify integration points

    The flow involves Auth sending data to Profile, then Profile triggering Notifications. Testing this chain checks integration.
  2. Step 2: Choose scenario covering full module interaction

    Only Test Auth sending data to Profile and Profile triggering Notifications tests the full flow of data and triggers across all three modules together.
  3. Final Answer:

    Test Auth sending data to Profile and Profile triggering Notifications -> Option C
  4. Quick Check:

    Full flow test = Auth -> Profile -> Notifications [OK]
Hint: Test full chain of modules for integration [OK]
Common Mistakes:
  • Testing modules in isolation only
  • Skipping intermediate module triggers
  • Ignoring data flow between modules
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard