【发布时间】:2021-09-01 17:32:30
【问题描述】:
我使用代码找到按钮:
cy.get('[class="ng-select ng-select-multiple ng-select-searchable ng-untouched ng-valid ng-select-focused ng-select-opened ng-select-top ng-dirty"]')
.children('[class="ng-select-container ng-has-value"]')
.children('[title="Clear all"]')
然后我执行几个操作 - 例如单击、检查是否可见等。如果我将这段代码直接放在测试文件中,所有这些都可以工作。
getClearObjectsButton() {
cy.get('[class="ng-select ng-select-multiple ng-select-searchable ng-untouched ng-valid ng-select-focused ng-select-opened ng-select-top ng-dirty"]')
.children('[class="ng-select-container ng-has-value"]')
.children('[title="Clear all"]')
}
但是,如果我使用带有已创建函数的辅助文件,则会收到标题中的错误。
register.getClearObjectsButton().click()
cypress_runner.js:174495 TypeError: Cannot read property 'click' of undefined
at Context.<anonymous> (tests?p=cypress\integration\create_user\check_objects_selector.js-106:580)
知道如何解决这个问题吗?
【问题讨论】:
标签: javascript cypress