柏树结束的引导模式
试图关闭模式时,它们不会关闭。
我有几种从不同元素调用的自举模式。要显示它们,我执行以下操作:
cy.get('#units_modal')。click(click()
,并且毫无问题地显示模式。
问题是关闭模态时。我想在hook 之后关闭中的对话框,当该的所有测试部分都完成时,我正在说:
describe('Checking vehicles.', function(){
before(()=>{
cy.get('#unitsCommandHeaderMenu').click()
cy.get('#units_modal').should('be.visible')
})
after(()=>{
cy.get('#units_modal')
.then(($dialog)=>{
cy.wrap($dialog).find('button').find('span').contains("×").click()
});
})
it('first test', ()=> {
cy.log('first test')
})
it('second test', ()=> {
cy.log('second test')
})
})
从视觉工具中,当我将指针放在点击事件我看到关闭按钮正在正确选择,应该单击它,但模态不会关闭。
甚至尝试使用:关闭Cypress中的角度材料对话框
这是我的HTML代码。
<!-- buttons -->
<ul class="modal">
<li id="first" data-toggle="modal" data-target="#units_modal">
<span>first</span>
</li>
<li id="second" data-toggle="modal" data-target="#second_modal">
<span>second</span>
</li>
<li id="third" data-toggle="modal" data-target="#third_modal">
<span>third</span>
</li>
</ul>
<!-- modals -->
<div class="modal fade" id="units_modal" tabindex="-1" role="dialog" aria-labelledby="firstModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- header -->
</div>
<div class="modal-body toFill">
<!-- body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-modal-update"><span class="modal-update-btn-spinner fa fa-refresh"></span><span class="modal-update-btn-text">Update</span></button>
<button type="button" class="btn btn-secondary btn-modal-add"><span class="fa fa-plus"></span><span class="modal-update-btn-text">Add</span></button>
<button type="button" class="btn btn-secondary btn-modal-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="second_modal" tabindex="-1" role="dialog" aria-labelledby="secondModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- header -->
</div>
<div class="modal-body toFill">
<!-- body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-modal-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="third_modal" tabindex="-1" role="dialog" aria-labelledby="thirdModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- header -->
</div>
<div class="modal-body toFill">
<!-- body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-thirdary btn-modal-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
When trying to close the modals they don't close.
I have several bootstrap modals that are called from different elements. To display them I do the following:
cy.get('#units_modal').click()
And the modal is displayed without problem.
The problem is when closing the modal. I want to close the dialog in the after hook when all the tests of that describe section have finished, I am putting:
describe('Checking vehicles.', function(){
before(()=>{
cy.get('#unitsCommandHeaderMenu').click()
cy.get('#units_modal').should('be.visible')
})
after(()=>{
cy.get('#units_modal')
.then(($dialog)=>{
cy.wrap($dialog).find('button').find('span').contains("×").click()
});
})
it('first test', ()=> {
cy.log('first test')
})
it('second test', ()=> {
cy.log('second test')
})
})
From the visual tool, when I put the pointer on the click event I see that the close button is being selected correctly and it should be clicking on it, but the modal does not close.
Even try the solution suggested by: Closing an Angular Material Dialog in Cypress
This is my html code.
<!-- buttons -->
<ul class="modal">
<li id="first" data-toggle="modal" data-target="#units_modal">
<span>first</span>
</li>
<li id="second" data-toggle="modal" data-target="#second_modal">
<span>second</span>
</li>
<li id="third" data-toggle="modal" data-target="#third_modal">
<span>third</span>
</li>
</ul>
<!-- modals -->
<div class="modal fade" id="units_modal" tabindex="-1" role="dialog" aria-labelledby="firstModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- header -->
</div>
<div class="modal-body toFill">
<!-- body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-modal-update"><span class="modal-update-btn-spinner fa fa-refresh"></span><span class="modal-update-btn-text">Update</span></button>
<button type="button" class="btn btn-secondary btn-modal-add"><span class="fa fa-plus"></span><span class="modal-update-btn-text">Add</span></button>
<button type="button" class="btn btn-secondary btn-modal-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="second_modal" tabindex="-1" role="dialog" aria-labelledby="secondModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- header -->
</div>
<div class="modal-body toFill">
<!-- body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-modal-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="third_modal" tabindex="-1" role="dialog" aria-labelledby="thirdModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- header -->
</div>
<div class="modal-body toFill">
<!-- body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-thirdary btn-modal-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是他们在按钮上的“ X”不是您从键盘上获得的“ X”。
我在下面显示了这两个,因此您可以比较它们。
但是使差异的行似乎是
。
实际上,我只是检查了 - 您的“ x”正确,
如果您在测试中不仅有
cy.log()
,就不会发生问题。可见性检查似乎使测试代码等待淡入淡出的动画完成(在顶部元素上,请参见
class =“模态淡出show”
)。I think the problem is the "x" they have on the button is not the one you get from the keyboard.
I've shown both below so you can compare them.
Actually, I just checked - you have the right "x", but the line that makes the difference seems to be
.should('be.visible')
after finding the modal (not checked exhaustively)
Maybe if you have more than just a
cy.log()
in the tests, the problem would not occur.The visibility checks seem to make the test code wait for the fade animations to complete (see
class="modal fade show"
on the top element).