You are on page 1of 4

Lệnh cmd:

1. Đường dẫn đến thư mục: cd <tên thư mục>


2. Tạo thư mục: mkdir <tên thư mục>
3. Remove thư mục: cd..

=====================================================================

Setup cypress:

1. Tạo một thư mục mới


2. Trỏ tới thư mục đó
3. Chạy lệnh: npm init
4. Chạy lệnh: npm install cypress --save-dev
5. Trỏ đến thư mục .bin (hoặc gõ npx): cypress open

Dùng xpath: npm i cypress-xpath

=====================================================================

Cy.visit(‘đường dẫn’): mở trang web.

Cy.contains(‘nội dung’).click(): tìm phần tử có nội dung rồi click vào nó.

Note: case phần tử click bị che thì thêm {force:true} bên trong dấu ngoặc của click

.scrollIntoView(): để scroll

Cy.url().should(‘include’, ‘/nội dung’): mở đường dẫn con.

Cy.get(‘element’).type(‘nội dung’).should(‘have.value’, ‘nội dung’): tự động nhập nội dung theo


element.

Cy.wait(10*1000): đợi khoảng 10s

.should(‘have.legnth’,1): kiểm tra xem phần tử có xuất hiện không. 1 là xuất hiện 1 lần, 0 là
không xuất hiện.

.invoke(‘text’).should(‘eq’,’nội dung’): kiểm tra xem có hiển thị dòng text đó không.

Note: eq là giống hoàn toàn. include là chỉ bao gồm.

Beforeach: để visit trang mà không cần phải viết nhiều lần.

Nếu timeout vô Cypress.config.js -> pageLoadTimeout(10*1000)

================
VSCode

Shift+alt+phím xuống: sẽ copy dòng lệnh xuống dòng mới


//const urls = ['https://hienoti.tabulalearning.net/']

describe('Login', () => {

beforeEach(function () {

cy.visit('https://hienoti.tabulalearning.net/')

});

it('passes', () => {

cy.get('.logo > .MuiBox-root > .MuiTypography-


root').invoke('text').should('eq','Hie Notification 01')

//cy.get(':nth-child(1) > .MuiFormControl-root > .css-1f8s1t


> .MuiBox-root > .MuiFormLabel-root').invoke('label').should('eq','Email
address')

// cy.get(':nth-child(2) > .MuiFormControl-root > .css-1f8s1t


> .MuiBox-root > .MuiFormLabel-
root').invoke('label').should('eq','Password')

//cy.xpath(input[placeholder="Your email
address"]).type('text').should('have.value','hie.noti@yopmail.com')

cy.get(':nth-child(1) > .MuiFormControl-root > .MuiInputBase-root


> .MuiInputBase-input').type('hie.noti@yopmail.com')

cy.get(':nth-child(2) > .MuiFormControl-root > .MuiInputBase-root


> .MuiInputBase-input').type('12345678')

cy.get('.btn-group > .MuiButtonBase-root').click()

cy.get('.css-70qvj9 > .MuiTypography-


root').invoke('text').should('eq','Hie Notification 01')

// Cy.wait(3000)

})

it('fail', () => {
it.only('empty',()=>{

cy.get('.btn-group > .MuiButtonBase-root').click()

cy.get(':nth-child(1) > .MuiFormControl-root > .MuiFormHelperText-


root').invoke('text').should('eq','This information is required.')

cy.get(':nth-child(2) > .MuiFormControl-root > .MuiFormHelperText-


root').invoke('text').should('eq','This information is required.')

cy.get(':nth-child(1) > .MuiFormControl-root > .MuiInputBase-root


> .MuiInputBase-input').type('hie.noti@yopmail.com').clear()

cy.get(':nth-child(1) > .MuiFormControl-root > .MuiFormHelperText-


root').invoke('text').should('eq','This information is required.')

cy.get(':nth-child(2) > .MuiFormControl-root > .MuiInputBase-root


> .MuiInputBase-input').type('12345678').clear()

cy.get(':nth-child(2) > .MuiFormControl-root > .MuiFormHelperText-


root').invoke('text').should('eq','This information is required.')

})

})

})

Cách dùng commands.js

Khai báo đường dẫn xpath

Cypress.Commands.add(‘clicks’, (…button) => {

button.forEach(elament => {

cy.xpath(elament).click()

});

})

Cách dùng: cy.clicks(button 1, button 2,…)

========
Cypress.Commands.add(‘type’, (locators = [], value =[]) => {

for

Cách sử dụng: cy.types([xpath1,xpath2],[username,password])

———-

.json

You might also like