0
0
Testing Fundamentalstesting~10 mins

Test environment setup in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the test environment is correctly set up before running any tests. It verifies that the browser opens, the test URL loads, and the main page elements are present.

Test Code - Selenium with unittest
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 TestEnvironmentSetup(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(5)

    def test_environment_ready(self):
        driver = self.driver
        driver.get('https://example.com')
        WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'h1')))
        heading = driver.find_element(By.TAG_NAME, 'h1')
        self.assertTrue(heading.is_displayed())

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and WebDriver Chrome instance is createdBrowser window opens, ready for commands-PASS
2Browser navigates to 'https://example.com'Browser loads the example.com homepage-PASS
3Waits up to 10 seconds for the <h1> element to be present<h1> element appears on the pageChecks presence of <h1> elementPASS
4Finds the <h1> element and checks if it is displayed<h1> element is visible on the pageAssert that heading.is_displayed() is TruePASS
5Test ends and browser closesBrowser window closes-PASS
Failure Scenario
Failing Condition: The <h1> element does not appear within 10 seconds after loading the page
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after opening the browser and loading the page?
AThat the browser window is maximized
BThat the main heading <h1> is present and visible
CThat the page title contains 'Welcome'
DThat the URL contains 'login'
Key Result
Always verify that the test environment is correctly set up by checking key page elements before running further tests. This prevents false failures caused by environment issues.