0
0
Selenium Pythontesting~10 mins

Browser profile configuration in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a Firefox browser with a custom profile that disables images to speed up loading. It verifies the browser starts with the profile applied by checking the page title.

Test Code - unittest
Selenium Python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
import unittest

class TestFirefoxProfile(unittest.TestCase):
    def setUp(self):
        profile = webdriver.FirefoxProfile()
        # Disable images to speed up loading
        profile.set_preference('permissions.default.image', 2)
        profile.update_preferences()

        options = Options()
        self.driver = webdriver.Firefox(firefox_profile=profile, options=options)

    def test_page_title(self):
        self.driver.get('https://example.com')
        title = self.driver.title
        self.assertEqual(title, 'Example Domain')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Create FirefoxProfile and set preference to disable imagesFirefoxProfile object configured with images disabled-PASS
2Launch Firefox browser with the custom profileFirefox browser opens with images disabled-PASS
3Navigate to https://example.comBrowser loads example.com page without images-PASS
4Get page title and assert it equals 'Example Domain'Page title is 'Example Domain'assertEqual(title, 'Example Domain')PASS
5Close the browserBrowser closed-PASS
Failure Scenario
Failing Condition: Page title does not match 'Example Domain' due to navigation failure or profile misconfiguration
Execution Trace Quiz - 3 Questions
Test your understanding
What does the FirefoxProfile configuration in this test do?
AChanges the browser language to French
BEnables JavaScript debugging
CDisables loading of images in the browser
DSets the browser window size
Key Result
Using a browser profile allows customizing browser behavior before tests run, such as disabling images to speed up tests or setting preferences for consistent test environments.