Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将已计算的javascript函数返回到终端_Javascript_Phantomjs - Fatal编程技术网

将已计算的javascript函数返回到终端

将已计算的javascript函数返回到终端,javascript,phantomjs,Javascript,Phantomjs,我正在尝试返回一个已计算到终端的函数。我尝试使用window.onload(),console.log()警报()但是URL不会被计算并发送到终端 我使用命令phantomjstest.js var webPage = require('webpage'); var page = webPage.create(); function testlink() { return(["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o",

我正在尝试返回一个已计算到终端的函数。我尝试使用
window.onload()
console.log()
警报()
但是URL不会被计算并发送到终端

我使用命令
phantomjstest.js

var webPage = require('webpage');
var page = webPage.create();

function testlink() {
  return(["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o","m"]);
}

window.onload = testlink;
console.log(testlink);
alert(testlink);
而不是得到(这是我想要的

我明白了

function testlink() {
  return(["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o","m"]);
}

Ps:我正在使用Ubuntu 18.04和phantomjs 2.1.1

试着做
console.log(testlink())
而不是
console.log(testlink)

如果要加入该数组中的所有字符,只需返回:

[“h”,“t”,“t”,“p”,“s”,“s”,““:”,“\/”,“\/”,“\/”,“i”,“b”,“m”,“c”,“o”,“m]”。加入(“”)


或者,如果您不想更改函数,请执行
console.log(testlink().join(“”)

感觉您刚刚开始编写此代码,而没有阅读虚拟文档:您已经创建了一个页面,然后呢?之后的代码基本上没有意义:这是一个测试用例,你在测试什么?因为将已知数组打印到终端没有任何意义,并且对页面应该做什么没有任何洞察。那么:你到底想做什么?@Mike'Pomax'Kamermans试图返回一个经过评估的url链接,该链接是使用javascript函数生成的,并在终端中显示出来。好吧,但是:为什么?因为Puppeter用于运行测试,并使用有用的退出代码退出(如果一个或多个测试未通过,还可以选择使用错误日志)。终端不应该是您查看测试执行情况的方法(当然也不应该是您试图寻找进一步自动化方面的特定信息的地方)。此外,在合理的代码注释上,我强烈建议不要使用
返回([“h”、“t”、“t”、“p”、“s”、“s”)、“:”、“\/”、“I”、“b”、“m”、“c”、“o”、“m”)但使用
返回“https://ibm.com.split(“”)
。请注意,
return
不是一个函数:它只是
return
,而不是
return(…)
。(后者会起作用,但不是出于您可能认为的原因,所以不要在返回时使用括号)它很接近,但它为输出提供了
h,t,t,p,s,:,/,/,i,b,m,,,c,o,m
。是吗?因为您在该函数中返回的是
[“h”、“t”、“t”、“p”、“s”、“:”、“\/”、“\/”、“\/”、“i”、“b”、“m”、“c”、“o”、“m”]
。Idk你期望它做什么。如果你想把所有的字符连接起来,请看我编辑过的答案。
function testlink() {
  return(["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o","m"]);
}