demo-Web-testing-with-Selenium
Project to test Serenity with Selenium and Cucumber
- Demo project to know how to architecture a test project which has some complexity.
- The project is following the Page Object pattern. Where a class express the interface of a page and nothing related to a test can be inside the class. So:
- No webElement should be exposed from a page object.
- No assert can be done inside a page object. So, be careful if you write a mehtod to verify anything in a page class, ie returns a boolean, that your are not coupled to a test.
Responsible
Sergio Sacristan [email protected]
Getting started
You can improve everything in the project with a PR:
- You need to create a git branch, following the naming convention feature/whatever
- Make a pull request!
- Thank you in advance for your contribution!!!!
Requirements
- Git: See the Git best practices.
- Install Docker.
- Install Docker-compose.
- Clone this repository
- Java Development Kit: See the Java best practices.
- Gradle: Use gradle wrapper.
- IDE: see intelliJ/eclipse, depending on your prefered IDE.
- Gherkin: Gherkin - best practices & tips.
Structure
Application mirror
- src/main/java.../domain: DTO objects (for the data interface of every page)
- src/main/java.../pages: Page objects
Application tests
- src/test/resources/features: create a structure in order to have all the features of a page in the same folder.
- src/test/java/,,,/builders: use the patter Builder and Data Builder in order to encapsulate the managemenet of the data needed for the tests.
- src/test/java/,,,/domain: DTO to access the API of the AUT (application under test).
- src/test/java/,,,/services: use the pattern Facade to encapsulate the initialization of the data scenario. This initialization should be done be calling the API services of the AUT or DB (using a DAO), but never initialize the data calling another pages of the AUT.
- src/test/java/,,,/stepsdefs: create a StepDef per Feature, and follow the same package structure as the related feature
- For commonn steps to different stepDef, but within the same folder, create a CommonStepDef
- Use Serenity.getCurrentSession().put/get to share common data between related steps definitions classes
- src/test/java/,,,/tests: here you have the classes to run the tests
Configuration
- This is a gradle project, you can import it from your favorite IDE as Gradle project.
- To verify that all is up to date with dependencies and test compilation, execute the gradle task: testClasses
gradlew.bat testClasses
Compilation
- From IntelliJ: See intelliJ config.
- From Eclipse: See eclipse config.
Execution
- From gradle:
gradle test -Dcucumber.options="--tags @something"
- From junit class: src/test/java/es/s2o/selenium/tests/reservations/ReservationTest.java
- See the reports in target/site/serenity/index.html
CI
$ zalenium/docker-compose up -d
- Selenium Grid Console http://localhost:4444/grid/console
- Zalenium http://localhost:4444/grid/admin/live