0
0
Selenium Javatesting~8 mins

Window management (maximize, size) in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Window management (maximize, size)
Folder Structure
selenium-java-project/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/example/app/pages/
│   │           └── HomePage.java
│   └── test/
│       └── java/
│           └── com/example/tests/
│               ├── BaseTest.java
│               ├── WindowManagementTest.java
│               └── utils/
│                   └── DriverFactory.java
├── testng.xml
└── pom.xml
Test Framework Layers
  • Driver Layer: DriverFactory.java manages WebDriver setup and teardown, including browser options.
  • Page Objects: Classes like HomePage.java represent web pages and expose methods to interact with UI elements.
  • Tests: Test classes such as WindowManagementTest.java contain test methods for window maximize and size operations.
  • Utilities: Helper classes for common functions, e.g., waiting, logging, or reading config.
  • Configuration: testng.xml and pom.xml define test suites, dependencies, and environment parameters.
Configuration Patterns
  • Environment Setup: Use testng.xml to define test groups and parameters like browser type.
  • Browser Selection: Pass browser name as a parameter to DriverFactory to create the correct WebDriver instance.
  • Window Settings: Tests explicitly call window management methods (maximize, setSize) to control window state.
  • Credentials & Secrets: Store sensitive data in environment variables or encrypted files, not in code.
Test Reporting and CI/CD Integration
  • Use TestNG built-in reports for test execution results (pass/fail, skipped).
  • Integrate with CI tools like Jenkins or GitHub Actions to run tests on code commits.
  • Generate HTML reports with plugins like maven-surefire-report-plugin or ExtentReports for detailed logs.
  • Configure CI to run tests on multiple browsers and report window management test outcomes.
Framework Design Principles
  1. Use Page Object Model: Keep window management calls in test or base test classes, not in page objects.
  2. Explicit Window Control: Always maximize or set window size explicitly in tests to avoid flaky UI behavior.
  3. Driver Factory Pattern: Centralize WebDriver creation to easily manage browser options and window settings.
  4. Parameterize Browser and Window Size: Allow tests to run on different browsers and window sizes via config.
  5. Clean Up: Ensure driver.quit() is called after tests to close browser windows properly.
Self Check

Where in this folder structure would you add a new utility method to resize the browser window to a custom dimension?

Key Result
Centralize WebDriver setup and explicitly control browser window size and maximize in tests for reliable UI automation.