CasperJS require('utils').dump(this.logs) is undefined - casperjs

I'm writing a CasperJS script and would like to dump the entire contents of what has been written to the logs since execution start. In the casperjs documentation, it says,
You can also dump a JSON log of your Casper suite just by rendering the contents of the Casper.logs property
Unfortunately, when I use the example code from the documentation, am getting 'undefined' from the casper.logs value. Here is sample code:
casper = require('casper').create({
verbose: true,
logLevel: 'info'
});
casper.start();
casper.thenOpen('http://casperjs.org', function() {
this.log("this is a log", 'info');
this.log(this.getTitle(), 'info');
});
casper.thenOpen('http://phantomjs.org', function() {
this.log(this.getTitle(), 'info');
require('utils').dump(this.logs);
});
casper.run(function() {
this.exit();
});
And here is the output of this code:
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[info] [phantom] Step anonymous 2/4 http://casperjs.org/ (HTTP 200)
[info] [phantom] this is a log
[info] [phantom] CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS
[info] [phantom] Step anonymous 2/4: done in 913ms.
[info] [phantom] Step anonymous 4/4 http://phantomjs.org/ (HTTP 200)
[info] [phantom] PhantomJS | PhantomJS
undefined
[info] [phantom] Step anonymous 4/4: done in 1340ms.
[info] [phantom] Done 4 steps in 1359ms

According to the code you should use:
require('utils').dump(this.result.log);
There is no such thing as this.logs anymore.
Since this is not really documented, it may change in future versions. I suggest you either register to the log event or use this.echo.

Related

Failed screenshot in Mochawesome Report in case of Test Retry

I am using addContext() that mocha provides to append failure screenshots in the Mochawesome html report. I have written this under support/index.js
Cypress.on('test:after:run', (test, runnable) => {
if (test.state === 'failed') {
const screenshot = `FailureScreenshots/${Cypress.spec.name
}/${runnable.parent.title} -- ${test.title} (failed).png`;
addContext({ test }, screenshot);
}
});
This works perfectly when there is a failure(and there are no Test Retries) it just appends the failure screenshot in the html report bases on test.state. However, in case of Test Retries, where on the first run the test failed but on the second run the test passed, it still attaches the failure screenshot. How can I prevent that? It should only append the screenshot when the test finally fails after the number of retries have been exhausted.

Magento Grunt child theme compilation fails to update merged style files

I've set up the Grunt workflow as described here:
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/css-topics/css_debug.html
My local-themes.js looks like this:
➜ m2 git:(master) ✗ cat dev/tools/grunt/configs/local-themes.js
'use strict';
module.exports = {
ac_default: {
area: 'frontend',
name: 'Ac/Default',
locale: 'en_US',
files: [
'css/source/_extend',
],
dsl: 'less'
},
ac_retail: {
area: 'frontend',
name: 'Ac/Retail',
locale: 'en_US',
files: [
'css/source/_extend',
],
dsl: 'less'
},
ac_wholesale: {
area: 'frontend',
name: 'Ac/Wholesale',
locale: 'en_US',
files: [
'css/source/_extend',
],
dsl: 'less'
}
};
I grunt watch successfully triggers when a less file in my child theme gets changed:
➜ m2 git:(master) ✗ grunt watch:ac_retail -v
Initializing
Command-line options: --verbose, --gruntfile=/data/src/m2/Gruntfile.js
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ black-list-generator, clean-black-list, default, deploy, documentation, legacy-build, mage-minify, prod, refresh, spec, static
Running tasks: watch:ac_retail
Loading "grunt-contrib-watch" plugin
Registering "/data/src/m2/node_modules/grunt-contrib-watch/tasks" tasks.
Loading "watch.js" tasks...OK
+ watch
Running "watch:ac_retail" (watch) task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.ac_retail.files exists in config...OK
Live reload server started on *:35729
Watching pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less for changes.
>> File "pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less" changed.
Initializing
Command-line options: --verbose, --gruntfile=/data/src/m2/Gruntfile.js
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ black-list-generator, clean-black-list, default, deploy, documentation, legacy-build, mage-minify, prod, refresh, spec, static
Running tasks: less:ac_retail
Loading "grunt-contrib-less" plugin
Registering "/data/src/m2/node_modules/grunt-contrib-less/tasks" tasks.
Loading "less.js" tasks...OK
+ less
Running "less:ac_retail" (less) task
Verifying property less.ac_retail exists in config...OK
Files: pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less -> pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css
Options: banner="", sourceMap, strictImports=false, sourceMapRootpath="/", dumpLineNumbers=false, ieCompat=false
Reading pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less...OK
Writing pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css.map...OK
File pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css.map created.
Writing pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css...OK
File pub/static/frontend/Ac/Retail/en_US/css/source/_extend.css created
>> 1 stylesheet created.
>> 1 sourcemap created.
Done.
Execution Time (2019-01-16 16:13:35 UTC-8)
loading tasks 42ms ▇▇▇▇▇▇▇▇▇▇▇▇▇ 39%
loading grunt-contrib-less 34ms ▇▇▇▇▇▇▇▇▇▇ 32%
less:ac_retail 31ms ▇▇▇▇▇▇▇▇▇ 29%
Total 107ms
Live reloading pub/static/frontend/Ac/Retail/en_US/css/source/_extend.less...
Completed in 0.729s at Wed Jan 16 2019 16:13:35 GMT-0800 (Pacific Standard Time) - Waiting...
Unfortunately the styles-m.css or styles-l.css files are not updated. Therefore when I refresh the page the changes made in the less files are not reflected on the page.
I posted a ticket in the Magento bug tracker but they have not been particularly helpful.
https://github.com/magento/magento2/issues/20356
My question is. Does anyone here uses Grunt to compile less for a setup with multiple child themes?
In my case the intended theme inheritance looks like this:
ac_retail inherits from ac_default inherits from luma
ac_wholesale inherits from ac_default inherits from luma
From what I can tell the Grunt workflow is the only workflow that is actually suitable for theme development. Server and client side compilation are way too slow to use for development.
Finally figured it out. The documentation has errors. You need to specify the parent themes style files, even if your child theme has it's own root source files, if you want to re-compile styles-m.css and styles-l.css, when the child themes less files change. This local-themes.js ended up working for me:
>>'use strict';
>>module.exports = {
ac_default: {
area: 'frontend',
name: 'Ac/Default',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
],
dsl: 'less'
},
ac_retail: {
area: 'frontend',
name: 'Ac/Retail',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
],
dsl: 'less'
},
ac_wholesale: {
area: 'frontend',
name: 'Ac/Wholesale',
locale: 'en_US',
files: [
'css/styles-m',
'css/styles-l',
],
dsl: 'less'
}
};
adding
'css/styles-m',
'css/styles-l',
fixed it for me too. Thanks for this

Unable to print the locator (webelement) in Console Log

I'm new to Protractor.
I'm declaring an element as a variable like :
txtSearch : element(by.xpath('//input[#type="search"]')),
In some point I want to log the locator as :
var clickOn = function(webElement)
{
webElement.click();
console.log("Successfully clicked on the " + webElement);
};
I'm calling this function from Spec file like - clickOn (txtSearch)
In Console.log I am getting like - Successfully clicked on the [object Object].
Please find the required details below :
Node Version: 7.5.0
Protractor Version: 5.1.1
Browser(s): Chrome
Protractor configuration file :
exports.config = {
capabilities: {
browserName: 'chrome',
},
onPrepare: function(){
jasmine.getEnv().addReporter(reporter);
global.isAngularSite = function(flag) {
browser.ignoreSynchronization = !flag;
};
browser.manage().timeouts().setScriptTimeout(60000);
browser.driver.manage().window().maximize();
},
seleniumServerJar: '../../protractor/selenium/selenium-server-standalone-2.52.0.jar',
chromeDriver: '../../protractor/selenium/chromedriver_2.27.exe',
directConnect: true,
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../PoC_Protractor/spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 600000,
isVerbose: true
}
I tried with webElement.locator().toString() but it is throwing-
Failed: webElement.locator is not a function
You can always output the locator used using webElement.locator().toString(). Check the output for the below code snipper.
Protractor spec:
describe('Locator testing by model', function(){
it('automate user register form', function(){
browser.get('http://www.way2automation.com/angularjs-protractor/registeration/#/login');
var search = element(by.model('Auth.user.name'))
console.log(search.locator())
console.log("Successfully clicked on the " + search.locator().toString());
console.log(search.locator().toString())
});
});
Output:
[14:01:48] I/local - Starting selenium standalone server...
[14:01:48] I/launcher - Running 1 instances of WebDriver
[14:01:49] I/local - Selenium standalone server started at http://10.96.61.119:56341/wd/hub
Started
{ findElementsOverride: [Function], toString: [Function] }
Successfully clicked on the by.model("Auth.user.name")
by.model("Auth.user.name")
.
1 spec, 0 failures
Finished in 0.942 seconds
[14:01:53] I/local - Shutting down selenium standalone server.
[14:01:53] I/launcher - 0 instance(s) of WebDriver still running
[14:01:53] I/launcher - internet explorer #01 passed
Hey it seems like you may not be resolving the promise in the correct way, try using -
webElement.click().then(function(element){
console.log(""Successfully clicked on the " + element);
};

how to switching off stack failure message?

While running a test suit, when something fails it also show the stack message like this
Failures:
1) Should validate labels
Message:
Failed: No element found using locator: By.cssSelector(".container h1")
Stack:
NoSuchElementError: No element found .........................
.........
......
....
can we switch off this stack output? I have tried
protractor conf.js --no-stackTrace
also updated conf.js file with settings
stackTrace: false,
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000,
includeStackTrace: false,
}
but its always showing stack output, how to fix it?
If you are using and old protractor (<=1.4 I think), setting both isVerbose and includeStackTrace to false would work for you:
jasmineNodeOpts: {
isVerbose: false,
includeStackTrace: false
}
Unfortunately, nowadays isVerbose or includeStackTrace would not be recognized in jasmineNodeOpts (explanation here):
Similar to jasmine 1.3, you may include jasmineNodeOpts in the config
file. However, because we changed the runner from
"https://github.com/juliemr/minijasminenode" to
"https://github.com/jasmine/jasmine-npm", the options have changed
slightly. Notably options print and grep are new, but we will no
longer support options isVerbose and includeStackTrace (unless, of
course, "jasmine-npm" introduces these options).
See also:
isVerbose has no effect
An elegant solution that I found was located on the protractor github at https://github.com/bcaudan/jasmine-spec-reporter/blob/master/docs/protractor-configuration.md
You can modify your jasmineNodeOpts like so
jasmineNodeOpts: {
...
print: function() {}
}
And that took care of the problem for me
I was successfully able to disable the Stacktraces in my test suite using the following setup in my "conf.js" file:
...
framework: 'jasmine',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
// If true, display spec names.
isVerbose : false,
// Use colors in the command line report.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace : false,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 60000,
// If true, print timestamps for failures
showTiming: true,
// Print failures in real time.
realtimeFailure: true
}
...
I found this GitHub issue (https://github.com/angular/protractor/issues/696) useful with this question. Setting both the "isVerbose" and "includeStackTrace" flags to 'false' worked for me.
includeStackTrace was removed in https://github.com/angular/protractor/commit/bf5b076cb8897d844c25baa91c263a12c61e3ab3
so the previous answers did not work for me.
The jasmine-spec-reporter has changed and no longer has a protractor-configuration.md file, so that advice no longer worked for me either.
However, despite the lack of a protractor-configuration.md file, I did find that jasmine-spec-reporter had the working solution for me.
I found that using the jasmine-spec-reporter in this way with Protractor 5.2.0 in my config file:
setup = function() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.TerminalReporter({
verbosity: 3,
color: true,
showStack: false }));
}
exports.config = {
onPrepare: setup
};
The key was to change the stackTrace parameter to false in the TerminalReporter

How to get filename of the test in mocha reporter

Is there a way to get the filename of current test in mocha reporter?
I couldn't find anything in the base and examples.
Actually, file name is passed to Suite in file field in mocha starting from this pull request. It's just nowadays mocha most commonly is ran as a karma plugin (namely, karma-mocha plugin), and, talking of December'14, this plugin just does not pass file name information further.
To make this answer self-consistent, here's how Suite is formed in mocha (it's tdd implementation, but it it is similar for bdd):
context.suite = function(title, fn){
var suite = Suite.create(suites[0], title);
suite.file = file;
suites.unshift(suite);
fn.call(suite);
suites.shift();
return suite;
};
And here's how suits are formed in karma-mocha/lib/adapter.js:
runner.on('test end', function(test) {
var skipped = test.pending === true;
var result = {
id: '',
description: test.title,
suite: [],
success: test.state === 'passed',
skipped: skipped,
time: skipped ? 0 : test.duration,
log: test.$errors || []
};
var pointer = test.parent;
while (!pointer.root) {
result.suite.unshift(pointer.title);
pointer = pointer.parent;
}
tc.result(result);
});
But you know what, I guess this is a nice thing to issue as a feature request in karma-mocha project.

Resources