0
0
Testing Fundamentalstesting~10 mins

Smoke testing and sanity testing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test performs a smoke test to check if the main features of the application load correctly. It then performs a sanity test to verify a specific feature works after a minor change.

Test Code - Selenium with unittest
Testing Fundamentals
import unittest
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

class SmokeSanityTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com')

    def test_smoke_and_sanity(self):
        driver = self.driver
        # Smoke Test: Check homepage title
        self.assertIn('Example Domain', driver.title)

        # Smoke Test: Check main heading is present
        heading = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.TAG_NAME, 'h1'))
        )
        self.assertEqual(heading.text, 'Example Domain')

        # Sanity Test: Click More Information link and verify URL
        more_info_link = driver.find_element(By.CSS_SELECTOR, 'a')
        more_info_link.click()

        WebDriverWait(driver, 10).until(
            EC.url_contains('iana.org/domains/example')
        )
        self.assertIn('iana.org/domains/example', driver.current_url)

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and browser opens ChromeChrome browser window opens at https://example.com homepage-PASS
2Check homepage title contains 'Example Domain'Browser shows homepage with title 'Example Domain'Assert 'Example Domain' in page titlePASS
3Wait for main heading <h1> to be presentPage loaded with visible main headingAssert heading text equals 'Example Domain'PASS
4Find and click the 'More Information' linkUser clicks link on homepage-PASS
5Wait until URL contains 'iana.org/domains/example'Browser navigates to IANA example domains pageAssert current URL contains 'iana.org/domains/example'PASS
6Test ends and browser closesBrowser window closes-PASS
Failure Scenario
Failing Condition: If the main heading <h1> is missing or text is incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
What does the smoke test verify in this test?
AThe 'More Information' link navigates correctly
BThe homepage title and main heading are present
CThe browser can open and close
DThe URL contains 'iana.org/domains/example'
Key Result
Perform smoke tests to quickly check if the main parts of the app load, then use sanity tests to verify specific features after changes.