// cypress/e2e/mobile/responsive.cy.js
import MobilePage from '../../support/mobile-pages'
describe('移动端响应式测试套件', () => {
const mobilePage = new MobilePage()
context('iPhone 6 竖屏测试', () => {
beforeEach(() => {
mobilePage.visit()
})
it('应正确显示移动端布局', () => {
mobilePage.verifyLayout()
})
it('导航菜单应可交互', () => {
mobilePage.openMenu()
cy.get('.nav-item').first().click()
cy.url().should('include', '/target-page')
})
it('表单元素应适配触摸操作', () => {
cy.get('input[type="text"]')
.type('测试输入', { force: true })
.should('have.value', '测试输入')
cy.get('select')
.select('选项1', { force: true })
.should('have.value', 'option1')
})
})
context('多设备兼容性测试', () => {
const devices = [
{ name: 'iPhone SE', width: 320, height: 568 },
{ name: 'iPhone 12 Pro', width: 390, height: 844 },
{ name: 'Samsung Galaxy', width: 360, height: 740 },
{ name: 'iPad Mini', width: 768, height: 1024 }
]
devices.forEach(device => {
it(`应在${device.name}上正常工作`, () => {
cy.viewport(device.width, device.height)
cy.visit('/')
// 核心功能验证
cy.get('.header').should('be.visible')
cy.get('.content').should(($el) => {
expect($el.width()).to.be.lessThan(device.width)
})
// 交互测试
cy.get('button').first().click({ force: true })
cy.get('.result').should('be.visible')
})
})
})
})