2014-03-24 38 views
0

首先伟大的测试工具替代在这里球员,因为我大量使用硒。这可能是基本的,但对于特定的javascript和node.js是一种新的东西。使用全局变量Dalek JS

我希望能在我的脚本中使用全局变量,但我有麻烦这样做

我有一个名为在同一水平作为我test.js例如脚本变量文件,在这个例子中我将google分配给变量url,但是在运行测试时无法加载。

require('variables.js'); 

module.exports = { 
'Log into Traceiq': function (test) { 
test 
.open(url) 
.done(); 
} 
}; 

然后我尝试这样做,测试开始运行,但在开局阶段

require('./variables'); 

module.exports = { 
'open Google': function (test) { 
test 
    .open(url) 
    .done(); 
} 
}; 

挂这是在控制台

Running tests 
Running Browser: Google Chrome 
OS: Linux 3.5.0-45-generic x86_64 
Browser Version: 31.0.1650.63 
>> WARNING: done not called! 

RUNNING TEST - "Open Google" 
✔ 0 Assertions run 
✔ TEST - "Open Google" SUCCEEDED 

输出有什么盲目明显,我在这里做错了?

任何帮助表示赞赏

感谢

回答

0

那么看起来就像是我的一部分螺母用户错误将发布的答案只是柜面它可以帮助别人。在Node.js中设置变量与典型的客户端Javascript不同。

所以我在那里设置

var url = "www.google.co.uk" 

我需要设置

global.url = "www.google.co.uk" 
0

Node.js的处理“进口”的文件与需要从我们习惯在browserland不同。这个所谓后给出了关于“如何” &“为什么”一个很好的概述:

What is the purpose of Node.js module.exports and how do you use it?

如果您正在寻找DalekJS如何保持你的测试DRY &模块化,看看这个库https://github.com/asciidisco/jsdays-workshop/tree/8-dry我特定的资源为研讨会制作。更具体地讲,这些文件特别:

https://github.com/asciidisco/jsdays-workshop/blob/8-dry/test/dalek/form2.js https://github.com/asciidisco/jsdays-workshop/blob/8-dry/test/dalek/functions/configuration.js https://github.com/asciidisco/jsdays-workshop/blob/8-dry/test/dalek/functions/formHelper.js https://github.com/asciidisco/jsdays-workshop/blob/8-dry/test/dalek/functions/selectors.js

希望有所帮助。