我有一个Python脚本,管理一系列CasperJS任务并处理结果.它从命令行运行良好,但是当我在cron中运行脚本时,我收到错误:
CalledProcessError: Command '['/path/to/casperjs', '/path/to/doSomething.js', 'args']' returned non-zero exit status 1
Run Code Online (Sandbox Code Playgroud)
在Python中,我称之为CasperJS:
response = subprocess.check_output(['/path/to/casperjs', '/path/to/doSomething.js', 'args'], shell=True)
Run Code Online (Sandbox Code Playgroud)
我曾尝试shell=False和Popen好,但我得到了相同的结果.我也尝试使整个命令成为一个字符串(而不是列表),但这也没有帮助.
'/path/to/casperjs /path/to/doSomething.js args'在shell中运行时,Running 返回退出代码0.
我也加入PATH=/usr/bin:/bin:/sbin:/usr/local/bin了我的crontab无济于事.(如本问题所示.)
任何想法为什么我只在cron中得到这个错误?谢谢!!
编辑:按照下面的答案,制定shell=False和stderr=subprocess.STDOUT作出的一切工作...
感谢您阅读我的主题,如果有人能提出我应该探索的任何其他途径来实现以下目标,我将非常感激.
使用CasperJS或PhantomJS我需要禁用属于我执行的导航页面的所有JavaScript,同时仍然可以使用casper.execute运行我自己的JavaScript.
有谁知道我可以这样做的方式?
感谢您的帮助 - 我很欣赏这是一个奇怪的用例.
出于某种原因,当我尝试运行以下代码时:
var casper = require('casper').create();
var x = require('casper').selectXPath;
var links = [];
casper.start('http://www.website.com');
function getLinks() {
var links = document.querySelectorAll(x('//*[@id="horizontalList"]/li[@class="paddingRight6"]/a');
return Array.prototype.map.call(links, function(e) {
return e.getAttribute('href')
});
}
casper.then(function() {
links = this.evaluate(getLinks);
this.echo(links);
}
casper.run();
Run Code Online (Sandbox Code Playgroud)
返回一个null对象,但是当我使用与thenClick方法相同的xpath选择器时,一切正常并且url会更改.为什么到底是这样的?
文档并没有真正有用 - 太简短和模糊.正如我从文档中所理解的那样,我们只需要在测试目录上运行casperjs命令并确保每个测试都以Tester.done().这是我的两个测试,
//test1.js
var casper = require('casper').create();
var urlPrefix = "http://localhost/NavHawk2/";
casper.start(urlPrefix , function() {
this.test.assertSelectorHasText('title', 'Login', 'Title Ok! Login Page Expected');
this.test.assertExists('form[action$="/login"]', 'Login Form is found');
this.fill('form[action$="/login"]', {
.....
}, true);
});
casper.run(function() {
this.test.done(2);
});
//test2.js
var blinkingCircleImg = "7.gif"
casper.on('page.error', function(){
console.log("SOme Javascript error persists!");
});
casper.then(function(){
this.test.assertSelectorHasText('title', 'Map', 'Login Ok! Map Page Expected');
this.test.assertExists('img[src$="' + blinkingCircleImg + '"]', 'Blinking Circle being shown!');
this.test.assetNotVisible('#sidebar_content_geofences', 'Geofencing sidebar not being shown!');
});
casper.run(function() { …Run Code Online (Sandbox Code Playgroud) 我希望能够有一组Casper JS测试,并在成功时获得退出代码0,在错误或测试失败时获得非零(我想从java运行casper命令并确定测试是否通过).
我遇到的问题是始终返回退出代码0.以下是发生这种情况的示例测试:
var casper = require('casper').create();
casper.start('http://www.google.com', function() {
this.test.assertEquals(true, casper.cli.options['value']);
});
casper.run(function() {
casper.test.done(1);
});
Run Code Online (Sandbox Code Playgroud)
以下所有命令都会导致退出代码为0:
C:/casperjs/bin/casperjs test --value=true C:/Temp/simpletest.js
C:/casperjs/bin/casperjs test --value=false C:/Temp/simpletest.js
C:/casperjs/bin/casperjs --value=true C:/Temp/simpletest.js
C:/casperjs/bin/casperjs --value=false C:/Temp/simpletest.js
Run Code Online (Sandbox Code Playgroud)
如何调用Casper并确定测试是成功还是失败/错误?
我正在尝试使用CasperJS构建功能测试. caseperjs由后端测试套件使用以下命令运行:
PHANTOMJS_EXECUTABLE=../client/node_modules/phantomjs/bin/phantomjs ../client/ext_modules/casperjs/bin/casperjs test ../client/test/functional/init.coffee
Run Code Online (Sandbox Code Playgroud)
在init.coffee中,我想导入/包含其旁边就位的其他模块(文件).怎么做?
以下不起作用:
require("user")
Run Code Online (Sandbox Code Playgroud)
我想要的是将其他文件中的内容导入init.coffee
我正在尝试使用CasperJS将图像上传到网络表单.
我的表单看起来像这样:
<form action="" method="POST" enctype="multipart/form-data" class="form-vertical">
...
<legend>Campaign Banner</legend>
<div class="control-group image-field ">
<label class="control-label">Now Large</label>
<div class="controls">
<div class="file-field"><input id="id_now_large_image" name="now_large_image" type="file"></div>
<div class="image-preview"></div>
<div class="clear"></div>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group image-field ">
<label class="control-label">Now Medium</label>
<div class="controls">
<div class="file-field"><input id="id_now_medium_image" name="now_medium_image" type="file"></div>
<div class="image-preview"></div>
<div class="clear"></div>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group image-field ">
<label class="control-label">Now Small</label>
<div class="controls">
<div class="file-field"><input id="id_thumbnail_image" name="thumbnail_image" type="file"></div>
<div class="image-preview now-small"></div>
<div class="clear"></div>
<span class="help-inline"></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
提交按钮如下所示:
<div class="form-actions"> …Run Code Online (Sandbox Code Playgroud) 我使用的是CapserJS 1.1.0-beta3和PhantomJS 1.8.2.
我调用一个响应重定向的URL(HTTP 302).PhantomJS自动跟随重定向,但在我的用例中,PhantomJS不应该遵循重定向.
重定向的调试输出如下所示:
[debug] [phantom] Navigation requested: url=https://foo.com/bar.jsp, type=Other, willNavigate=true, isMainFrame=true
Run Code Online (Sandbox Code Playgroud)
如何配置PhantomJS/CapserJS不遵循重定向?
我用CasperJS编写了一个web抓取脚本,它在Mac OS 10.10.4上完美运行,CasperJS版本1.1.0-beta3和PhantomJS版本1.9.8,但当我在我的一台服务器上放置相同的脚本时,就是Ubuntu 14.04(在具有相同环境(CasperJS和PhantomJS所有相同版本)的Docker容器内运行时,它突然输出:
我是`fs`模块
这很奇怪.我的一个建议是,在这个脚本中我也试图要求其他一些需要的脚本:
var parsingStrategy = require(strategiesPath + strategyName);
Run Code Online (Sandbox Code Playgroud)
并且这些策略的路径是正确的我已经检查过了.我在这个脚本中所做的所有其他事情都只是正常的CasperJS内容,我认为这些内容已经记录并且运行良好.
我正在尝试用Slimerjs运行Casperjs
在Centos 6.8上运行
当试图从php运行casperjs + slimerjs我得到:
Gecko error: it seems /usr/bin/firefox is not compatible with SlimerJS.
See Gecko version compatibility. If version is correct, launch slimerjs
with --debug=true to see Firefox error message
Run Code Online (Sandbox Code Playgroud)
当我尝试使用debug = true从控制台运行脚本时:(
/usr/local/bin/casperjs /tmp/casperjs-5cn484 --debug=true --engine=slimerjs
我也试过xvfb-run)
我收到此错误:
Xlib: extension "RANDR" missing on display ":99".
process 5588: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to …Run Code Online (Sandbox Code Playgroud) casperjs ×10
phantomjs ×6
javascript ×4
centos ×1
coffeescript ×1
crontab ×1
fs ×1
html ×1
http ×1
linux ×1
module ×1
python ×1
require ×1
slimerjs ×1
subprocess ×1
web-scraping ×1
xpath ×1
xvfb ×1