测试量角器是否可点击元素 很简单,但是我一直抓挠头试图弄清楚如何检查元素是否可点击
It's trivial to test if an element is clickable with Protractor, but I'm stuck scratching my head trying to figure out how to check if an element is not clickable.
我试图将click函数包装在try/catch中,以便当尝试单击时引发错误时,它应该捕获并让测试通过;但是,这不起作用.
I've attempted to wrap the click function in a try/catch so that when an error is thrown when trying to click it should catch it and let the test pass; however, this does not work.
这是我执行检查的方法的代码:
Here is my code for the method that does the check:
return this.shouldSeeDisabledFunds() .then(function() { var clickable = true; try { fundsElem.first().click(); } catch (e) { clickable = false; console.log(clickable); } finally { console.log(clickable); } console.log(clickable); // All the way through, clickable is still true, and the console log in the // catch is not called. I believe this is because click is asynchronous. }) ;推荐答案
我找到了适用于此的解决方案.当click()返回一个承诺时,您可以简单地.then离开它,并放入成功的单击处理程序,并覆盖catch处理程序以执行任何操作,如果该元素不可单击,则使测试通过.
I have found a solution that works for this. As click() returns a promise you can simply .then off of it and throw in the successful click handler and override the catch handler to do nothing which makes the test pass if the element is not clickable.
return this.shouldSeeDisabledFunds() .then(function() { fundsElem.first().click() .then( function() { throw "Can click Funds element that should be disabled"; }, function() {} ) ; }) ;更多推荐
如何检查量角器是否不可单击某个元素?
发布评论