英文:
Can we add path of other fixture files in a fixture.json in Cypress?
问题
{
"stremeadConfig": "./alerts-escalation-param.stremead.json",
"screenIds": [],
"institutionInputId": "bank_code",
"screenLabels": {
"searchLabels": "./alerts-escalation-param.search-labels.json",
"detailsLabels": "./alerts-escalation-param.details-labels.json"
},
"search": "./alerts-escalation-param.select.json",
"searchCriteriaFields": [],
"requiredFieldsOnSearchScreen": [],
"requiredFieldsOnDetailsScreen": [],
"operationsDefaultExpectedValues": {
"numberOfColumnsOnEmptyRow": 1,
"numberOfRecordsAfterDelete": 0
},
"existingDataToDelete": "./alerts-escalation-param.existing.json",
"operations": [
"./alerts-escalation-param.select.json",
"./alerts-escalation-param.create.json",
".alerts-escalation-param.update.json",
"./alerts-escalation-param.duplicate.json",
"./alerts-escalation-param.delete.json"
]
}
英文:
the idea is that I want to use operations and each operation have a name and a fixture file ,
each path have a file that contains data.
and I have a command that get me the fixture file just by calling the operation name, the main question here is if this code is correct in json file for fixture :
{
"stremeadConfig": "./alerts-escalation-param.stremead.json",
"screenIds": [],
"institutionInputId": "bank_code",
"screenLabels": {
"searchLabels": "./alerts-escalation-param.search-labels.json",
"detailsLabels": "./alerts-escalation-param.details-labels.json"
},
"search": "./alerts-escalation-param.select.json",
"searchCriteriaFields": [],
"requiredFieldsOnSearchScreen": [],
"requiredFieldsOnDetailsScreen": [],
"operationsDefaultExpectedValues": {
"numberOfColumnsOnEmptyRow": 1,
"numberOfRecordsAfterDelete": 0
},
"existingDataToDelete": "./alerts-escalation-param.existing.json",
"operations": [
"./alerts-escalation-param.select.json",
"./alerts-escalation-param.create.json",
".alerts-escalation-param.update.json",
"./alerts-escalation-param.duplicate.json",
"./alerts-escalation-param.delete.json"
]
}
答案1
得分: 4
这是一个自定义命令,可以根据指定的操作加载一个测试数据。
Cypress.Commands.add('fixtureForOperation', (operation) => {
return cy.fixture('my-fixtures.json').then(fixtureMain => {
const fixturePath = fixtureMain.operations.find(path => {
return path.contains(operation)
})
if (!fixturePath) {
throw new Error('Operation not found in fixtures')
})
return cy.fixture(fixturePath)
})
})
测试
cy.fixtureForOperation('duplicate').then(data => {
英文:
Here is a custom command that can load a fixture based on the specified operation.
Cypress.Commands.add('fixtureForOperation', (operation) => {
return cy.fixture('my-fixtures.json').then(fixtureMain => {
const fixturePath = fixtureMain.operations.find(path => {
return path.contains(operation)
})
if (!fixturePath) {
throw new Error('Operation not found in fixtures')
})
return cy.fixture(fixturePath)
})
})
test
cy.fixtureForOperation('duplicate').then(data => {
答案2
得分: 3
路径只是字符串,所以它们可以存储在JSON文件中。
为了方便起见,您希望在测试的顶部导入查找文件并删除 ./
前缀。
const fixtures = require('my-fixtures.json')
it('testing existingDataToDelete', () => {
cy.fixture(fixtures.existingDataToDelete).then(data => {
...
英文:
The paths are just strings, so they can be stored in a JSON file.
For convenience, you want to remove ./
in front of fixture names. Import the lookup file at the top of the test.
const fixtures = require('my-fixtures.json')
it('testing existingDataToDelete', () => {
cy.fixture(fixtures.existingDataToDelete).then(data => {
...
答案3
得分: 0
{
"stremeadConfig": "./alerts-escalation-param.stremead.json",
"screenIds": [],
"institutionInputId": "bank_code",
"screenLabels": {
"searchLabels": "./alerts-escalation-param.search-labels.json",
"detailsLabels": "./alerts-escalation-param.details-labels.json"
},
"search": "./alerts-escalation-param.select.json",
"searchCriteriaFields": [],
"requiredFieldsOnSearchScreen": [],
"requiredFieldsOnDetailsScreen": [],
"operationsDefaultExpectedValues": {
"numberOfColumnsOnEmptyRow": 1,
"numberOfRecordsAfterDelete": 0
},
"existingDataToDelete": "./alerts-escalation-param.existing.json",
"operations": [
{
"name": "select",
"fixture": "./alerts-escalation-param.select.json"
},
{
"name": "create",
"fixture": "./alerts-escalation-param.create.json"
},
{
"name": "update",
"fixture": "./alerts-escalation-param.update.json"
},
{
"name": "duplicate",
"fixture": "./alerts-escalation-param.duplicate.json"
},
{
"name": "delete",
"fixture": "./alerts-escalation-param.delete.json"
}
]
}
英文:
try this corrected json file
{
"stremeadConfig": "./alerts-escalation-param.stremead.json",
"screenIds": [],
"institutionInputId": "bank_code",
"screenLabels": {
"searchLabels": "./alerts-escalation-param.search-labels.json",
"detailsLabels": "./alerts-escalation-param.details-labels.json"
},
"search": "./alerts-escalation-param.select.json",
"searchCriteriaFields": [],
"requiredFieldsOnSearchScreen": [],
"requiredFieldsOnDetailsScreen": [],
"operationsDefaultExpectedValues": {
"numberOfColumnsOnEmptyRow": 1,
"numberOfRecordsAfterDelete": 0
},
"existingDataToDelete": "./alerts-escalation-param.existing.json",
"operations": [
{
"name": "select",
"fixture": "./alerts-escalation-param.select.json"
},
{
"name": "create",
"fixture": "./alerts-escalation-param.create.json"
},
{
"name": "update",
"fixture": "./alerts-escalation-param.update.json"
},
{
"name": "duplicate",
"fixture": "./alerts-escalation-param.duplicate.json"
},
{
"name": "delete",
"fixture": "./alerts-escalation-param.delete.json"
}
]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论