如何避免双击不同的按钮? [英] How to avoid double click on different button?

查看:78
本文介绍了如何避免双击不同的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题不是双击同一按钮而是双击两个按钮.

My problem is not a double click on same button but on 2 buttons.

用户双击按钮.

  • 通过第一个按钮检测到第一次点击
  • 控制器执行操作
  • UI刷新,另一个按钮显示在相同位置
  • 第二个点击被第二个按钮捕获 =>用户不想单击第二个按钮
  • The first click is detected by a first button
  • the controller do the action
  • the UI is refreshed, another button is display at same position
  • the second click is catched by the second button => user don't want click on the second button

如何避免这种情况?

我已经测试过:

  • 在操作期间禁用所有UI按钮
    但是如果操作确实非常快,则在第二次单击之前启用按钮

  • To disable all UI buttons during action
    but if action is really quick, buttons are enable before the second click

不要在用户界面的同一位置放置2个按钮
并非总是可能,并且使用响应式UI不可能管理所有情况

To not put 2 buttons on same place in the UI
not always possible and with responsive UI it's not possible to manage all cases

要在点击时添加全局时间戳记,并在第二次点击时测试是否有500毫秒

To add a global timestamp on click, and test during the second click if we have 500ms

            _click: function(args)
            {
                // to avoid double click user need wait 500ms between each click
                if(window.paperbutton_timestamp)
                {
                    var diff = new Date() - window.paperbutton_timestamp;                            
                    if(diff < 500)
                    {
                        window.paperbutton_timestamp = new Date();                        
                        return;
                    }
                }
                window.paperbutton_timestamp = new Date();                        

                if(scope.click)
                {
                    scope.click(args);
                }
            },

好的,就可以了.

现在,我的问题是我有很多量角器端到端测试,点击次数超过2000次. 在500ms内完成一些量角器点击.

Now my problem is I have many protractor end to end tests, with more 2000 clicks. Some protractor click are done in less 500ms.

我可以使用哪种解决方案?
1.每次点击后添加一个等待时间
(超过2000个等待手动添加)
2.在全局变量中设置500ms,并将此值覆盖为0ms
如何覆盖每个测试和每个页面的刷新?
3.覆盖量角器,单击?
Seam是更好的解决方案,但我不知道该怎么做.

Which solution can I have ?
1. Add a wait after each click
(more 2000 wait to add manually)
2. Set the 500ms in a global variable and override this value to 0ms
how to override on each test and each page refresh ?
3. Override protractor click ?
Seam is the better solution but I don't know how to do this.

  • 您还有另一个更好的主意:)吗?

推荐答案

如果您为量角器点击编写自定义函数会更好:

It would be better if you write a custom function for protractor click:

protractor.ElementFinder.prototype.waitClick = function(wait){
  browser.sleep(wait);
  this.click();
};

describe('Tests', function() {
  element.all(by.css('#testElements')).get(0).waitClick(1000)
});

因此,不建议覆盖默认的点击功能.

Since, overriding the default click function is not recommended.

这篇关于如何避免双击不同的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆