0
0
Selenium Javatesting~8 mins

Typing text (sendKeys) in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Typing text (sendKeys)
Folder Structure
  selenium-java-project/
  ├── src/
  │   ├── main/
  │   │   └── java/
  │   │       └── pages/
  │   │           └── LoginPage.java
  │   └── test/
  │       └── java/
  │           ├── tests/
  │           │   └── LoginTest.java
  │           └── utils/
  │               └── WebDriverFactory.java
  ├── testng.xml
  ├── pom.xml
  └── README.md
  
Test Framework Layers
  • Driver Layer: Manages WebDriver setup and teardown (e.g., WebDriverFactory.java).
  • Page Objects: Classes representing web pages with methods to interact, including typing text using sendKeys().
  • Tests: Test classes that call page object methods to perform actions and assertions.
  • Utilities: Helper classes for waits, logging, and common functions.
  • Configuration: Files like testng.xml and pom.xml to manage test execution and dependencies.
Configuration Patterns
  • Environment Setup: Use testng.xml to define test suites and parameters like browser type.
  • Browser Selection: Pass browser name as a parameter to WebDriverFactory to create the correct driver.
  • Credentials: Store sensitive data in environment variables or encrypted files, not hardcoded.
  • Timeouts and Waits: Configure implicit and explicit waits centrally in WebDriverFactory or utilities.
Test Reporting and CI/CD Integration
  • Use TestNG built-in reports for pass/fail results and test details.
  • Integrate with CI/CD tools like Jenkins or GitHub Actions to run tests automatically on code changes.
  • Generate HTML or XML reports for easy review by the team.
  • Use screenshots on failure to help debug typing or interaction issues.
Best Practices for Typing Text (sendKeys)
  • Use Page Object Model to keep typing actions inside page classes, not tests.
  • Use explicit waits to ensure the input field is visible and enabled before typing.
  • Clear input fields before typing to avoid leftover text.
  • Use meaningful method names like enterUsername(String username) for clarity.
  • Avoid hardcoding text in tests; use test data or parameters for flexibility.
Self Check

Where would you add a new method enterPassword(String password) that types text into the password field?

Key Result
Use Page Object Model with explicit waits and clear input before sendKeys for reliable typing actions.