Cypress.platform
Cypress.platform
返回底层操作系统名称,等同于Node的
os.platform()
返回值。
尽管Cypress运行在浏览器中,但它会自动使该属性在测试中可用。
语法
Cypress.platform // 'darwin'
示例
条件判断
it('包含JSON文件', () => {
// 如果是Windows执行一种操作,否则执行另一种
const cmd = Cypress.platform === 'win32' ? 'dir *.json' : 'ls *.json'
cy.exec(cmd).its('stdout').should('include', 'package.json')
})