使用 javascript 准备自动化测试以测试模块

Preparing an automated testing using javascript for testing a module

本文关键字:测试 模块 自动化测试 javascript 使用      更新时间:2023-09-26

该模块有三个页面,单击下一个或上一个按钮时,它们会逐个更改。我可以通过编写两次单击方法来单击它。如何在一次测试中使其工作?我必须使用循环或任何其他方式吗?请建议JavaScript,我的箭头环境对我来说是新的。我们正在使用 nodejs。

其次,他们正在为该模块添加自动旋转功能,为此我还必须准备自动化测试。请建议如何自动测试此功能。

http://att.yahoo.com/ (检查聚焦模块)

为了您的方便,这是我为该模块编写的当前代码:

YUI.add("cdt-att-spotlight-func-tests", function(Y) {
  'use strict';
  var Utils = Y.Media.Cdt.FuncTestUtils;
  Y.Media.Cdt.FuncTestUtils.DebugMode=true;
  var selectors = {
          module: "#mediabcarouselmixedlpca_2",
          /*title: ".heading",
                  numberSlot: ".yui-carousel-pagination",
          clickButtons: ".ymg-nav-buttons",*/
          nextButton: ".yui-carousel-next",
          prevButton: ".yui-carousel-prev",
                  visibleImage:".img-wrap",
                  /*linkText_bestdeals: ".txt",
                  linkText_CheckGoPhone:".txt",
                  linkText_greatdeals:".txt",*/
                  linkText: ".txt"
  };
  var suite = new Y.Test.Suite("Cdt Att Spotlight Func Test Suite");
  suite.add(new Y.Test.Case({
    setUp: function() {
         // Find our module...
        this.module = Y.one(selectors.module);
     // Define our components...
        this.components = {
            nextButton: this.module.one(selectors.nextButton),
                prevButton: this.module.one(selectors.prevButton),
                visibleImage: Utils.track.selector(this.module, selectors.visibleImage),
                linkText: this.module.one(selectors.linkText)
        }; 

        this.module.scrollIntoView();
    },
     "Verify MediaCdtAttSpotlight module loaded": function() {
         this.module.should.be.visibleToUser();
       },

        "Verify Image showed in the module": function() {
      var visibleImage = this.components.visibleImage.current();
      this.wait(function() {
        visibleImage.should.be.visibleToUser();
      }, 2000);
    },

       "Verify the Link Text is visible": function() {
        this.components.linkText.should.be.visibleToUser();
      },

    "Verify clicking next button to scroll left": function() {
      this.components.nextButton.simulate("click");
      this.wait(function() {
      }, 3000);
    },

    "Verify clicking next button1 to scroll left": function() {
      this.components.nextButton.simulate("click");
      this.wait(function() {
      }, 3000);
    },

     "Verify clicking prev button to scroll right": function() {
      this.components.prevButton.simulate("click");
      this.wait(function() {
      }, 2000);
    },

     "Verify clicking prev button1 to scroll right": function() {
      this.components.prevButton.simulate("click");
      this.wait(function() {
      }, 2000);
    }

  }));
  Y.Test.Runner.add(suite);
}, "0.1", { requires: ["test", "node", "node-event-simulate", "chai-yui", "cdt-func-test-utils"]});

注意:这个问题针对的是一般的nodejs模块测试,而不是Arrow。我不想删除它,因为作者正在我的 anwser 的评论中寻找一些事情的澄清。如果需要,我很乐意删除此 anwser。

我会推荐摩卡 http://visionmedia.github.io/mocha/。这是一个非常受欢迎的出色测试框架。当与模块应该结合使用时,您可以编写简单的测试,如下所示。

require('should');
describe('Array', function(){
  describe('#indexOf()', function(done){
    it('should return -1 when the value is not present', function(){
      [1,2,3].indexOf(5).should.equal(-1);
      [1,2,3].indexOf(0).should.equal(-1);
      done();
    })
  })
})

然后,您可以设置一个名为travis ci https://travis-ci.org/的免费Web服务,以便在推送到github时运行测试。我正在为我的模块使用这些服务,非常高兴。