Ask a Question

Descriptive Programming with Regular Expression

nimishbhuta
Frequent Contributor

Descriptive Programming with Regular Expression

Hello, 

 

I have gone through different post related to descriptive programming in TestComplete but not found any appropriate answer to implement this. 

 

My requirement about Descriptive programming is as follows : 

 

I am writing custom subroutine for clicking a button on any page as I don't want to use standard method of TestComplete.

    This subroutine will click on the button irrespective of any web application it is not defined for any webpage, 

 For ex : In UFT, I can write Browser("name:=.*").Page("title:=.*").WebButton("name:=.*").Click

From the above example, I can click on any button on any web page, so it is not binded with any application or object repository. 

 

".*" in the code refer Regular Expression which does not relate to any specific object.

 

I would like to have similar thing in TestComplete, I am not interested in creating object from the application and then passing to my subroutine. 

 

Let me know how can it be done with the example. 

 

Regards,

 

Nimish

 

 

       

         

13 REPLIES 13
shankar_r
Community Hero

I think it is possible, you can create dummy objects in the NameMapping and modify them in-order to use it as descriptive way.

 

Like below,

desc-prog.png


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

nimishbhuta
Frequent Contributor

Hello Shankar, 

 

Thanks for your reply. I am not sure why we need to create a dummy object instead why can't we use  the mapped or named object hierarchy and use regular expression to achieve the desired result. 

 

Also,creating the dummy objects and working on it will be additional task and time consuming. I require a good solution on this.

 

Apart from this, I was evaluation the option to pass the object to the function ClickButton but that is also not working. 

 

I tried to create the object as Set obj= Aliases.browser.page.button and pass obj in to the ClickButton Sub routine with a statement to click the object but that is also not working. I tried using the map object : Set obj=Sys.browser.page.button but that is also not working. 

 

Right now, I am clueless on how to create custom sub routines for basic task such as click button, set the text box value etc. 

 

Regards,

 

Nimish

I guess, you want your descriptive programming without having any NameMapping predefined.

 

I personally would not recommend to go without NameMapping since you can not achieve 100% without NameMapping.

 

Also, TestComplete provide massive options in the NameMapping which ease our automation.

 

 

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

nimishbhuta
Frequent Contributor

Yes. I dont want to use the NameMapping but the example you should involves NameMapping for creating a dummy object. 

 

I don't want to go through NameMapping or Mapped object just directly referring to the object through it's property. 

 

Please let me know if it can be achieved or not. 

 

Regards,

 

Nimish

Why do you not want to use NameMapping?  This is the primary and preferred/best practice method for object identification in TestComplete.  It abstracts the UI object identification from your code so that you can alter your object identification without needing to affect your code (that's the beauty of Aliases).  You are using TestComplete, not UFT...  So, you may need to adapt your automation techniques to the tool.

 

TestComplete does not allow you to over-ride/overload/replace the "Click" methods with your own... you still need to work with TestComplete's "Click".  

 

If you WANT to construct your own object identification layer in code, you will want to use liberally the FindChild, FindAllChildren, FindChildEx, etc., methods... but they require you to start with The basics of the AUT... Sys.Process('myapp') or Sys.Browser(<browsername>)... but you're going to lose performance... Finding objects and using any code techniques to construct and recognize objects in code is going to SEVERELY slow your test cases because you will need to search for the object EVERY time... while NameMapping caches much of the information and is internal code logic of the Tool rather than "interpreted" script code... it natively runs faster.

 

So.... back to question 1: Why do you want to avoid using NameMapping when, for the tool you have selected to use, it is the best practice for the tool?


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

Thanks Robert for your reply. 

 

In the NameMapping way of object identification,I can't use descriptive way of accessing the object. I will explain you why I need to have descriptive way of access is that I need to have subroutines which are generic and not tied up with NameMapping. 

 

For Ex: I want to create customized Click Button subroutine,so that I can put some customized code like first checking the object exist or not and then add some reporting code. 

 

In UFT, we used to this way sorry for going back to UFT, where we are aware that that we can access the property using descriptive programming and once we create this, we are not concerned about the object repository or in TestComplete case it is NameMapping. 

 

 

Sub ClickButton(btName)

       If   Browser("name:=.*").Page("title:=.*").WebButton("name:"=btName).Exist() Then

               Browser("name:=.*").Page("title:=.*").WebButton("name:"=btName).Click

      End If 

       

End Sub 

 

In the above code, I need just pass the button name and that's it, this will work on any web page or button, so it is application independent and more useful in organizing  subroutines or function. 

 

Regards,

 

Nimish

 

 

 

 

 

Based on your explanation, Does all your objects has unique name or property in-order to use only one parameter make your object to identify? I don't think any AUT has this.

 

Why we want to go to NameMapping?

  • It makes maintenance easy
  • It has best functions like Extended Find, Conditional Object Mapping, Using different type of property values which can set thru run time, etc. which reduces your complexity of object mapping.
  • Aliases make your name mapping to be uch understandable and easy to update.
  • TestComplete making good enhancements on NameMapping which increases our code to execute effortless

I know, Since you are from UFT background you want to accomplish your requirements in UFT way in TestComplete which makes you lot of confusions and questions. 

As you are now working with TestComplete[i hope] you may want to spent some time on the TestComplete 's powerful modules like Project Variables, NameMapping and lot of in-built functions which increases os Automation code more descriptive.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

Hi Nimish,

 

> Sub ClickButton(btName)

>        If   Browser("name:=.*").Page("title:=.*").WebButton("name:"=btName).Exist() Then

>                Browser("name:=.*").Page("title:=.*").WebButton("name:"=btName).Click

>       End If 

> End Sub 

 

The exact port of the above code to TestComplete is:

Sub ClickButton(btName)
  Dim btn

  Set btn = Sys.Browser("*").FindChild(Array("ObjectType", "ObjectIdentifier"), Array("Button", btName), 1000)
  If (btn.Exist) Then
    Call btn.Click()
  End If 
End Sub

Note, however, that this code (like yours from UFT):

a) Assumes that there is only one browser process in the system with only one web page opened;

b) All buttons on all tested web pages are defined the same way in the markup;

c) As it was already mentioned by others, the code obviously has less than optimal performance.

 

The final decision is up to you depending on your actual needs and expectations.

 

 

P.S.

> In the NameMapping way of object identification,I can't use descriptive way of accessing the object.

Actually, you can: define your browser as any browser in the system and the page like any page in the system and the button as a child of the page with the Extended Find option enabled and you will get exactly the same as in UFT or the code above. Obviously, with exactly the same problems and inconveniences.

Regards,
  /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
================================
maxtester
Contributor

I  also stopped to use NameMapping. I replaced the name mapping by a custom solution with the "Find"- method. If you write your method in a clever way you can also use something like a conditional mode and everything else. I hab the same problem. On one testcase I get all elements from the Gui and then I make some interactions with them. It's much easier without name mapping

cancel
Showing results for 
Search instead for 
Did you mean: