此系列文章会同步发文到个人部落格,有兴趣的读者可以前往观看喔。
writeFile()
语法
cy.writeFile(filePath, contents)
cy.writeFile(filePath, contents, encoding)
cy.writeFile(filePath, contents, options)
cy.writeFile(filePath, contents, encoding, options)
可以写成 txt 档或是 json 档,档案会放在 cypress/fixtures 底下
cy.writeFile('path/to/message.txt', 'Hello Cypress')
cy.writeFile('path/to/data.json', { name: 'Jennifer', email: '[email protected]' })
在档案的最後附加文字可以用 { flag: 'a+' }
cy.writeFile('path/to/message.txt', 'Hello World', { flag: 'a+' })
readFile()
语法
cy.readFile(filePath)
cy.readFile(filePath, encoding)
cy.readFile(filePath, options)
cy.readFile(filePath, encoding, options)
动手写程序
describe('测试写档案', function() {
it('应该可以在test1档案写东西', function() {
cy.writeFile('cypress/fixtures/test1.txt', 'Hello Cypress!\n')
})
it('应该可以在test1档案上附加文字', function() {
cy.writeFile('cypress/fixtures/test1.txt', 'Hello Cypress!!', {flag: 'a+',})
})
it('应该可以在test2档案写东西', function() {
cy.writeFile('cypress/fixtures/test2.json', { name: 'Jennifer', email: '[email protected]' })
})
})
describe('测试读档案', function() {
it('应该可以在test1档案读档案', function() {
cy.readFile('cypress/fixtures/test1.txt').should('eq','Hello Cypress!\nHello Cypress!!')
})
it('应该可以在test2档案读档案', function() {
cy.readFile('cypress/fixtures/test2.json').its('name').should('eq', 'Jennifer')
})
})
看结果
>>: 【设计+切版30天实作】|Day19 - 切版 - Heroheader - 怎麽切出满版heroheader?
本系列文章同步发布於笔者网站 在经过了好几篇的 Neutron 之後我们终於来到下一个 OpenSt...
继续昨天~ 拉取三个Label,这是往後会从资料库回传资料到我们在主画面拉的tableview里显示...
人工智慧共创平台-离职率预测(上) 资料来源 因为工作偶尔也会有闲暇时间,尤其我们是业务单位提出需求...
前言 前面已经知道如何抓「台湾证券交易所」的除权除息计算结果表 CSV 档,接下来要处理资料,并存入...
从源头降低风险(X),可归究责任(O) 适用人员: 技术人员(开发人员)。 适用法规: 资通安全责任...