cancel
Showing results for 
Search instead for 
Did you mean: 

Keyword Test - Passing Name mapping array of objects

SOLVED
Highlighted
Occasional Contributor

Keyword Test - Passing Name mapping array of objects

Hi Everyone,

We are trying to create a reusable function with the objective of  the function taking dynamic number of Namemapping objects passed as parameter in a keyword test. Unfortunately, keyword test do not seem to support such an idea as far as we could observe. Any feedback on how to successfully pass an array of name mapping objects from keyword tests will be much appreciated.

 

 

Example function to be fed with name mapping objects:

function GenerateShareholderListReportName(nameMappingArrayOfObjects){

var reportNameArray = new Array();

for (i=0; i<nameMappingArrayOfObjects.length; i++){

reportNameArray.push(nameMappingArrayOfObjects[i])

}

var reportName = reportNameArray.join("; ");

return reportName;

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Re: Keyword Test - Passing Name mapping array of objects

Hi Sonya,

We are not passing any aliased or namemapped object from keyword test as did not find solution for that.

But will try to minimize usage of xpath as per advice given.

View solution in original post

6 REPLIES 6
Highlighted
Community Hero

Re: Keyword Test - Passing Name mapping array of objects

Hi,

 

I am not sure that I've got the whole idea...

You must use code in order to create an array of objects. Then you should be able to pass this array to keyword test as a parameter. (Never tried this, thus this should be checked.)

While you can create an array of NameMapped (better - Aliased) objects and pass it to some other function, this is usually not the best idea in TestComplete's world. The case is that Aliases object in TestComplete caches actual objects and tries to reuse them. The problem is that if aliased object is recreated in the tested application (e.g. table with data has beed recreated as a result of some ajax request and page script), its cached copy becomes invalid but is not destroyed and can be refreshed from test code. So, the longer test code passes Aliased object through function calls, the higher the chances (especially, for web applications) that the object will become invalid. In order to prevent false negative failures, test code should always consider whether or not the given object must or may not be valid and proceed appropriately.

Obvoiusly, for performance considerations your test code should search for tested objects as little as possible and use references to the found ones as long as possible. But on the other hand you must consider the life time of this or that tested object in the tested application and search for the new or recreated object when needed.

 

> reportNameArray.push(nameMappingArrayOfObjects[i])

> var reportName = reportNameArray.join("; ");

While technically it might be possible to join an array of complex tested objects into a string... What output are you expecting for?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Occasional Contributor

Re: Keyword Test - Passing Name mapping array of objects

Hi Alex,

Thanks for your reply. We are looking to get the ContentText of the objects (Not mentioned in the function code snippet). At the moment, we are passing Xpath of the objects and internally getting the content text of these objects after which converting to a string format with delimiter ";" as per the functionality check required for our application.

 

Any other workarounds possible excluding name mapping as you've mentioned the pitfalls that could arise?

The client wants us to only use name mapping for all check but we think xpath is an easier alternative 🙂

Highlighted
Community Hero

Re: Keyword Test - Passing Name mapping array of objects

I think your client and @AlexKaras are correct.  NameMapping and Aliases are much easier to use.

 

Once you have the context text, why are you converting it to a string?   mycontexttext + ";" will get you the string you want.  

Highlighted
Community Hero

Re: Keyword Test - Passing Name mapping array of objects

Hi,

 

The client wants us to only use name mapping for all check but we think xpath is an easier alternative 🙂

Generally speaking, I am with your client.

While it may depend on the given tested application, Aliasing is usually a much better approach when compared to XPath.

Something that might affect your code:

-- If XPath finds the sought for object, then either TestComplete's wrapping object or native DOM object may be returned. Native DOM object does not have .Exists property (and others, provided by TestComplete). So you will have to either figure out what object was returned as a result of the search, or use only native DOM properties in your test code.

-- If XPath does not find the sought for object, then null is returned. Which means that you cannot use object.Exists approach that is native for TestComplete.

 

We are looking to get the ContentText of the objects

Again, if the native DOM object is returned as a result of XPath search, then this object will not have .ContentText property as it is provided by TestComplete:

https://support.smartbear.com/testcomplete/docs/app-testing/web/general/cross-browser/creating.html#...

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Community Manager

Re: Keyword Test - Passing Name mapping array of objects

Thanks Alex, Marsha! 

Hi @Amytav , did you have a chance to follow the advice from the Community? 


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Occasional Contributor

Re: Keyword Test - Passing Name mapping array of objects

Hi Sonya,

We are not passing any aliased or namemapped object from keyword test as did not find solution for that.

But will try to minimize usage of xpath as per advice given.

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare images using the Region Checkpoint

See replies!

Converting UTC TimeDate in an Excel file

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors