Forum Discussion
- SaravanaKumar_NContributor
It would depend on how you develop your framework. I understood you are not using namemapping feature.
One of the framework design pattern that is popular amoung Selenium users is Page Object Model. If you take that each page will have its own objects and corresponding methods.
We could implement the same in TestComplete. So your page1/window1 will be one script file. At the top you could have a global variables and have all the objects...like this (JavaScript)
//Script1.js var BTN_OK = "Sys.Process.Window.BtnOk" var BTN_CANCEL = "Sys.Process.Window.BtnCancel" var TXT_USERNAME = "Sys.Process.Window.txUserName" 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
}Here, if there is any change in your objects you can always go to the corresponding file and make changes easily. Just remember to have all the objects initialized at the top, never hard code it at the method level which will be difficult to maintain.
Thanks.
- tristaanogreEsteemed Contributor
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.
- nikki85Contributor
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 .