使用 javascript 准备自动化测试以测试模块
Preparing an automated testing using javascript for testing a module
该模块有三个页面,单击下一个或上一个按钮时,它们会逐个更改。我可以通过编写两次单击方法来单击它。如何在一次测试中使其工作?我必须使用循环或任何其他方式吗?请建议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时运行测试。我正在为我的模块使用这些服务,非常高兴。
相关文章:
- 如何在Mocha/Chai中测试JS原型(非模块)
- 找不到模块'它'当用摩卡/柴测试时
- 如何测试运行 node-fluent-ffmpeg(异步模块)的自定义模块
- 如何为多个需求模块设置单元测试
- 错误:使用摩卡测试时找不到模块
- 如何防止模块的运行块在测试期间被执行
- 使用谷歌地图模块依赖性运行Karma测试
- 单元测试节点模块与mocha,模块变量行为怪异
- Gulp测试找不到模块
- 如何在测试的函数中对外部模块进行调用
- 单元测试使用全局的模块.XMLHttpRequest
- 模块模式单元测试
- 茉莉花测试显示模块未定义
- 使用 javascript 准备自动化测试以测试模块
- 如何向nodejs超级测试模块添加方法
- Instruments Xcode中的UIAutomation测试模块
- javascript:我如何制作自己的测试模块
- 在Angular.js中测试模块控制器、工厂、服务等
- 单元测试模块化javascript
- 测试模块的未导出节点方法