How can I change FAIL output details at casperjs test? - casperjs

I would like to make some changes at the message of output FAIL test.
For example:
Hide type and file parameters;
Rename subject and expected parameters;
I tried to use casper.test.on('fail', function (failure) { casper.test.comment("mylabel: " + failure.values.subject);}) to output my message and it worked, but the default parameters were not hidden.
Some idea?

Related

inspec - i want to output structured data to be parsed by another function

I have a inspec test, this is great:
inspec exec scratchpad/profiles/forum_profile --reporter yaml
Trouble is I want to run this in a script and output this to an array
I cannot find the documentation that indicated what method i need to use to simulate the same
I do this
def my_func
http_checker = Inspec::Runner.new()
http_checker.add_target('scratchpad/profiles/forum_profile')
http_checker.run
puts http_checker.report
So the report method seems to give me load of the equivalent type and much more - does anyone have any documentation or advice on returning the same output as the --reporter yaml type response but in a script? I want to parse the response so I can share output with another function
I've never touched inspec, so take the following with a grain of salt, but according to https://github.com/inspec/inspec/blob/master/lib/inspec/runner.rb#L140, you can provide reporter option while instantiating the runner. Looking at https://github.com/inspec/inspec/blob/master/lib/inspec/reporters.rb#L11 I think it should be smth. like ["yaml", {}]. So, could you please try
# ...
http_checker = Inspec::Runner.new(reporter: ["yaml", {}])
# ...
(chances are it will give you the desired output)

Properties in JMeter for GUI and CMD

I have a JMeter script, where I have some user defined Variables like FILE_SAVE_PATH. This script should be started on a command line with parameter -J. So in the GUI, I changed the value for the variable FILE_SAVE_PATH to ${__P(FILE_SAVE_PATH, "C:\svn\trunk\dir")}, because the test should save there a file, but only on my machine. On the machine, where the script will be started from command line, it should save the file into another path.
My problem is now this: When I test this JMeter script on my machine in the GUI, I get an output of this:
About to replace in property of type: class org.apache.jmeter.testelement.property.StringProperty: ${__P(FILE_SAVE_PATH, "C:\svn\trunk\dir")}
2017/04/04 17:09:38 DEBUG - jmeter.testelement.property.AbstractProperty: Not running version, return raw function string
2017/04/04 17:09:38 DEBUG - jmeter.engine.util.ValueReplacer: Replacement result: ${__P(FILE_SAVE_PATH, "C:\svn\trunk\dir")}
But I think, the last line should be something like this:
2017/04/04 17:09:38 DEBUG - jmeter.engine.util.ValueReplacer: Replacement result: "C:\svn\trunk\dir"
So, how to change the test to get the result I want?
Escape every backslash with another one - C:\\svn\\trunk\\dir, or use unix slash, JVM's gonna handle it right: C:/svn/trunk/dir
And remove the doublequotes, they're not needed.
P.S. I presumed you're not using that notation in the Beanshell/JSR223 context. If you do - stop there and use the legit way to access properties.

Laravel - call Artisan command and wait for the result

I'm trying to call in a controller a very time-consuming Artisan command (it executes in 20-90 s ), but I have two problems. First of all it seems like the command does not execute at all (if I return the output it just returns "0").
Secondly the other part (returning the file) does not wait for the command to execute (but it can be related to the first part). Here's my code:
public function returnZip()
{
// just a failsafe, in case if scheduled command did not created the file yet
if( ! file_exists( storage_path( '/app/exports/' . date('Y_m_d') . '.zip' ) ) ){
Artisan::call('maximus:export');
}
return response()->file( storage_path( '/app/exports/' . date('Y_m_d') . '.zip' ) );
}
How can I properly execute the Artisan command from route/controller and wait for it to finish it's task?
EDIT
I tried to debug this problem a little more and found out that the command is not being executed at all when called from a route/controller.
Tried this:
Route::get('/test', function(){
Artisan::call('maximus:export');
return ['ok'];
});
And my command is supposed to create a file:
public function handle()
{
exec('touch /some/path/storage/app/exports/test');
}
When I run this command in terminal, the file is being created, but when I hit the route, it isn't. Any ideas?
Okay, I fired up Laravel and tested it. My command is:
public function handle()
{
exec('touch ' . storage_path(str_random(16) . '.txt'));
}
It works perfectly both in terminal and in a route by calling Artisan::call().
A wild guess: does the www-data user (or whatever user the PHP used by your webserver is running as) have sufficient privilege to write the file?
I'm pretty sure that the artisan command is being handled asynchronously, so it isn't going to wait for the command to finish. Therefore your response is likely to be empty/malformed.
You may want to look into Events and Listeners to ensuring your order of operations is correct (https://laravel.com/docs/5.4/events).
For example, in your maximus:export command you could fire an event immediately after the file has been created.
Example:
Create an event called ZipCreated and a listener called SendZip. Then in your artisan command handler call the event:
event(new ZipCreated($file));
Then link it to a listener in your EventServiceProvider.php:
protected $listen = [
Events\Repository\ZipCreated::class => [
Listeners\Repository\SendZip::class,
],
];
This way ZipCreated will provide SendZip with the zipped file (or a filepath if you want) and SendZip can handle returning the file to the user.
Now whenever the command is run, the creation of the file and the handling of response will always happen in the correct order.
if I return the output it just returns "0"
Let me point out just in case that the call method doesn't return the output of the command, but its exit code ("0" meaning success). Instead, Artisan::output() will return the output.
I'd say check the logs to see what's going on, also check you are in fact useing the Artisan facade. Otherwise, try a debugger or alternatively insert informative dd() statements ;) (the entry point being Illuminate\Foundation\Console\Kernel::call).
try this:
dd(Artisan::output());

Passing property to custom gradle task from command prompt

I wrote a custom gradle task class (say PrintNameTask) that accepts some input parameter (say name).
Then if I define a printName task of type PrintNameTask like below:
task printName(type: PrintNameTask) {
name = project.name
}
and invoke it from command prompt like below I can see the passed name printed out
$gradle printName -Pname=myName
myName
However if I invoke any other task like clean or build the build fails because there is no property called name passed. This is fair enough as my printName is a configure closure and is evaluated all the times.
To address this I tried to change the configure closure into a task action closure like below:
task printName(type: PrintNameTask) << {
// What should I put on here?
name = ???
// or
name ???
}
But it was no way to make it work. I tried project.name, getProperty("name") and a few more other combinations but nothing worked. All I get back is:
* What went wrong:
A problem was found with the configuration of task ':printName'.
No value has been specified for property 'name'.
This kind of requirement looks to me quite basic and it is a bit frustrating that tons of books and documentation are published but they only shows trivial examples. Maybe is just me but at the point of asking this question my initial gradle enthusiasm is more than half gone. Anyway thank you in advance for your inputs.
Configure the task in the following way:
task printName(type: PrintNameTask) {
name = project.hasProperty('name') ? project.name : '' // or null
}
Since this closure is evaluated at configuration phase it's executed every time the script is processed. You just need to check if the property is present.

How to see what Protractor tests is currently executing?

In my Protractor test script, I use the usual notation:
describe("mytest") {
...
it(" should do this") {
...
it(" should do that") {
I would like to be able to see what test and what part of each is currently running when I run them. Is there any option I can use to output test descriptions to the console?
There is a reporter that should do what you are looking for. Take a look at https://www.npmjs.com/package/jasmine-spec-reporter and https://github.com/bcaudan/jasmine-spec-reporter/tree/master/examples/protractor
You can use the --verbose option to print more information about your tests, but it will not tell you which test is currently being run.
I suggest you to create an issue if you want that feature. https://github.com/angular/protractor/issues/new
$ ./node_modules/protractor/bin/protractor protractor-config.js --verbose
------------------------------------
PID: 7985 (capability: chrome #1)
------------------------------------
Using the selenium server at http://localhost:4444/wd/hub
angularjs homepage
should greet the named user
todo list
should list todos
should add a todo
Finished in 5.915 seconds
3 tests, 5 assertions, 0 failures
since protractor runs in node you can use console.log as you normally would in javascript, for more console fun see the node docs
I like to place any logs after functionality so that I know its been completed, so wrapping it inside of a .then() function seemed to work best for me
example:
element(elementToFind).click().then(function(){
console.log("clicked element");
continue();
});
If you need to know the name of the spec currently rinning you could use: jasmine.getEnv().currentSpec.description
and log it
console.log('\nTest spec: ' + __filename + '\n');
to log the test but no idea how to log the it being executed

Resources