Keyword Test - Passing Name mapping array of objects
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
/Alex [Community Champion]
____
[Community Champions] 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 Champions]
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 Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
/Alex [Community Champion]
____
[Community Champions] 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 Champions]
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 Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Alex, Marsha!
Hi @Amytav , did you have a chance to follow the advice from the Community?
Sonya Mihaljova
Community and Education Specialist
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
