У меня есть несколько тестов на странице с поисковым вводом.
Все тесты в основном одинаковы, за исключением первого: команда type
- меняется.
Есть ли способ избежать дублирования кода в каждом тесте??
it('Search test1', () => {
searchedString = '0987416572';
cy.get('input[data-test="Search"]').type(searchedString); //same for all test
cy.get('span[data-test="Submit"]').should('be.visible'); //same for all test
cy.get('input[data-test="Search"]').should('have.value', searchedString); //same for all test
cy.get('span[data-test="Submit"]').click(); //same for all test
cy.contains('No results');
});
it('Search test2', () => {
searchedString = 'rewretretre';
cy.get('input[data-test="Search"]').type(searchedString); //same for all test
cy.get('span[data-test="Submit"]').should('be.visible'); //same for all test
cy.get('input[data-test="Search"]').should('have.value', searchedString); //same for all test
cy.get('span[data-test="Submit"]').click(); //same for all test
cy.contains('No results');
});
it('Search test3', () => {
searchedString = '1234';
cy.get('input[data-test="Search"]').type(searchedString); //same for all test
cy.get('span[data-test="Submit"]').should('be.visible'); //same for all test
cy.get('input[data-test="Search"]').should('have.value', searchedString); //same for all test
cy.get('span[data-test="Submit"]').click(); //same for all test
cy.get('div[data-test="Results"]').should('be.visible');
});
Имеет ли смысл добавить функцию для команды duplicates и вызвать эту функцию?Есть ли лучший способ?