javascript 如何重构此Cypress固定装置代码?[已关闭]

hfyxw5xn  于 2023-01-29  发布在  Java
关注(0)|答案(1)|浏览(96)

昨天关门了。
Improve this question
我需要你帮我重新整理这个cypress代码

let stripe;
  let bookService;
  let images;
  let moreDetails;
  let checkoutDetails;
  let wait;
  before(() => {
    cy.visit('/');
    cy.fixture('stripe').then((data) => {
      stripe = data;
    });
    cy.fixture('bookService').then((data) => {
      bookService = data;
    });
    cy.fixture('images').then((data) => {
      images = data;
    });
    cy.fixture('moreDetails').then((data) => {
      moreDetails = data;
    });
    cy.fixture('wait').then((data) => {
      wait = data;
    });
  });

我试过了

stripe = cy.fixture('stripe')

但它返回了一个对象{specWindow:...,链ID:...}

ibrsph3r

ibrsph3r1#

可以在规范的末尾导入fixture,您可以使用require()以您建议的方式重构fixture,

let stripe = require('./cypress/fixtures/stripe.json')
let bookService = require('./cypress/fixtures/bookService.json')
let images = require('./cypress/fixtures/images.json')
let moreDetails = require('./cypress/fixtures/moreDetails.json')
let wait = require('./cypress/fixtures/wait.json')

before(() => {
    cy.visit('/');
});

相关问题