This question already has an answer here:
Karate framework retry until not working as expected
(1 answer)
Closed 1 year ago.
I have a scenario to conditional wait for every 5 secs for max 1 min. And I have implemented it via polling using java.lang.Thread.sleep(), which is blocking the Threads and failing in my multithread project. How can I use something like karate.pause() in my normal karate feature functions? Note: I can't use "retry until" in my case.
This is the method I use for polling with Thread.sleep(),
* def checkForEventCompletion =
"""
function(arg) {
var poolTime = 5;
var counter = 1;
// should pool for every 5 seconds until it exceeds your input wait time
while (true) {
if( (counter*poolTime) > arg.maxWaitTime){
karate.log('Status Not yet Updated');
return EventStatus;
}
//Code to Fetch EventStatus
karate.log('Current Status->',EventStatus);
if (EventStatus == 'COMPLETED') {
karate.log('Status Verified, --Exiting--');
return true;
}
// pool every 5 seconds
java.lang.Thread.sleep(poolTime*1000);
counter++;
}
}
When I try to use karate.pause(), it fails with "invokeMember (pause) on com.intuit.karate.core.ScenarioBridge#4acb7ecc failed due to: Unknown identifier: pause".
Most likely because you are using an old version of Karate and pause() is only in 1.1.0.
And I think you have confused a lot of things, pause() is only for performance-testing using Gatling: https://github.com/intuit/karate/issues/1622
If you are looking for testing async flows, please refer this: https://twitter.com/KarateDSL/status/1417023536082812935
The above example gives you an way to "wait" or poll for something. An alternate way is this: https://stackoverflow.com/a/55823180/143475
Else - your question does not make sense, so please provide more info after following this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
And you can find an example of someone doing this here: https://github.com/intuit/karate/issues/1681
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a node.js command line tool that I'd like to run in order to generate an asset in response to an HTTP Request that I receive in Vapor 4. Is it possible to do this?
I guess it is something like this
func requestHandler(_ req: Request) throws -> EventLoopFuture<HTTPStatus> {
let promise = req.eventLoop.makePromise(of: HTTPStatus.self)
let process = Process()
// e.g. use `which node` to find path to `node`
process.executableURL = URL(fileURLWithPath: "/path/to/binary") // e.g. /usr/bin/node
// in which folder execute the command, it is optional
process.currentDirectoryPath = "/path/to/folder"
// optional arguments, e.g. if your arguments are -c release then it should be ["-c", "release"]
process.arguments = ["arg1", "arg2", "argN"]
// wait for termination in closure
process.terminationHandler = { process in
switch process.terminationStatus {
// probably normal termination via SIGTERM or when process successfully finished
case 0:
promise.succeed(.ok)
default:
promise.fail(Abort(.failedDependency, reason: "Process finished with code \(process.terminationStatus)"))
}
}
// don't forget to launch it
try process.run()
return promise.futureResult
}
I've been looking into this for awhile now as I have created a client I would love to be able to run in a separate window (In a similar design to the Blizzard launcher or the old Ijji reactor). I was wondering if this was possible. Last week I created a web browser within Visual Basic but I was not happy with the final result at the bars where still stationed around the window. Any helpful tips or advice would be appreciated!
You didn't specify language, so you get it in c#. This might work. Starts chrome in app mode. here is the argument list
http://peter.sh/experiments/chromium-command-line-switches/
url = "--app=http://google.com";
Process[] pname = Process.GetProcessesByName("chrome");
if (pname.Length == 0)
{
chrome = false;
}
else // if chrome is running
{
if (!chrome)
{
Process process = new Process();
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = url;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
//Process.Start("chrome", url);
}
chrome = true;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I want to achieve below goals:
Read a MP3 metadata
Modify the encoding of that metadata (if I could modify the content of that metadata, that would be better)
Save the modification to that MP3 file
All these operations could be based on native Node.js (without browser). Is there any module provide such function or I can develop based on?
For those coming to this question through Google, there is a node module that can do this, both read and write metadata:
https://www.npmjs.org/package/ffmetadata
I don't know whether there's a way to actually do the meta data manipulation in NodeJS. This is a work around way but you could do this using child_process.exec and perl:
NodeJS Code
var exec = require('child_process').exec,
child;
child = exec('perl changeTags.pl file.mp3',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
Perl code
#!/usr/bin/perl
use MP3::Tag;
$mp3 = MP3::Tag->new(#ARGV[0]); # create object
$mp3->get_tags(); # read tags
print "Attempting to print tags for #ARGV[0]\n";
if (exists $mp3->{ID3v2}) {
print "Comments: " . $mp3->{ID3v2}->comment . "\n";
print "Zip: " . $mp3->{ID3v2}->album . "\n";
print "Tags: " . $mp3->{ID3v2}->title . "\n";
} else {
print "#ARGV[0] does not have ID3v2 tags\n";
}
$mp3->close(); # destroy object
Something like that. You'd obviously want to give more arguments for what you actually want to change the meta data to.... Good luck!
So far i found jsmediatags is best npm package to read ID3v2 tags
var jsmediatags = require("jsmediatags");
jsmediatags.read("./song.mp3", {
onSuccess: function(tag) {
console.log(tag);
},
onError: function(error) {
console.log(':(', error.type, error.info);
}
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Is there anything similar to Microsoft Powershell (an object-oriented shell built on the .NET framework) for Linux (possibly built on Java, GObject, or its own object type/nothing)?
edit: especially if similar to bash or powershell or cmd etc. syntax (=''standard'' shell syntax)
Python. No joking.
Scripting languages are scripting languages, and Python is a particularly nice one that many people find very approachable.
Even though this question is pretty old, I think its worth mentioning that in August 2016 Microsoft made Powershell open-source and cross platform. Instructions for installation are on github.
https://github.com/PowerShell/PowerShell
Perl, Python, and Ruby
Ok, I'm sure you already know that, but someone had to say it.
Perl is the oldest and most popular.
If you like objects, you will probably love Ruby. It has an elaborate object system inspired by Smalltalk.
Python has this cool block-structure-by-indent syntax.
Unix is a gold mine of advanced scripting tools...
Hotwire
NodeJS can do that, in fact it's one of the samples included in the download. Use it interactively, or (probably more usefully) write shell scripts in JavaScript.
For example:
#!/usr/local/bin/node
var sys = require('sys'),
exec = require('child_process').exec;
// Run `ls`:
exec('ls -lh /usr', function(error, output, erroutput) {
sys.print('output: ' + output);
sys.print('erroutput: ' + erroutput);
});
...but that's just the high-level interface that buffers all the output for you, etc. You can get a lot more down and dirty than that if you like.
NodeJS takes asynchronicity as the normal state of affairs, and so if you want a "traditional" shell script, you may find it's not a good match as it doesn't (as of this writing, as far as I know) offer a synchronous version of exec. So an ad hoc series of serial statements becomes an exercise in callbacks:
exec('first_command', function(error) {
if (error != null) {
exec('second_command', function(error) {
if (error != null) {
// ....
}
});
}
});
...but of course, you can create a function that handles that for you and takes (say) an array of sequential statements to execute (and then install it as a module via Node's module sysstem). So for instance:
#!/usr/local/bin/node
var sys = require('sys'),
exec = require('child_process').exec;
execSeries([
'ls -ld /usr',
'foobar',
'ls -ld /etc'
], {echo: true}, function(results) {
sys.print("Done\n");
});
// ===> This would be in a module, not in the script itself <===
function execSeries(series, options, callback) {
var index = 0,
results = [];
// Make 'options' optional
if (!callback && typeof options === "function") {
callback = options;
options = undefined;
}
// Default options
options = options || {};
// Go
callNext();
function callNext() {
if (index >= series.length) {
// Done
callback(results);
}
else {
// Call the next one
exec(series[index++], function(error, stdout, stderr) {
// Record result
results.push({error: error, stdout: stdout, stderr: stderr});
// Echo?
if (options.echo) {
if (error == null) {
sys.print(stdout);
}
else {
sys.print("Error: " + error + "\n");
}
}
// Stop on error?
if (options.breakOnError && error != null) {
// Yes, and there was an error; stop
callback(results);
}
else {
// No, continue
callNext();
}
});
}
}
}
You should rethink why it is you think you need an object-oriented shell. That said, if you're set trying weird shells you can't go wrong with zoid. Unlike many of the other suggestions I see here it really is a shell. On the other hand, if you don't know or don't like Perl you probably won't be happy.
jq is not quite an object-oriented shell, but it provides some of the benefits which object-oriented shells may have; I use it a lot, together with shell scripts, for such tasks.