javascript - 如何在 Cypress 内部正确实现 Drop 或 Trigger?
问题描述
我目前正在使用“将文件拖放到此处”组件与 Salesforce 合作,似乎如果我使用“拖放”NPM 依赖项,它将不会出现任何错误,但屏幕永远不会弹出。
注意:删除文件后,我们应该会看到一个弹出窗口,其中包含用于存储该文件的所有文件选项。
如果我使用“触发操作”执行此操作,我将收到以下错误消息:
我的代码如下:
describe("Checklist - Drag and Drop Functionality", function () {
beforeEach(() => {
cy.login();
});
it("Drag and Drop Files", () => {
cy.viewOpportunityRecord();
cy.wait(10000);
// Click to view More Tabs inside of the opportunity
cy.get('button[title="More Tabs"]', { delay: 1000, force: true }).click({multiple: true, force: true});
cy.get("span.slds-truncate")
.contains("Checklist (beta)")
.dblclick({ multiple: true });
cy.wait(10000)
const filePath = 'html-cheat-sheet.csv'
cy.xpath('//*[@id="tab-18"]/slot/flexipage-component2/slot/flexipage-aura-wrapper/div/section[1]/h2/div[2]/button[3]').click({force: true})
cy.wait(10000)
cy.xpath('/html/body/div[4]/div[1]/section/div[1]/div[2]/div[2]/div[1]/div/div/div/div/div/one-record-home-flexipage2/forcegenerated-adg-rollup_component___force-generated__flexipage_-record-page___-opportunity_-record_-page___-opportunity___-v-i-e-w/forcegenerated-flexipage_opportunity_record_page_opportunity__view_js/record_flexipage-record-page-decorator/div[1]/records-record-layout-event-broker/slot/slot/flexipage-record-home-with-subheader-template-desktop2/div/div[3]/div[1]/slot/slot/flexipage-component2[1]/slot/flexipage-tabset2/div/lightning-tabset/div/slot/slot/slot/flexipage-tab2[16]/slot/flexipage-component2/slot/flexipage-aura-wrapper/div/div[1]/div[1]/ul/li[1]/section/div[2]/div[2]/div[4]').trigger('drop', {filePath})
})
})
另外,要运行拖动文件,我认为我可以这样做:
const fileLocated = cy.xpath('/html/body/div[4]/div[1]/section/div[1]/div[2]/div[2]/div[1]/div/div/div/div/div/one-record-home-flexipage2/forcegenerated-adg-rollup_component___force-generated__flexipage_-record-page___-opportunity_-record_-page___-opportunity___-v-i-e-w/forcegenerated-flexipage_opportunity_record_page_opportunity__view_js/record_flexipage-record-page-decorator/div[1]/records-record-layout-event-broker/slot/slot/flexipage-record-home-with-subheader-template-desktop2/div/div[3]/div[1]/slot/slot/flexipage-component2[1]/slot/flexipage-tabset2/div/lightning-tabset/div/slot/slot/slot/flexipage-tab2[16]/slot/flexipage-component2/slot/flexipage-aura-wrapper/div/div[1]/div[1]/ul/li[1]/section/div[2]/div[2]/div[4]')
cy.xpath('//*[@id="tab-18"]/slot/flexipage-component2/slot/flexipage-aura-wrapper/div/section[1]/h2/div[2]/button[3]').click({force: true})
cy.wait(10000)
cy.xpath('//*[@id="fileTable"]').xpath('//*[@id="fileTable"]/tbody/tr[1]/td[1]/div/button').contains('12 Month Payment History').drag(fileLocated, { force: true})
主要问题是我遇到了以下问题:
CypressError
Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
The command that returned the promise was:
> cy.wrap()
有谁知道如何解决这个问题?
解决方案
我不知道这是否解决了它,但你不能这样做
const fileLocated = cy.xpath(<horrendously-long-xpath-selector>)
...
cy.xpath(<another-long-xpath-selector>).drag(fileLocated, { force: true})
因为fileLocated
不会是一个元素(这是您作为放置目标所需要的),它将是一个 Chainer。
相反,这样做
cy.xpath(<horrendously-long-xpath-selector>)
.then( targetItem => {
...
cy.xpath(<another-long-xpath-selector>).drag( targetItem, { force: true})
})
推荐阅读
- javascript - 如何从javascript中的自定义对象构造函数返回视频持续时间?
- javascript - 如何修复班级中未定义的错误?
- vue.js - Vue JS:更改后vuex状态不更新组件
- c# - 异步操作已取消但仍需要时间来更新网格
- r - 当从一个简单的一维向量进行子设置时,为什么我们需要连接位置向量?
- c# - 将 ILogger 传递到 .net 核心控制台中的 DI 导致服务未注册错误
- android - Android Studio 3.3 不允许 SDK 版本低于 26 的自适应图标
- sas - 计算置信区间的值
- php - 检查数组是否可以在单次交换中按升序排序
- ajax - 在 rest API 中避免使用 CORS