Forum Discussion

CWRodgers's avatar
CWRodgers
Occasional Contributor
14 years ago

Turning a Picture Object into a Push Button ...

My company uses Telrik controls and while some are supported others are not, at least that I can determine.  My problem is that we use a Telrik Ribbon Bar at the top of one of our apps.  Test Complete only recognizes the Ribbon Bar itself and not the individual components.  So in order to be able to push the individual buttons on the ribbon bar, I figured I would use the Rect function to find the image I need and then create a button that Test Complete would be able to click..  I used the code that is in the Help files with some minor tweeks to accommodate the softeware I am testing.  I have pasted it here



<snip>




function RectObjectSample()

{

  var p, w, WndPicture, Pict, Rect, Img, x, y;

  // Obtains the Page object

  p = Aliases.SNC;

  w = p.frmMainForm.m_rb;

  //Checkpoint to verify that the image is found on the screen before continuing.

  Regions.My_Project.Check(Aliases.SNC.frmMainForm.m_rb.push_button.Picture(8, 65, 71, 69, false), false, false, 326, 17);

  // Obtains the image of the software object

  WndPicture = w.Picture();

  Log.Picture(WndPicture);

  // Loads the sought-for image

  Pict = Utils.Picture;

  Pict.LoadFromFile("c:\\my_image.bmp");

  Log.Picture(Pict);

  // Searches for the image within the software object

  Rect = WndPicture.Find(Pict);    //<========= THIS IS WHERE NOTHING IS RETURNED

  if (Rect == null)

  {

  Log.Warning("The image was not found on the page.");

  return;

  }

  // Calculating coordinates of the image center

  x = w.ScreenLeft + Rect.Left + (Rect.Right - Rect.Left) / 2;

  y = w.ScreenTop + Rect.Top + (Rect.Bottom - Rect.Top) / 2;

  // Obtains the IMG object by coordinates

  Img = Sys.ObjectFromPoint(x, y);

  // Checks the results and simulates the mouse click over the image

  if (Img.Exists)

  Img.Click();

  else

  Log.Warning("Unable to simulate the click.");





}
 

As you can see this is pretty much exactly as it reads in the help file.  Am I doing something wrong or missing something or is this even acceptable to do within the Test Complete realm?  All of the checkpoints pass and the images are loaded.

1 Reply

  • Hi,



    You need to calculate coordinates within your ribbon control and then click the ribbon on them:



    var ribbon = // obtain the ribbon control

    var ribbonPic = ribbon.Picture();

    var buttonPic = Utils.Picture;

    buttonPic.LoadFromFile("c:\\my_image.bmp");

    var rect = ribbonPic.Find(buttonPic);

    ribbon.Click((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2);