0
0
Selenium Javatesting~8 mins

Checking state (isDisplayed, isEnabled, isSelected) in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Checking state (isDisplayed, isEnabled, isSelected)
Folder Structure
src/
└── test/
    └── java/
        └── com/
            └── example/
                ├── pages/
                │   └── LoginPage.java
                ├── tests/
                │   └── LoginTests.java
                ├── utils/
                │   └── WebDriverFactory.java
                └── config/
                    └── ConfigReader.java
Test Framework Layers
  • Driver Layer: Manages WebDriver setup and teardown (e.g., WebDriverFactory).
  • Page Objects: Classes representing web pages with methods to interact and check element states (e.g., isDisplayed(), isEnabled(), isSelected()).
  • Tests: Test classes that use page objects to perform actions and assertions on element states.
  • Utilities: Helper classes for common functions like waits, logging, or reading configs.
  • Configuration: Handles environment settings, browser types, and credentials.
Configuration Patterns
  • Use config.properties file to store environment URLs, browser types, and credentials.
  • ConfigReader class reads properties and provides access to tests.
  • Pass browser type as a system property or environment variable to run tests on different browsers.
  • Use profiles or separate config files for different environments (dev, test, prod).
Test Reporting and CI/CD Integration
  • Use TestNG built-in reports or integrate with Allure for detailed test reports showing pass/fail and screenshots.
  • Configure CI/CD pipelines (e.g., Jenkins, GitHub Actions) to run tests on code commits and pull requests.
  • Generate reports automatically and archive them for review.
  • Fail builds if critical tests checking element states fail.
Best Practices
  • Use Page Object Model: Encapsulate element state checks inside page object methods like isLoginButtonDisplayed().
  • Explicit Waits: Use explicit waits before checking states to avoid flaky tests.
  • Clear Assertions: Assert element states with meaningful messages for easier debugging.
  • Reusable Utilities: Create helper methods for common state checks if used across pages.
  • Consistent Naming: Name methods clearly to indicate what state is being checked.
Self Check

Where in this folder structure would you add a new method isRememberMeCheckboxSelected() to check if the "Remember Me" checkbox is selected?

Key Result
Use Page Object Model with explicit waits to check element states like isDisplayed, isEnabled, and isSelected for reliable UI tests.