Forum Discussion

VNA's avatar
VNA
Occasional Contributor
7 years ago
Solved

How to check alignment from keyword test

Hi, Can anyone suggest how to check the alignment of few lines of text from keyword test, I need whether it is centre, left or right aligned .The text may be as follows:

 

 Address1

Address 2

Address 3

 

 

With Regards,

Veena.

  • Alignment is always relative to something.  Centered to what? Right aligned to what?  When doing this as a manual test, the requirements would say something like "Centered within the panel" or "Aligned to the left side of the window".  

     

    Every component TestComplete sees has a "Left" property that gives, in pixels, the alignment of the particular component on screen.  So, if you want to make sure that something is left aligned, you would compare the "Left" property of the container with the "Left" property of the item.  Strictly left aligned would show those to values to be equal.  Obviously, there are margins so it could be that the component's "Left" property is something like 20 greater than the container's "Left" property.  Right alignment would use a similar rule but would have to take into consideration the width of the container, the width of the component and make sure that the "Left" property is the Container width minus the component width.

     

    Centering is trickier because you would need to find the midpoint of the container based upon the Left and Width values.  Then find the midpoint of the component.  Then subtract the midpoint of the component from the midpoint of the container and that would be what the "Left" value of the component should be to be centered.

     

    OR....  Don't bother automating these kinds of things.  I find that the trouble it takes to do these kind of UI Look and Feel tests on an application ends up sucking up a lot of resource that could be better spent automating critical functionality things.  Look and Feel testing is actually a VERY fast test for a manual tester.  I can open up a screen and, within a second or two, tell you if stuff is not aligned where it should be.

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Alignment is always relative to something.  Centered to what? Right aligned to what?  When doing this as a manual test, the requirements would say something like "Centered within the panel" or "Aligned to the left side of the window".  

     

    Every component TestComplete sees has a "Left" property that gives, in pixels, the alignment of the particular component on screen.  So, if you want to make sure that something is left aligned, you would compare the "Left" property of the container with the "Left" property of the item.  Strictly left aligned would show those to values to be equal.  Obviously, there are margins so it could be that the component's "Left" property is something like 20 greater than the container's "Left" property.  Right alignment would use a similar rule but would have to take into consideration the width of the container, the width of the component and make sure that the "Left" property is the Container width minus the component width.

     

    Centering is trickier because you would need to find the midpoint of the container based upon the Left and Width values.  Then find the midpoint of the component.  Then subtract the midpoint of the component from the midpoint of the container and that would be what the "Left" value of the component should be to be centered.

     

    OR....  Don't bother automating these kinds of things.  I find that the trouble it takes to do these kind of UI Look and Feel tests on an application ends up sucking up a lot of resource that could be better spent automating critical functionality things.  Look and Feel testing is actually a VERY fast test for a manual tester.  I can open up a screen and, within a second or two, tell you if stuff is not aligned where it should be.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      As for doing this in keyword tests... these would all be property checkpoints where you would be comparing the property of the component with some code expression that utilizes the property of the containing component.