https://medium.com/@naruapon/การทดสอบด้วย-cypress-e3e049da048c
ติดตั้ง Cypress
npm install cypress --save-dev
เปิด Cypress
npx cypress open
สร้างกรณีทดสอบ
cypress/e2e/ts1-spec.cy.js
describe('Yahoo Search Test Suite', () => {
beforeEach(() => {
cy.visit('https://www.yahoo.com')
cy.title().should('include', 'Yahoo')
})
it('should search by keyword "Cypress"', () => {
cy.get('input[name="p"]').type('Cypress')
cy.get('button[type="submit"]').click()
cy.contains('Cypress').should('exist')
})
it('should search by keyword "Yahoo"', () => {
cy.get('input[name="p"]').type('Yahoo')
cy.get('button[type="submit"]').click()
cy.contains('Yahoo').should('exist')
})
it('should search by keyword "Google"', () => {
cy.get('input[name="p"]').type('Google')
cy.get('button[type="submit"]').click()
cy.contains('Google').should('exist')
})
})
การรันการทดสอบ
npx cypress run
google search — ts2-search-google.spec.cy.js
describe('Google Search and Verify Results', () => {
const URL = 'https://www.google.com';
const SEARCH_TERM = 'robot framework';
const SEARCH_RESULT = 'Robot Framework';
it('Search Google and Verify Results TC2001', () => {
cy.visit(URL);
cy.get('a').contains('English').click();
// Input Search Term and Enter
cy.get('#APjFqb').type(SEARCH_TERM);
cy.get('#APjFqb').type('{enter}');
// Verify Search Results
cy.contains(SEARCH_RESULT).should('exist');
// Capture Page Screenshot
cy.screenshot('TC2001_Screenshot');
});
});