![](/img/trans.png)
[英]Is there any method to know if an element is focused using Dalek.js?
[英]Using Global Variables Dalek JS
首先,这里的测试工具很好用,因为我大量使用硒。 这可能是基本的,但对javascript和node.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
我在这里做错了吗?
任何帮助表示赞赏
谢谢
好吧,看来这是我的用户错误,只要它对其他人有帮助,都会发布答案。 在Node.js中设置变量不同于典型的客户端Javascript。
所以我在哪里设定
var url = "www.google.co.uk"
我需要设置
global.url = "www.google.co.uk"
Node.js处理“导入”文件的要求与我们在浏览器领域的要求不同。 这样的SO帖子很好地概述了“如何”和“为什么”:
Node.js module.exports的用途是什么,如何使用它?
如果您正在寻找有关如何保持DRY和模块化测试的DalekJS特定资源,请查看此存储库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
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.