Click Here To See The Project Codebase
Use of selenium with design patterns as chain of responsibility for customize the workflows.
This project automates a Decathlon shopping scenario with Selenium while demonstrating a clean, pattern-driven architecture. The repository is intentionally small but showcases the following ideas:
Main launches the shopping use case by delegating to ComplexDecathlon.ComplexDecathlon wires a sequence of handler objects that each perform one browser action and then invoke the next handler.DecathlonBot (the concrete bot) extends the abstract Bot, which owns WebDriver lifecycle and primitive user interactions such as clicking, typing, scrolling, and selecting options.src/main/java/testing/project/Main.java — entry point that triggers the Decathlon scenario.src/main/java/testing/project/bot/ — core browser automation abstraction:
Bot encapsulates ChromeDriver setup, waits, and keyboard/mouse helpers.decathlon/DecathlonBot provides Decathlon-specific configuration (URL, timeouts) through ConnectionInformation.src/main/java/testing/project/bot/decathlon/usecases/ — use case composition:
ComplexDecathlon builds and executes the handler chain for the shopping flow.chainofresponsibility/Handler defines the minimal contract for chaining.chainofresponsibility/DecathlonBaseHandler stores the shared bot and delegates to the next link.chainofresponsibility/steps/* contains concrete handlers such as accepting cookies, searching products, applying filters, picking an item, and validating the cart.src/main/java/testing/project/bot/decathlon/statictests/utils/ — standalone validation utilities used by unit tests (email, password, physical attributes, comments, cart quantity, registration rules).src/test/java/util/ — JUnit tests that exercise the static validators.The chain-of-responsibility pattern is used to represent the ordered browser actions required for the Decathlon journey. Each handler performs exactly one concern and then calls super.executeNext() to advance the chain. This keeps responsibilities isolated and makes it trivial to reorder, insert, or remove steps without changing other classes.
Implementation highlights
Handler defines setNext and executeNext, creating a minimal protocol for chaining without leaking implementation details.DecathlonBaseHandler holds the shared DecathlonBot instance and provides a default executeNext that only forwards to the next handler if one is present.steps/ overrides executeNext to run its browser action before delegating. For example, DecathlonAcceptCookies clicks the consent button and pauses, then invokes super.executeNext() to continue the flow.ComplexDecathlon instantiates the handlers, links them with setNext, and kicks off the sequence by calling executeNext on the first step.Bot encapsulates WebDriver lifecycle management plus reusable user interactions. Concrete bots only supply configuration (URL, timeout) and can focus on domain-specific actions instead of Selenium boilerplate.
Implementation highlights
initialize sets up the driver, waits, and Actions provider, while connect and quit open and close the browser respectively.DecathlonBot passes Decathlon-specific constants to the base constructor, keeping configuration decoupled from behavior.The statictests/utils package showcases straightforward validation logic without WebDriver dependencies. They illustrate pure functions that are easy to test and reuse.
Examples
EmailValidator.isValidEmail enforces single @, valid domain segments, allowed extensions, and whitespace checks.RegistrationValidator.canRegister composes email and password validation to model a simple gatekeeper for account creation.Bot centralizes driver mechanics.Handler and linking it into the chain without modifying existing handlers.Bot’s methods; consumers interact through intention-revealing operations (e.g., clickByXpath, scrollToBottom).chainofresponsibility/steps/ extending DecathlonBaseHandler, implement its executeNext, and connect it inside ComplexDecathlon with setNext calls.Bot to provide alternative URLs or timeouts (e.g., staging vs. production) while reusing the same handler chain.statictests/utils validators with additional rules and add matching tests under src/test/java/util/ to keep the suite deterministic.The repository includes JUnit tests for the static validators. Run them with Maven:
mvn test
They execute without needing a browser because they only cover the pure validation utilities.