0

I am trying to print the Parameter itself on console. my sample codes are like this:

it('should print the parameter value', async function(){
    expect (PO.printParameterandDoSomethingElse(myElement1)).toBe(true); 
}

the Page object is :

this.printParameterandDoSomethingElse = async function(ele){
   console.log(ele)
   //do something
   //do something else
   //return output
}

I was hoping to get "MyElement1" printed , but, in this code the console is printing "[object Object]" instead of the parameter itself (MyElement1). I found a discussion in the github thread where another user had the same problem but I could not find her SO thread. Is there a way to achieve this?

nhrcpt
  • 862
  • 3
  • 21
  • 51
  • Do you mean you want to print the parameter name? I am assuming `myElement1` is an element so `[object Object]` is the expected output – DublinDev May 14 '19 at 14:53
  • Exactly!! I want the output of console.log(ele) to be "myElement1". Can we do it using any method? – nhrcpt May 14 '19 at 17:53
  • [This thread](https://stackoverflow.com/questions/3404057/determine-original-name-of-variable-after-its-passed-to-a-function) may be of use to you but as mentioned in it there is rarely a good reason to do this. The main answer suggests wrapping your your variable in curly braces therefore converting it to a key:value pair in a JSON object `PO.printParameterandDoSomethingElse({myElement1})`. You can then access the key if you need to original variable name – DublinDev May 14 '19 at 20:25
  • Possible duplicate of [Determine original name of variable after its passed to a function](https://stackoverflow.com/questions/3404057/determine-original-name-of-variable-after-its-passed-to-a-function) – DublinDev May 14 '19 at 20:26
  • Can you add an example of what you're are passing to the function – Sergey Pleshakov May 15 '19 at 14:46

0 Answers0