How to Implement Cucumber Tests?

How to Implement Cucumber Tests?

Creating Tests with Fisher

Overview of Test Creation

  • The discussion begins with the focus on creating tests associated with Fisher, emphasizing the need for a specification that includes various scenarios. In this case, only one scenario is presented.

Scenario Description

  • The specific scenario involves attempting to register a new student using an existing CPF (683), which should result in a successful registration despite the duplicate entry.

Steps for Automation

  • For each step in the testing scenario, code must be written to automate these actions. The speaker mentions starting with defining the body of code that will execute when each step is invoked.

Code Execution and Matching

  • Each test step requires matching text from the feature file. The notation used indicates where certain strings must appear within the text being tested, ensuring precise execution of commands.

Browser Interaction and Asynchronous Operations

  • Communication with the browser is asynchronous; thus, commands may not return immediately. This necessitates waiting for responses before executing subsequent commands to ensure proper flow in test execution.

Verifying Student Registration

Initial Verification Step

  • Before registering a new student, it’s crucial to verify that no student exists with CPF 683. This ensures that the test accurately reflects behavior when trying to register a non-existent student.

Parameter Handling in Tests

  • The test step includes parameters such as CPF numbers. These are matched against existing entries to confirm their absence before proceeding with further actions.

HTML Element Filtering

Filtering Elements by CPF

Filtering Process Overview

  • The process involves filtering a list to return only elements that match a specified CPF parameter, effectively reducing a large list to relevant entries.
  • The filter checks if the HTML text of each element in the list matches the provided CPF (683), resulting in either an empty list or a list containing matching elements.

Accessing and Validating Filtered Results

  • The method getText is used to access the text of each element, ensuring that it retrieves the correct data for comparison.
  • After filtering, the size of the resulting list is checked; if it's zero, it indicates no students with CPF 683 exist in the original list.

Conditional Logic Based on List Size

  • If no matching student is found (list size equals zero), further actions are determined based on this condition.
  • A test failure occurs if there was an expectation for at least one entry with CPF 683 when none exists.

Executing Actions Based on Conditions

Setting Up System State

  • Initial steps set up system conditions where no student with CPF 683 is registered before attempting to add a new student.

Adding New Student Details

  • When registering a new student named "Mário" with CPF 683, two parameters are passed into the registration function.
  • The input field for name (nameBox) is accessed from the rendered HTML document to enter "Mário".

Interacting with HTML Elements

  • The method simulates typing into input fields, filling out both name and CPF boxes accordingly.
  • Finally, an "Add" button is clicked programmatically by searching for its text within the HTML structure.

Verifying Successful Registration

Checking Updated Student List

  • After attempting to add Mário, another check verifies whether he appears in the updated student list.

Filtering for Confirmation

  • All elements labeled as alunoList are retrieved again to confirm Mário's presence alongside his corresponding CPF (683).

Final Validation Steps

Verifying Student Registration Conditions

Checking the Resulting List Size

  • The initial condition for student registration is that the resulting list can either be of size zero, indicating no students meet the criteria, or size one, confirming a successful registration.
  • If the resulting list has a size of one, it confirms that "aluna Mari" with CPF 683 is present in the list. A size different from one indicates an issue with registration.

Error Handling in Registration

  • A resulting list size greater than one suggests that "aluna Mari" appears multiple times (which is an error), while a size of zero means she was not registered at all.
Playlists: Testing