Forum Discussion
SaravanaKumar_N gives an excellent example. However, instead of the strings indicated at the top, I'd change those to be arrays of properties and values that you can then apply to your FindChild calls. That way, if the UI changes, you only need to change those values at the top rather than find all the FindChild calls. Something like:
//Script1.js
var BTN_OK = ['WndClass, Caption', 'Button, OK']
var TXT_USERNAME = ['WndClass, Caption', 'EditText, UserName']
function enterUserName() {
// implement find child to find the TXT_USERNAME and enter the username
}
functin clickOk(){
// implement find child to find the BTN_OK and to click it
}
This is totally untested and just theoretical... perhaps a better way of encapsulating the property/value pairs than what I've demonstrated above. But, essentially, your code within your functions would do some sort of parsing of those values, feed them into a FindChild method call on your application, and execute an action against it.
FWIW, NameMapping really does exactly the same thing... just that it's built in, compiled code of the TestComplete environment to do the "finding". In my experimentation in recent projects, I've found that utilizing built in functionality of TestComplete is faster than implementing similar technology in script code. For example, finding a particular value in a particular column in a web table using a for loop to cycle through all the rows in the table is slower than using FindChild to search the child objects for a cell with the desired contentText.
tristaanogre, Thanks for your reply , it 's a very good example, another question :which one is better ,by scripts or by Namemapping? I found it's easy to local objects by namemapping , but I worry about the maitainance if UI changes too much .
- SaravanaKumar_N8 years agoContributor
tristaanogre, I agree, yours is even more reliable :)
nikki85, we always use NameMapping feature. Though we do not have much changes with our objects, It should not be any difference to maintain it as like local objects. If you are a newbie with NameMapping you could find difficult to begin with, but once you get used to it you would feel the difference, it's a cool feature.
I know people have used it with ease in their Web application automation which is prone to change a lot more than our desktop application.
Still if you search for NameMapping in this community, you will find lot of discussions regarding your doubts and then you could to come to conclusion.
- nikki858 years agoContributor
SaravanaKumar_N, Thanks so much ,it 's helpful for me