赛普拉斯触发器不会在每个循环中保持两次点击
Cypress trigger does not hold the click two times in same each loop
我正在尝试删除“每个”循环内的记录。每次运行第一次都删了,第二次就点不挂了。
cy.get('pc-fonts-manager-list').then(($fontsList) => {
cy.get('pc-fonts-family-list-item').each(listItem =>{
cy.get('[data-at=fontName]').first().invoke('text').then($fontName =>{
cy.get('[data-at=removeFontBtn]').first().click();
cy.holdToDeleteFontFamily('[data-at=fontFamilyConfirmRemoveBtn]');
cy.wait('@deleteFamily');
cy.assertSnackbarMessage(' Font Family \''+$fontName+'\' has been deleted ');
这是点击并按住按钮的片段(第一次迭代有效):
Cypress.Commands.add('holdToDeleteFontFamily', (element) =>{
cy.get(element).focus().trigger('keydown', {key: 'Enter'})
});
我不确定它是否与 trigger()
有关,因为我也尝试了 'mouseclick' 方法,但它也没有用。
HTML片:
<div class="c-alert__buttons"><button _ngcontent-cvf-c367="" ip-btn-regular-tertiary="" size="small" data-at="fontFamilyCancelRemoveBtn" class="c-btn c-btn--regular-tertiary c-btn--regular-tertiary-small c-btn--regular-tertiary-danger" ng-reflect-size="small"><span class="c-btn__content"> cancel </span></button><button _ngcontent-cvf-c367="" ip-btn-regular-secondary="" ip-btn-click-and-hold="" size="small" data-at="fontFamilyConfirmRemoveBtn" class="c-btn c-btn--regular-secondary c-btn--regular-secondary-small c-btn--click-and-hold c-btn--regular-secondary-danger" ng-reflect-size="small"><span class="c-btn__content"> confirm </span></button></div>
感谢您的帮助!
我通过在触发 keydown
之前添加一个额外的 click()
来解决
cy.get(element).focus().click().trigger('keydown', {key: 'Enter'})
我正在尝试删除“每个”循环内的记录。每次运行第一次都删了,第二次就点不挂了。
cy.get('pc-fonts-manager-list').then(($fontsList) => {
cy.get('pc-fonts-family-list-item').each(listItem =>{
cy.get('[data-at=fontName]').first().invoke('text').then($fontName =>{
cy.get('[data-at=removeFontBtn]').first().click();
cy.holdToDeleteFontFamily('[data-at=fontFamilyConfirmRemoveBtn]');
cy.wait('@deleteFamily');
cy.assertSnackbarMessage(' Font Family \''+$fontName+'\' has been deleted ');
这是点击并按住按钮的片段(第一次迭代有效):
Cypress.Commands.add('holdToDeleteFontFamily', (element) =>{
cy.get(element).focus().trigger('keydown', {key: 'Enter'})
});
我不确定它是否与 trigger()
有关,因为我也尝试了 'mouseclick' 方法,但它也没有用。
HTML片:
<div class="c-alert__buttons"><button _ngcontent-cvf-c367="" ip-btn-regular-tertiary="" size="small" data-at="fontFamilyCancelRemoveBtn" class="c-btn c-btn--regular-tertiary c-btn--regular-tertiary-small c-btn--regular-tertiary-danger" ng-reflect-size="small"><span class="c-btn__content"> cancel </span></button><button _ngcontent-cvf-c367="" ip-btn-regular-secondary="" ip-btn-click-and-hold="" size="small" data-at="fontFamilyConfirmRemoveBtn" class="c-btn c-btn--regular-secondary c-btn--regular-secondary-small c-btn--click-and-hold c-btn--regular-secondary-danger" ng-reflect-size="small"><span class="c-btn__content"> confirm </span></button></div>
感谢您的帮助!
我通过在触发 keydown
click()
来解决
cy.get(element).focus().click().trigger('keydown', {key: 'Enter'})