Snippet for taking screenshot on Test Failure
afterEach(function() {
var spec = jasmine.getEnv().currentSpec;
var passed = spec.results().passed();
if (!passed) {
browser.takeScreenshot().then(function(png) {
writeScreenShot(png, "screenshot.png");
});
}
function writeScreenShot(data, filename) {
var stream = fs.createWriteStream(filename);
stream.write(new Buffer(data, 'base64'));
stream.end();
}
});
Console error
Message:
Failed: Cannot read property 'results' of undefined
Stack:
TypeError: Cannot read property 'results' of undefined
at Object.<anonymous>
it returns undefined here,
var spec = jasmine.getEnv().currentSpec;
console.log(spec);
Looks like issues due to Jasmine 2; any alternate solutions also welcome! I use Jasmine 2
As of Jasmine 2.0, env.currentSpec is no longer supported.
https://github.com/jasmine/jasmine/issues/1212
"var spec" is not being set to anything. That means "jasmine.getEnv().currentSpec" is not working for whatever reason.
Related
I wanted to replace /\r?\n|\r/g with empty string but got a type error "Cannot read property 'replace' of undefined".
export function getCupsCredentials() {
var vcap_services = process.env.VCAP_SERVICES;
var vcap_servces_as_single_line = vcap_services.replace(/\r?\n|\r/g, " ");
var vcap_servces_as_json = JSON.parse(vcap_servces_as_single_line)
var vcap_servces_user_provided = vcap_servces_as_json['user-provided']
var cups_credentials = vcap_servces_user_provided[0].credentials;
return cups_credentials;
}
i got the following error message on using .replace
TypeError: Cannot read property 'replace' of undefined
at getCupsCredentials (/app/ui/dist/webpack:/src/utils/VcapUtils.js:4:50)
at Object.defineProperty.value (/app/ui/dist/webpack:/src/utils/IAMUtils.js:5:17)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b700ecf31:19:1)
at Object.defineProperty.value (/app/ui/dist/webpack:/src/api/middleware/filters/authFilter.js:1:1)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b700ece831:19:1)
at Object.<anonymous> (/app/ui/dist/webpack:/src/api/middleware/pre.js:1:1)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b70031:19:1)
at Object.defineProperty.value (/app/ui/dist/webpack:/src/api/middleware/index.js:1:1)
at __webpack_require__ (/app/ui/dist/webpack:/webpack/bootstrap 713b700ececf31:19:1)
at Object.canUseDOM (/app/ui/dist/webpack:/src/server.js:4:1)
Starting Conductor UI
using Conductor API server from 'http://chand-wf-nfce-server.cloud.pcftest.com/api'
/app/ui/dist/webpack:/src/utils/VcapUtils.js:4
var vcap_servces_as_single_line = vcap_services.replace(/\r?\n|\r/g, " ");
If these values are getting fetched from a remote server then the case might be that you are trying to replace the characters before the data is assigned to the variable. Try using await functions or the .then() And also replace as such var vcap_servces_as_single_line = vcap_services?.replace(/\r?\n|\r/g, " ");
So that the code will not scream at you if you have an undefined value.
The most probable cause is that your process.env.VCAP_SERVICES is not initialized properly and it is initializing your vcap_services with undefined. As the replace method does not work with undefined thus that error.
Try checking if vcap_services is empty or not by the ternary operator
export function getCupsCredentials() {
var vcap_services = process.env.VCAP_SERVICES;
var vcap_servces_as_single_line = vcap_services
? vcap_services.replace(/\r?\n|\r/g, " ")
: "vcap_servisec is empty";
console.log(vcap_services);
/*
var vcap_servces_as_json = JSON.parse(vcap_servces_as_single_line)
var vcap_servces_user_provided = vcap_servces_as_json['user-provided']
var cups_credentials = vcap_servces_user_provided[0].credentials;
return cups_credentials;
*/
}
I use this"https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/hid " The following error occurred
Uncaught TypeError: Cannot read property 'getDevices' of undefined
at enumerateDevices (control-panel.js:55)
at initializeWindow (control-panel.js:42)
Is the chrome version a new issue? How do I modify it to use the new chrome?
var enumerateDevices = function() {
chrome.hid.getDevices({}, onDevicesEnumerated);
chrome.hid.onDeviceAdded.addListener(onDeviceAdded);
chrome.hid.onDeviceRemoved.addListener(onDeviceRemoved);
};
I keep getting this error Failed with: TypeError: Cannot read property 'success' of undefined which i cannot figure out the problem
Parse.Cloud.httpRequest(
{
url:url,
success:function(httpResponse)
{
var Day = Parse.Object.extend("TestDay");
var queryToday = new Parse.Query(Day);
queryToday.equalTo("dayday", day);
queryToday.equalTo("daymonth", month);
queryToday.equalTo("dayyear", year);
queryToday.equalTo("owner", theUser);
queryToday.first().then(function(dayObject) <---line 662
{
if(dayObject == undefined)
{
console.log("not found");
}
else
{
console.log(dayObject);
}
}, function(error)
{
console.log("first failed");
});
}
});
Failed with: TypeError: Cannot read property 'success' of undefined
at Object.b.Query.first (Parse.js:1:57000)
at Object.Parse.Cloud.httpRequest.success (main.js:662:48)
How do you know that's the line? I mean, are you on web using the console?
Is there something else to know? Like are you working on a cloud function?
My guess is that returning dayObject.save(); doesn't work. Try using a console.log(dayObject) to know exactly the query's response. It may happens that you'll have to use a conditional as follows:
if(dayObject == undefined){
return Parse.Promise.error("Not Found");
}else{
dayObject.increment("totalnumberofphotos");
return dayObject.save();
}
I have found the answer to my question. it is because the parse sdk on cloud is too low version, so i have to update it to the latest one and it works now. thank you very much
How can I get more error details from a javascript catch?
Are there more parameters to get more details from the caught error.
try {
var s = null;
var t = s.toString();
} catch(err) {
alert(err);
}
The Error Object has several properties that you can use. One property you can use to get the message of the error, is .message, as in:
catch(err) {
alert(err.message);
}
The .name property returns the type of error as in:
catch(err) {
x = err.name;
// ... do something based on value of x
}
The name describes the type of error, and the value of .name can be : EvalError, RangeError, ReferenceError, SyntaxError, TypeError , and URIError. You may decide to handle the error differently depending on the error type which is returned by the .name property.
A good tutorial can be found on JavaScriptKit. The is also an article on the error object at Mozilla Developer Network.
Check this link out:
Reference to Error.prototype
Basically you have err.name and err.message.
You also have a few vendor-specific extensions:
Microsoft => err.description and err.number.
Mozilla => err.fileName, err.lineNumber and err.stack.
function message()
{
try
{
}
catch(err)
{
alert(err.message);
}
}
SEE HERE and HERE
I'm trying to figure out how to correctly use JS Test Driver's assertException method. From google's documentation it should be: assertException([msg], callback, error). However, no matter what I do, I always get an [ERROR] for this test (instead of a [PASS] since there was an exception):
ComponentTest.prototype.testEnforceUniqueComponentIds = function() {
assertException(function(){
this.component = new myNamespace.component(this.testComponentSettings);
});
}
And in my src JS:
myNamespace.component = function(params){
if (typeof params.selector == 'undefined'){
throw new Error('no selector provided');
}
this.settings = jQuery.extend({}, {
id : 'defaultComponentId',
type : 'defaultComponentType',
selector : 'body',
isUnique : false
}, params);
if(typeof(myNamespace.componentRegistry[params.id]) === "undefined"){
myNamespace.registerComponent(this);
} else {
throw new Error('non-unique component id provided');
}
}
Here is the output from js-test-driver:
C:\xampp2\htdocs\myNamespace\v2>java -jar JsTestDriver.jar --tests all --verbose
[PASSED] ComponentTest.testInit
[LOG] setUp
[LOG] tearDown
[PASSED] ComponentTest.testDestroy
[LOG] setUp
[LOG] tearDown
[ERROR] ComponentTest.testEnforceUniqueComponentIds
[LOG] setUp
Total 3 tests (Passed: 2; Fails: 0; Errors: 1) (1.00 ms)
Firefox 7.0.1: Run 3 tests (Passed: 2; Fails: 0; Errors 1) (1.00 ms)
ComponentTest.testEnforceUniqueComponentIds error (1.00 ms):
For the life of me, I can't figure out how to have the code within the assertException callback actually throw an exception without it causing an ERROR in the test - isn't this what is supposed to happen?
Any help would be appreciated.
assertException(function(){
this.component = new myNamespace.component(this.testComponentSettings);
}, "Error");
error argument should be Error.name of thrown error(such as "ReferenceError", "TypeError", etc.).