How to retreive current test case name in nightwach [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I m working with balloon pop up which will invoke for currently running test case, I need to pass the current test case name to that balloon popup.I tried with browser.currentTest but it is returning [object, object]. Is there any other way of retrieving the current test case name,if so can someone help me in retrieving the current test case name. Thanks in advance.

Try
browser.currentTest.module
In nightwatch, you have access to the name of the currentTest using .module. It's not in the docs, it just came up by logging
var keys = Object.keys(client.currentTest)
to the console like:
console.log(keys)
from the base test class. Adding that to the prototype isn't even necessary as it's available in any test. "module" is a property of the Test object in Nightwatch.
Also note that, from experience, the seemingly inaptly named browser.currentTest.name is not what you want. It's an array of numbers whose purpose I have yet to deduce...

Related

How to use attr in elements within an array? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So, I have an array with 200 items called "icone", and when I use this code:
icone.attr('src', 'img/known.svg');
All items change according to what is in the code.
But how do I do if I want to change only 1 of the items in this array, and not all 200?
I tried with:
icone[0].attr('src', 'img/known.svg');
But the console returned "icone[0].attr is not a function".
Any ideas on how to make this work?
Thanks!
If it is absolutely necessary to use jQuery in this case. You can do this:
$(icone[0]).attr('src', 'img/known.svg');
In case it is not, you can do it as the other answers say.
Once you do icone[0], you're dealing with a raw node, not a jQuery "wrapper." That raw element does not have an .attr function.
As Ouroborus suggests, just set the attribute directly by doing icone[0].src = ....
(If Ouroborus submits an answer in addition to their comment, you should mark it as accepted, not this answer. I just wanted to explain why what you're doing doesn't work.)
EDIT: Interestingly, icone.first().attr(...) does work, because it does wrap the first element with a jQuery wrapper.

JavaScript binding of global result is undefined [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I looked below code in blog cause i wanna know about this.
When i copy & paste this code and then execute that.
The result is different.
The result of bike is undefined. But i dont know why result is different.
That is so because , global scope in browser and nodejs are different. When you declare a var in browser , variable is attached to global scope and can be accessed by this operator. Where as it is not the case with nodejs.
So if you copy paste and run this code in browser it would work as expected.
More clarification

JSON.stringify options [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm returning an SQL query and using JSON.stringify to store the query in a JSON file.
Here is my code:
fs.writeFileSync('data/csv/file.json', JSON.stringify(results));
Which is giving me the following output when saved to file:
[{"":4.55},{"":114}]
I'm wanting to instead output the following:
[4.55, 114]
Is there a way to do this with JSON.stringify?
UPDATE
As per the answer from #cars10
The following did the trick:
JSON.stringify(results.map(a=>a['']))
Use
JSON.stringify(Object.values(results))
instead.
Edit: This is not yet the correct solution since it only works for input like {"":4.55, " ":114}.
Looking a bit closer at your example, you will have to do:
JSON.stringify(results.map(a=>a['']))
results=[{"":4.55},{"":114}] then turns into "[ 4.55, 114 ]".
results seems to be an array with a collection of objects inside. From each object you want the property "" placed into the output array.

JavaScript [object][Object] debugging [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am asking this question because it is difficult to search/google it.
Sometimes in javascript, I want to debug things. I am writing alert(var); or console.log(variable); but very often I get something like this:
[object][Object]
If I don't know what object it is I have hard time guessing what properties it has. What are ways of painless debugging this type of objects? And by the way, what debugging methods do you recommend?
I know it is duplication, sorry for this. Answers I found so far were not satisfying.
edit
myObj = {myObjProp: objVal}
Ok. alert(myObj); => [object][object]. Is there a method that would allow me to alert a real object like alert(exampleMethod(myObj)); => {myObjProp: objVal} ?
If you use alert to print an object, then that object would be converted into a primitive value (string) before displaying. So for instance toPrimitive({}) would be [object Object]. That is why you have to use console.log(object) while debugging your code.
Just use the debugger statement.
and access it from the console
function potentiallyBuggyCode() {
debugger;
// do potentially buggy stuff to examine, step through, etc.
}

Window.open not working, boolean is not a function [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I know there is a lot of question about this but I check all of them, nothing with the same error (I might have missed one or two post)..
So, I get this jsFiddle to know how to open a facebook share window inside the current window in order to have my own share button.
But this fiddle is not working on my local.
I didn't change the code first to test so it's not because I change something.
Chrome's console throw me this error pointed on the window.open():
Uncaught TypeError: boolean is not a function
What I missed ?
Thank you in advance
It works, the problem don't come from there,
Did you overwrited the function "open" in your code? like a global variable that you have set as a boolean ?
just ctlr + F your scripts to find a "open" or "var open" ^^

Categories