I am trying to use datatables to test one input field in my Cypress scenario below
Scenario: The one where the user enters a value to calculate the factorial
Given the user navigates to the Factoriall calculator screen
When the user enters a value into the input box
| value |
| 12 |
| 34.56 |
And the user clicks the Calculate button
Then a message is displayed to the user
| message |
| The factorial of 12 is: 479001600 |
| Please enter an integer |
Here is the current testing behaviour:
- 12 is entered into the input box.
- 34.56 is entered into the input box.
- The Calculate button is clicked.
- The message is validated ("Please enter an integer" is displayed) as the input reads
1234.56.
This is how I want the test to behave:
- 12 is entered into the input box.
- The Calculate button is clicked.
- The factorial value is displayed.
- The input box is cleared.
- 34.56 is entered into the input box.
- The Calculate button is clicked.
- The error message is displayed.
I understand there's an issue with my current logic in that it's entering all the text at the beginning before clicking the button, but can someone please tell me what updates are required so I can get this test working as expected?
Here are my Step Definitions:
When('the user enters a value into the input box', (userInputs) => {
userInputs.hashes().forEach((userInput) => {
myValue = userInput.value
factoriall.getInputBox().type(myValue)
});
});
When('the user clicks the Calculate button', () => {
factoriall.getBtnCalculate().click();
});
Then('a message is displayed to the user', (expectedMessages) => {
expectedMessages.hashes().forEach((expectedMessage) => {
factoriall.getInputBox().clear();
myMessage = expectedMessage.message
factoriall.getResultParagraph().should('have.text', myMessage)
});
});