怎么使用nightmare

这篇文章主要讲解了“怎么使用nightmare”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用nightmare”吧!

  今天将介绍一款自动化测试套件名叫nightmare,他是一个基于phantomjs的测试框架,一个基于phantomjs之上为测试应用封装的一套highlevelAPI。其API以goto,refresh,click,type…等简单的常用e2e测试动作封装,使得其语义清晰,简洁。

  安装nightmare:

  npminstallnightmare

  下面我们对比nightmare与远程phantomjs:

  原phantomjs的代码:

  phantom.create(function(ph){

  ph.createPage(function(page){

  page.open('http://yahoo.com',function(status){

  page.evaluate(function(){

  varel=

  document.querySelector('input[title="Search"]');

  el.value='githubnightmare';

  },function(result){

  page.evaluate(function(){

  varel=document.querySelector('.searchsubmit');

  varevent=document.createEvent('MouseEvent');

  event.initEvent('click',true,false);

  el.dispatchEvent(event);

  },function(result){

  ph.exit();

  });

  });

  });

  });

  });

  nightmare代码:

  newNightmare()

  .goto('http://yahoo.com')

  .type('input[title="Search"]','githubnightmare')

  .click('.searchsubmit')

  .run();

感谢各位的阅读,以上就是“怎么使用nightmare”的内容了,经过本文的学习后,相信大家对怎么使用nightmare这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!