How to create a new test - alandiaz08/e2e-web-framework GitHub Wiki

Before writing the test

  • Is it possible to test the feature without the UI? Based on the Testing Pyramid, it is better to test a feature with unit tests or integration tests (API, Cypress) instead of E2E tests because they are slow and expensive. If you are not sure, ask the QA team.
  • Can the new test be part of an existing test? Check the list of tests first!
  • Is the scenario clear? The QA team can help you with the analysis (what to test) and design (how to test) of the new test.
  • Is the feature to be tested not covered by any other test? If that's the case, then the QA team will need to create new Page Objects. Coordinate with the QA team before implementing page objects.

Writing the test

This framework was designed with the goal of making it easy for developers to create new tests by themselves.

Where to create the test

If the test is about one of the features already covered, put the new test method in one of the existing testing classes. The list of tests can be found here.

Tests naming convention

Tests are named based on the feature and scenario being tested. For example:

  • bookingUnknownCustomer
  • mapWithNoRestaurants
  • login
  • michelinRestaurantPage

AAA: Arrange, Act, Assert

"Arrange, Act, Assert" is a testing pattern to describe the natural phases of most software tests. Tests must be organized following the AAA principle:

  • Arrange: describes whatever setup is needed
  • Act: describes the subject's behavior that's under test (and typically only describes a single line needed to invoke that behavior)
  • Assert: describes the verification that the subject's behavior had the desired effect by evaluating its return value or measuring a side-effect (with a spy or mock)

Example:

@Test(retryAnalyzer = RetryAnalyzer.class)
  public void mapWithNoRestaurants() {
    // Arrange
    final String searchArguments = "?coordinates=48.316996%2C2.310415&radius=0.6004318453315488";
    final int expectedNumberOfPins = 0;

    // Act
    SearchPage searchPage = new SearchPage(searchArguments);
    searchPage.get();

    // Assert
    TestReporter.addInfoToReport("Assert that the list of restaurants is empty message is displayed");
    Assert.assertTrue(searchPage.isListOfRestaurantsEmpty(),"The list of restaurants is empty message is not displayed");

    TestReporter.addInfoToReport("Assert that the number of pins in the map is 0");
    Assert.assertEquals(searchPage.getSearchMap().getNumberOfPins(), expectedNumberOfPins, "There are more than 0 pins in the map");
  }

A test can have multiple Act and Assert sections.

After writing the test

  • Make sure that your test passes locally in PREPROD and PROD
  • Use the semantic pull request title, example:
    • test(QAL-XXX): added new booking test
    • test: added more steps to existing test
  • Add the new test or update the scenario in the list of tests
  • Update the Changelog