[英]Angular 2 e2e Testing
I just started with Angular 2 and e2e testing and I am trying to close a Bootstrap 4 modal by clicking in a blank area, using Protractor. 我刚开始进行Angular 2和e2e测试,并且尝试通过使用Protractor在空白区域中单击来关闭Bootstrap 4模式。 I've tried:
我试过了:
it('should close the login modal when the blank space outside of the modal is clicked', () => {
element(by.tagName('body')).click().then(function() {
browser.sleep(250);
expect(element(by.id('myModal')).isDisplayed()).toBeFalsy();
});
});
...and I've even tried: ...而且我什至尝试:
it('should close the login modal when the blank space outside of the modal is clicked', () => {
browser.actions()
.mouseMove(element(by.id('login_modal')), -20, -20)
.click().then(function() {
browser.sleep(250);
expect(element(by.id('login_modal')).isDisplayed()).toBeFalsy();
});
});
I'm new the the Angular 2 world, so the answer is probably obvious. 我是Angular 2世界的新手,所以答案很明显。 Thank you in advance for any help.
预先感谢您的任何帮助。
I haven't seen your HTML, but I think this will happen. 我还没有看到您的HTML,但是我认为这会发生。 A
click
-action on an element will execute a click on the center of the element, see the actions docs . 一个
click
一个元素肌动将在元件的中心执行点击,看到行动文档 。
It depends on how your modal is positioned on the page, but in common situations, a modal is in the center of the page. 这取决于模态在页面上的位置,但是在通常情况下,模态位于页面的中心。 If we use that as a given and we execute the first click command you describe above, we will get the following
如果将其作为给定值并执行上面描述的第一个单击命令,我们将获得以下内容
body
, the body it the full screen, the center of the body will click on the modal => modal will not be closed body
,主体将全屏显示,主体的中心将单击模态=> 模态将不关闭 The second click command you describe fails because you need to provide an object, see here , so it needs to be 您描述的第二个click命令失败,因为您需要提供一个对象(请参见此处) ,因此需要
browser.actions() .mouseMove(element(by.id('login_modal')), { x: toRight, y: toBottom }) .click().then(function() { browser.sleep(250); expect(element(by.id('login_modal')).isDisplayed()).toBeFalsy(); });
Thanks for the feedback, which led me to the answer. 感谢您的反馈,这使我找到了答案。 I should have posted that this is a bootstrap modal, which is relevant.
我应该已经发布过,这是一个相关的引导程序模式。 When called, the modal covers the whole page, not just the rectangle in the middle.
调用时,模式将覆盖整个页面,而不仅仅是中间的矩形。 By setting my coordinates to x:0, y:0 I was on the "blank" area of the modal.
通过将坐标设置为x:0,y:0,我处于模态的“空白”区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.