如何使用Protractor和Jasmine测试pointer-events: none?

3

在某些情况下,我会设置CSS属性"pointer-events:none"来避免元素可点击(它是一个复杂的元素,无法逐个禁用,并且它被一个div包裹着,这个div的pointer-events设置为none)

所以曾经是可点击的并进行了测试的元素,现在不再可点击。

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

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

这是预期的,因为当元素不可点击时,父元素会接收到点击事件。

我的问题是,如何使用Protractor/Jasmine测试一个通过设置pointer-events属性而不可点击的元素?

顺便说一下,常用的isEnabled和isDisplayed方法都返回true。

我也考虑过创建一个预期错误的测试(虽然我更喜欢更干净的解决方案),使用toThrow()或ToThrowError(),但它根本没有起作用。

谢谢

1个回答

3
您可以尝试使用特殊的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");
});

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


1
使用elementToBeSelected()方法对我有效,而使用elementToBeClickable()方法返回了true而不是false。 - AzizStark

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接