程序化点击JS通知

时间:2017-01-06 07:55:30

标签: javascript selenium testing

我正在尝试测试我的webapp,其中显示了js通知: $("#bx-pager").bxSlider({ slideWidth: 275, minSlides: 3, maxSlides: 3, slideMargin: 0, controls: true, pager: false, infiniteLoop: false, prevText: "", nextText: "" }); 。然后我需要测试当我点击它时是否发生了某些行为。如何在javascript中模拟用户点击通知?

1 个答案:

答案 0 :(得分:0)

存储构建后获得的通知对象。然后您可以执行任何操作

  var notification = new Notification('test', {
    icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
    body: 'this is body of the notification'
  });                                  

  notification.onclick = function() { alert('got clicked'); }  //handler   

  var event = new Event('click');        //event creation 
  notification.dispatchEvent(event);     //triggering