0
0
Selenium Javatesting~8 mins

findElement by partialLinkText in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - findElement by partialLinkText
Folder Structure
src/
└── test/
    └── java/
        └── com/
            └── example/
                ├── pages/
                │   └── HomePage.java
                ├── tests/
                │   └── HomePageTest.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 locators and methods. Use By.partialLinkText to locate links partially matching text.
  • Tests: Test classes using TestNG or JUnit to run test cases calling page object methods.
  • Utilities: Helper classes for common functions like waits, logging, or reading configs.
  • Configuration: Handles environment variables, browser types, and credentials.
Configuration Patterns

Use property files or YAML to store environment URLs, browser types, and credentials.

Example: config.properties

baseUrl=https://example.com
browser=chrome
username=testuser
password=secret
    

Load these in ConfigReader class to provide values to tests and driver setup.

Test Reporting and CI/CD Integration
  • Use TestNG reports or Allure for detailed test execution reports.
  • Integrate with CI/CD tools like Jenkins or GitHub Actions to run tests on code commits.
  • Reports show pass/fail status and screenshots on failure.
Best Practices
  • Use By.partialLinkText only when link text is unique enough to avoid false matches.
  • Keep locators in page objects to separate test logic from UI details.
  • Use explicit waits before locating elements to handle dynamic page loading.
  • Use descriptive method names in page objects for readability (e.g., clickPartialLink(String partialText)).
  • Keep configuration externalized to easily switch environments or browsers.
Self Check

Where in this folder structure would you add a new page object class for a page that contains a link you want to locate using partialLinkText?

Key Result
Organize Selenium Java tests with clear layers: driver setup, page objects using partialLinkText locators, tests, utilities, and config for maintainability.