负载测试csript intern.js内测试

问题描述:

我想根据通过启动命令传递的自定义参数加载测试脚本来开始实习测试。 要做到这一点,我试图要求在测试中的具体测试脚本,但我得到Attempt to require unloaded module错误。 这是我的代码设置。有人可以帮助解决这个问题,或者采取一些替代方法来完成这项工作。负载测试csript intern.js内测试

define(function (require) { 
var intern = require('intern'); 
var AdvalentAutomationTestSuite = require('intern!object'); 
AdvalentAutomationTestSuite({ 
    name: 'Advalent Automation Test', 

    'AdvalentTestSets': function() { 
     return this.remote 
      .then(function() { 
       var product = intern.args.product; 
       var script = 'Automation/TestScripts/FRG/' + product + '-Config'; 
       require(script) 
      }) 
     }, 
    }); 
}); 

更新:

intern.js包括文件:

define(function (require) { 
var intern = require('intern'); 
console.log(intern) 
return { 
    proxyPort: 9000, 

    proxyUrl: 'http://localhost:9000/', 
    defaultTimeout: 120000, 
    capabilities: { 
     'selenium_version': '2.48.2', 
    }, 

    environments: [ 
     {browserName: 'chrome', version: '48', platform: ['WINDOWS'], chromeOptions: {args: ['start-maximized']}}, 
    ], 

    maxConcurrency: 3, 

    tunnel: 'NullTunnel', 
    reporters: [ 
     {id: 'JUnit', filename: 'test-reports/report.xml'}, 
     {id: 'Runner'}, 
    ], 

    Loaders: { 
     'host-node': 'dojo/dojo', 
     'host-browser': 'node_modules/dojo/dojo.js' 
    }, 
    loaderOptions: { 
     packages: [{name: 'intern-tutorial', location: '.'}] 
    }, 

    functionalSuites: [ 

     'Automation/TestScripts/FRG/FRG-Config', 
    ], 
    defaultTimeout: 70000, 
    excludeInstrumentation: /^(?:tests|node_modules)\// 
} 

});

你应该罚款与默认加载器,虽然正如@Troopers指出的那样,它是loaders,而不是Loaders。问题是,你正在做一个动态的需要与计算机名称:

var script = 'Automation/TestScripts/FRG/' + product + '-Config'; 
require(script) 

AMD装载机不完全支持require(script)语法,因为他们不加载模块同步。当模块使用CJS兼容模式编写时,加载程序通过扫描模块代码来调用require调用,然后在执行模块代码之前预加载和缓存模块。当最终执行require(script)调用时,将返回预加载的模块。

当您使用计算模块名称时,加载程序无法预加载所需模块,因此同步require调用将失败。要加载模块与计算名字,你需要使用require([ dependency ])语法,如:

var script = 'Automation/TestScripts/FRG/' + product + '-Config'; 
return new Promise(function (resolve) { 
    require([ script ], resolve); 
}); 

在一个较高的水平,不过,它似乎很奇怪在第一地点进行测试,在做这个。这似乎是应该在模块或配置级别处理的东西。例如,假设'Automation/TestScripts/FRG/' + product + '-Config'是一个功能测试套件,如果提供了所需的命令行参数,配置可以简单地将该套件添加到functionalSuites列表。

+0

感谢@ jaso0x43这是启示。感谢分享知识。至于我的问题的解决方法,我解决了如果从'intern.js'文件。我也添加了我的解决方案作为在这篇文章中的答案。请在回顾我的方式后建议是否有更好的方法来做到这一点。 – CodeBlooded

您需要在您的配置文件来指定装载机:

loaders: { 
    "host-node": "requirejs", 
    "host-browser": "node_modules/requirejs/require.js" 
}, 

并安装NPM包requirejs

的文档here

+0

你的意思是我必须安装'require.js' packae加载脚本。正如我在上述问题中所做的一样?你能否详细说明一下。 – CodeBlooded

+0

我的intern.js文件中已经定义了一个加载器。我updatin我的问题也包括intern.js文件。 – CodeBlooded

+0

您的加载程序部分在您的intern.js文件中不正确:使用'loaders'而不是'Loaders'并使用require.js加载程序代替dojo加载程序 – Troopers

几命中和试用后,我设法让它改变我的intern.js如下工作:

define(function (require) { 
    var intern = require('intern'); 
     var product = intern.args.product 
     return { 


    functionalSuites: [ 
     'Automation/TestScripts/FRG/' + product + '-Config.js', 
     ], 
// rest of config code ... 
    } 
}); 

请建议,如果有什么更好的办法来做到这一点。