Cypress版本10.3.0
我有以下测试。cy.js,它是异步IT块。文章源自玩技e族-https://www.playezu.com/180082.html
///文章源自玩技e族-https://www.playezu.com/180082.html
import loadFileObjects from '../../../support/load_file_objects'
var fixtureUrl = '/test/mydata/'
describe("TC1_getResidentialInfo", () => {
var load_test_case;
it('Validate and load all automation feeds', async () => {
load_test_case = await loadFileObjects.getJsonObj(fixtureUrl + '/CUP-575-TC1-TC.json');
})
})
支持/加载文件对象。js公司文章源自玩技e族-https://www.playezu.com/180082.html
class load_file_objects{
//it should accept fixture folder structure and test case name
//returns json object directly using promise
getJsonObj(testCasePath){
// return new Cypress.Promise((resolve, reject) => {
return new Cypress.Promise((resolve, reject) => {
cy.fixture(testCasePath).then((data) => {
cy.log("Test Data for "+testCasePath+ ": " +JSON.stringify(data))
resolve(data)
})
// do something custom here
})
// var data = data;
// return data
// })
}
}
export default load_file_objects
当我使用cypress open(test runner UI)运行相同的测试时,它工作正常
请告诉我我错过了什么。文章源自玩技e族-https://www.playezu.com/180082.html 文章源自玩技e族-https://www.playezu.com/180082.html
未知地区 1F
类实例需要在某处创建。
惯例是类名大写。这是一种干净的方式
class LoadFileObjects {
…
exp或t default LoadFileObjects
或
imp或t LoadFileObjects from ‘../../../supp或t/load_file_objects’
it(‘Validate and load all automation feeds’, async () => {
const loadFileObjects = new LoadFileObjects()
const load_test_case = await loadFileObjects.getJsonObj(fixtureUrl + ‘/CUP-575-TC1-TC.json’);
})
需要固定装置
如果夹具文件的路径是固定且一致的,则可以使用 需要() 在脚本的顶部,为您执行异步/等待重载。
const load_test_case = require(‘./cypress/fixtures/test/mydata/CUP-575-TC1-TC.json’)