从命令行Get =&gt运行柏树测试; CypressError:在运行此命令时停止了柏树测试

发布于 2025-02-13 06:02:38 字数 1238 浏览 0 评论 0原文

柏树版本10.3.0

我有以下test.cy.js,即Async IT阻止。

///

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');
        })
})

支持/load_file_objects.js

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

使用柏树开放(测试跑者UI)进行相同的测试时,其工作正常 请让我在这里想念的东西。

Cypress version 10.3.0

I have a following test.cy.js, which is async IT block.

///

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');
        })
})

support/load_file_objects.js

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

Its working fine when I run the same test using cypress open(Test runner UI)
Please let me what I am missing here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩扇题诗 2025-02-20 06:02:38

需要在某个地方创建类实例。

惯例是班级名称已大写。这是执行此操作的干净方法

class LoadFileObjects {
  ...
export default LoadFileObjects

,或者

import LoadFileObjects from '../../../support/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');
})

需要固定装置

如果固定固定文件的路径是固定且一致的,那么您可以在该固定文件的顶部使用requiend()脚本为您提供异步/等待您的繁重举重。

const load_test_case = require('./cypress/fixtures/test/mydata/CUP-575-TC1-TC.json')

The class instance needs to be created somewhere.

Convention is class names are capitalized. This is the clean way to do it

class LoadFileObjects {
  ...
export default LoadFileObjects

or

import LoadFileObjects from '../../../support/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');
})

Requiring the fixture

If the path to your fixture file is fixed and consistent, then you can use require() at the top of the script to do the async/await heavy lifting for you.

const load_test_case = require('./cypress/fixtures/test/mydata/CUP-575-TC1-TC.json')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文