javascript - 从Robot Framework中的js文件调用函数
问题描述
有可能从文件中执行 javascript。
Execute JavaScript ${CURDIR}/js_to_execute.js
但是我怎样才能从这个文件中按名称调用一个函数呢?
解决方案
Execute Javascript
无法使用开箱即用的方式调用函数。但是可以将函数名作为参数传递。
Execute Javascript ${CURDIR}/js/utils.js ARGUMENTS clickElement ${locator}
文件内容utils.js
:
var utils = utils || {};
(function (arguments) {
utils.clickElement = function (locator) {
// implementation of the function
}
// this piece of code does the trick
// get function name from arguments and remove it from the list of arguments
var functionName = [].shift.call(arguments);
// call the function and pass the arguments
utils[functionName].apply(this, arguments);
})(arguments);
推荐阅读
- amazon-cloudformation - AWS CloudFormation Parameter values specified for a template which does not require them
- python - AttributeError:“Checkbutton”对象没有“取消选择”属性
- solr - 将文档从索引转换为适合包含在 SolrQueryResponse 中的 SolrDocument 的方法
- c# - 需要在通过wpf中的函数打开的网页中输入username的值
- java - 正则表达式允许在 java 中为空或正的非零数字
- css - 显示来自单个控制器的不同样式通知消息以进行插入、更新或错误
- delphi - 德尔福。WinInet + 思科 + NTLM。12045 和 12057 错误
- java - WARN EclipseJavaCompiler 使用不受支持的 Java 版本“11”,假设在 Java 11 上运行 AEM 6.5 时最新支持的版本“9”
- javascript - window.addEventListener('online') 如何工作?
- gcc - 我如何进一步了解 gcc 使用的编译过程?