Forum Discussion

VNA's avatar
VNA
Occasional Contributor
8 years ago

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 Add...
  • tristaanogre's avatar
    8 years ago

    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.