如何使用Protractor和Jasmine测试指针事件:none?

时间:2016-07-08 11:00:35

标签: css testing jasmine protractor

在某些情况下,我正在设置css属性" pointer-events:none"避免一个元素被点击(它是一个复杂的元素,不能一个一个地被禁用,它被div包裹,这个div的指针事件为无)

那么过去可以点击和测试的东西,已经不存在了。

当我尝试测试时,我总是得到这个:

 Failed: unknown error: Element is not clickable at point (167, 407). Other element would receive the click:...

这是预期的,因为元素不可点击,父元素获得点击。

我的问题是,如何通过设置此属性(指针事件)来测试Protractor / Jasmine无法点击的元素?

顺便说一句,常用的方法是启用和isDisplay,它们都返回true。

我还考虑过使用toThrow()或ToThrowError()创建一个预期错误的测试(尽管我更喜欢更清晰的解决方案),但它根本不起作用。

由于

1 个答案:

答案 0 :(得分:2)

您可以尝试特殊的EC - http://www.protractortest.org/#/api?view=ExpectedConditions.prototype.elementToBeClickable

示例:

var isClickable = protractor.ExpectedConditions.elementToBeClickable($('your element here'));
expect(isClickable()).toBeFalsy('Element expected not to be clickable');

我遇到了同样的问题 - 我如何断言我无法点击元素 -

myElement.click().then(
  () => {
    fail("Element should not be clickable for Observer");
  },
  (err) => {
    expect(err.message.toString()).toMatch("Element is not clickable at point");
});

抛出错误回调并断言正确的错误被抛出。