Ask a Question

Passing object from script to keyword test

SOLVED
kor
Occasional Contributor

Passing object from script to keyword test

Hi,

I wrote a script that returns a grid's cell object. I want to use it in keywords test to perform methods on it.
How to use such object in keyword test?

I created object variable that is set from the script but when I want to use it e.g. in 'Call Object Method' I get message that there is no object or it's unavailable or something like this. When I use this variable in 'Run Code Snippet' it works but I don't want to use that way.  

Any ideas/suggestion ?

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: Passing object from script to keyword test

The answer is: you can't.  The object needs to be referenced in some way as to be able to interact with it.  So, when your script returns an object, you need to have some way of getting to that object.  Assigning it to a variable is the only way I've found to be able to do this and a code snippet is the only way without implementing some other code (another script function for example) to perform the necessary action against it.

 

Now... if you DO go the way of a custom keyword operation (which is basically writing another script function but encapsulating it), you could pass the retrieved object to that operation using "Last Results" item as I mentioned above.  I'd be curious to see what you come up with but, either way, you're going to write script code somewhere... either as a snippet, as a script routine, or as a script extension.

 

May I ask... why do you want to avoid a code snippet?  If it's not broke, don't fix it...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

8 REPLIES 8
tristaanogre
Community Hero

Re: Passing object from script to keyword test

What I would do is write your script code to return the object as the result of the script. Then you call the Script Routine and then use "Last Operation Result" to get the object.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
kor
Occasional Contributor

Re: Passing object from script to keyword test

Thanks, but in 'Call Object Method' operation or any other keyword test operation I can't see the way to select 'last operation result' when selecting object to perform action on. Could you give more details on that ?

 

korrrro
Occasional Contributor

Re: Passing object from script to keyword test

Anybody ?

It's probably something simple to do.

tristaanogre
Community Hero

Re: Passing object from script to keyword test


@kor wrote:

Thanks, but in 'Call Object Method' operation or any other keyword test operation I can't see the way to select 'last operation result' when selecting object to perform action on. Could you give more details on that ?

 


It is simple... first of all, you don't use "Call Object Method".  Your script code needs to look something like this:

 

function findMyObject(someparameters) {
    var myObject;
    myObject = <some code to find the desired object>;
    return myObject;

}

Then, you do something like this:


2017-12-05 08_36_31-Clipboard.png

 

To explain what you're seeing...  I'm running the script routine to find my object.  Then I set a variable (type is "Object") to "Last Operation Result".  Then I call a code snippet to call the click method off the myVar variable.  

 

This is a very simplistic demonstration of the concept.  I'd personally add a check to make sure that the function returned an actual onscreen object (check for "Exists") before I attempt to operate on it.

 

Side note: If this was an urgent problem that needed rapid results, your best bet is not the forums.  We folks here do try to reply quickly... but I'm in the East Coast of the US and you just happened to catch me at a rare time when I was on after my normal hours.  So... yes, I was going to answer you... but it was going to take some time. 🙂


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
kor
Occasional Contributor

Re: Passing object from script to keyword test

Thanks for detailed answer:)

 

Unfortunately, as I mentioned before I would like to know other solutions than using code snippet.
How to use object reference returned from script in existing TC keywords operations ?
Or is it posssible to add custom operations to keyword tests (like to have it available to select from left pane 'Operations')?

tristaanogre
Community Hero

Re: Passing object from script to keyword test

The answer is: you can't.  The object needs to be referenced in some way as to be able to interact with it.  So, when your script returns an object, you need to have some way of getting to that object.  Assigning it to a variable is the only way I've found to be able to do this and a code snippet is the only way without implementing some other code (another script function for example) to perform the necessary action against it.

 

Now... if you DO go the way of a custom keyword operation (which is basically writing another script function but encapsulating it), you could pass the retrieved object to that operation using "Last Results" item as I mentioned above.  I'd be curious to see what you come up with but, either way, you're going to write script code somewhere... either as a snippet, as a script routine, or as a script extension.

 

May I ask... why do you want to avoid a code snippet?  If it's not broke, don't fix it...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
kor
Occasional Contributor

Re: Passing object from script to keyword test

Ok, so I will use code snippet or create short procedures/functions to use to perform operations I need.

 

"May I ask... why do you want to avoid a code snippet?  If it's not broke, don't fix it..."

- I just wanted to have my test steps more clearly and easier to maintain.

tristaanogre
Community Hero

Re: Passing object from script to keyword test

Rather than a code snippet, as mentioned, you could either create another script function to perform your desired action against the result of your prior function or you can create a Keyword Operation script extension to do it.  So, if you want to go that route, those two options are available to make your code clearer. 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: