Forum Discussion

asavoia's avatar
asavoia
Occasional Contributor
4 years ago
Solved

background color

Hi everyone
I have a problem with the backgroud color of an object, I can't understand how to detect it. Using the object spy on the object, there is no property that tells me the color. Do you have any suggestions?

thank you very much

  • Use pixel property of the picture of the object

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/pixels.html

     

    Example of use:

    /**
      qa.system.isCheckedTCheckListBox (OBJECT CheckListBox, INTEGER Item, INTEGER CheckColor)
        Check state of a TCheckListBox item (must be visible)
        CheckListBox is the TCheckListBox object to check
        Item is the line number to check
        CheckColor is the color code of checkbox. Default value is clBlack
        Return true if item is checked
    */
      qa.system.isCheckedTCheckListBox = function (CheckListBox, Item, CheckColor = clBlack) {
        var found = false;
        try {
          var image = CheckListBox.Picture(CheckListBox.wItemBounds(Item).Left + 4, CheckListBox.wItemBounds(Item).Top + 7, 8, 8, false);
          for (var i = 0;i<8;i++) {
            for (var j = 0;j<8;j++) {
              if (image.Pixels(i, j) == CheckColor) {
                found = true;
                break;
              }
              if (found)
                break;
            }
          }
        }
        catch(e) {
          qa.system.logExceptionByLevel(e, 'isCheckedTCheckListBox()', null, 'Warning');
        }
        return found;
      };
    

     

  • Hi Guys,

    I like BenoitB's approach. Wamboo, are you working with asavoia?

    If you use the TextObject method to get the needed text, I think it should be possible to treat the obtained rectangle as an image. After that, you can calculate the background color as the most common pixel color in the object or the first 2 px from top and from left (depending on what you TextObject will return.

7 Replies

  • BenoitB's avatar
    BenoitB
    Community Hero

    Use pixel property of the picture of the object

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/pixels.html

     

    Example of use:

    /**
      qa.system.isCheckedTCheckListBox (OBJECT CheckListBox, INTEGER Item, INTEGER CheckColor)
        Check state of a TCheckListBox item (must be visible)
        CheckListBox is the TCheckListBox object to check
        Item is the line number to check
        CheckColor is the color code of checkbox. Default value is clBlack
        Return true if item is checked
    */
      qa.system.isCheckedTCheckListBox = function (CheckListBox, Item, CheckColor = clBlack) {
        var found = false;
        try {
          var image = CheckListBox.Picture(CheckListBox.wItemBounds(Item).Left + 4, CheckListBox.wItemBounds(Item).Top + 7, 8, 8, false);
          for (var i = 0;i<8;i++) {
            for (var j = 0;j<8;j++) {
              if (image.Pixels(i, j) == CheckColor) {
                found = true;
                break;
              }
              if (found)
                break;
            }
          }
        }
        catch(e) {
          qa.system.logExceptionByLevel(e, 'isCheckedTCheckListBox()', null, 'Warning');
        }
        return found;
      };
    

     

    • Wamboo's avatar
      Wamboo
      Community Hero

      I was just wondering how to write something like that! I have to test it!

       

      Do you have any idea how to define a color if I see no value in ObjectSpy?

       

      A color is not saved as an object property.

       

       

      • BenoitB's avatar
        BenoitB
        Community Hero

        To know the color on screen use a good screen capture software (like ShareX which has built-in on-screen color reader).

        Or do a reverse like using a loop from the picture of the object and logging the pixel value (wich is the color value).