我们可以在 Cypress 的 fixture.json 文件中添加其他 fixture 文件的路径吗?

huangapple go评论108阅读模式
英文:

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"
}
 ]
}

huangapple
  • 本文由 发表于 2023年6月8日 18:56:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定