Estoy tratando de usar tablas de datos para probar un campo de entrada en mi escenario de Cypress a continuación
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 |Aquí está el comportamiento de prueba actual:
1234.56 .Así es como quiero que se comporte la prueba:
Entiendo que hay un problema con mi lógica actual, ya que está ingresando todo el texto al principio antes de hacer clic en el botón, pero ¿alguien puede decirme qué actualizaciones se requieren para que esta prueba funcione como se espera?
Aquí están mis definiciones de pasos:
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) }); });Sería mejor utilizar un Scenario Outline .
Con esto, su escenario completo se ejecutará 2 veces (o el número de filas que agregue en su tabla en Examples ) y cada vez, las palabras entre paréntesis angulares <value> y <message> serán reemplazadas por su valor correspondiente del Examples: mesa.
Scenario Outline: The one where the user enters value <value> to calculate the factorial Given the user navigates to the Factoriall calculator screen When the user enters value <value> into the input box And the user clicks the Calculate button Then this message is displayed to the user: <message> Examples: | value | message | | 12 | The factorial of 12 is: 479001600 | | 34.56 | Please enter an integer | Para usar los valores <value> y <message> , debe llamar a su paso así:
When(/^the user enters value (.+) into the input box$/, (value) => { ... }); Then(/^this message is displayed to the user: (.+)$/, (message) => { ... });En mi ejemplo anterior, uso expresiones regulares para capturar mis variables. Hay otras formas, pero prefiero esta.