0
0
Selenium Javatesting~8 mins

JSON test data in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - JSON test data
Folder Structure
selenium-java-project/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/example/app/          # Application source code
│   └── test/
│       ├── java/
│       │   └── com/example/tests/       # Test classes
│       └── resources/
│           └── testdata/                 # JSON test data files
│               └── loginData.json
├── pom.xml                              # Maven project file
└── README.md
Test Framework Layers
  • Test Classes: Java classes under src/test/java/com/example/tests/ that contain test methods using Selenium WebDriver.
  • Page Objects: Java classes representing web pages under src/main/java/com/example/app/pages/ implementing the Page Object Model.
  • Test Data: JSON files stored in src/test/resources/testdata/ holding input data for tests.
  • Utilities: Helper classes for reading JSON files and parsing data, e.g., JsonUtils.java.
  • Configuration: Properties files or environment variables to manage URLs, browsers, credentials.
Configuration Patterns
  • Environment Config: Use config.properties or system properties to set base URLs and environment (dev, test, prod).
  • Browser Selection: Pass browser type as a Maven parameter or environment variable to run tests on different browsers.
  • Credentials: Store sensitive data encrypted or use environment variables; do not hardcode in JSON or code.
  • JSON Test Data: Load JSON files from src/test/resources/testdata/ using utility methods before test execution.
Test Reporting and CI/CD Integration
  • Use TestNG or JUnit reports for test execution results.
  • Integrate with Maven Surefire plugin to generate XML and HTML reports.
  • Use Jenkins or GitHub Actions to run tests automatically on code commits.
  • Publish reports and logs for easy review of test outcomes.
Best Practices
  • Separate Test Data: Keep JSON test data outside code to allow easy updates without recompiling.
  • Use Page Object Model: Encapsulate page elements and actions to keep tests clean and maintainable.
  • Utility Methods: Create reusable methods to read and parse JSON data safely and efficiently.
  • Parameterize Tests: Use data-driven testing with JSON to run tests with multiple data sets.
  • Secure Sensitive Data: Avoid storing passwords or secrets in plain JSON files.
Self Check

Where in this folder structure would you add a new JSON file to store test data for the "Registration" feature?

Key Result
Store JSON test data in src/test/resources/testdata and load it via utility classes for data-driven Selenium tests.