Forum Discussion

DanH's avatar
DanH
Contributor
5 years ago

How to map multiple instances of the same form

Hello,

 

I've got a bit stuck with a test which runs two instances of the same form.

 

The situation is:

 

We have a Winforms application which has a form frmInvoice, this is used for a wide range of invoice types.

 

On the whole this isn't a problem as I can simply use the mapped frmInvoice for which ever type of invoice I am testing.

 

However, there are a number of tests where an instance of frmInvoice will open up a fresh instance of frmInvoice whilst remaining open, e.g. an instance dealing with Purchase Invoices can open an instance for Purchase Credit Notes.  I have recorded a test which does this but it will not play back correctly as when the code to enter text into a control on the second instance of frmInvoice (Purchase Credit Note) is hit, the control on the first instance of frmInvoice (Purchase Invoice) is the target. 

 

I have tried mapping the two instances of frmInvoice, as e.g. frmInvoicePI and frmInvoicePCN, but I have  not been able to do this.  If I try to map a fresh instance of the form, TestComplete says it is already mapped.  I have tried looking in the Object Browser:  I can see both instances of frmInvoice, but again, I cannot change their mapping to distinguish between them.

 

 

Would anyone have an idea how I might start distinguishing between the two instances?

 

Thanks in advance,

 

Dan

 

  • are the invoice forms precisely the same for every single kind? purchase, credit note, etc?

    If not, I'd suggest creating a persisten project level variable, and using those variables as a unique identifier within the name mapping properties of that invoice object within the name mapping repo.

    So at the top , it may say something like (object type- something) for the form, but you can edit and add in additional properties, say perhaps a txt identifer of some kind, that points to that persistent variable that tells testcomplete which invoice form you want to perform the settext or keys operations on.

     

  • are the invoice forms precisely the same for every single kind? purchase, credit note, etc?

    If not, I'd suggest creating a persisten project level variable, and using those variables as a unique identifier within the name mapping properties of that invoice object within the name mapping repo.

    So at the top , it may say something like (object type- something) for the form, but you can edit and add in additional properties, say perhaps a txt identifer of some kind, that points to that persistent variable that tells testcomplete which invoice form you want to perform the settext or keys operations on.

     

  • DanH's avatar
    DanH
    Contributor

    Hello there,

    Thanks for your suggestion, I’ve now managed to sort the issue out.

    After trying to save the form frmInvoice as an object in Stores for both Purchase Invoice and Purchase Credit Note and drilling down into its properties to figure out which one to use… then realising that, whilst it might work, would be very cumbersome, I followed your advice simply copying the mapped objects and adding a filter to the properties.  I opened up my name mappings and copied the mapped object frmInvoice. I then renamed one version frmInvoiceForPI, and one frmInvoiceForPCN. I then simply added a property to filter by the FormCaption to be either “Purchase Invoice” or “Purchase Credit Note”. It is now easy to distinguish between the two instances of the form when writing code:  The different mapped objects also seem to be correctly used when simply recording KeyWordTests.

    Thanks again,

    Dan

  • Try recording a simple test that ends up with both version of the form open and enter data or click on both of them.  See if TestComplete comes up with a way to tell them apart.