Forum Discussion

sedens's avatar
sedens
Contributor
3 years ago
Solved

How to check property for text color or yellow highlight in Keyword Test for web tests

I have a web application that contains a page that shows the results of a search. The search results will show text in red to indicate a close match otherwise is black text highlighted in yellow. How...
  • AlexKaras's avatar
    3 years ago

    Hi,

     

    As this is a web application, unless the color is explicitly provided in the markup (of the element itself or some parent), I think that you need to check the style of the element you are verifying.

    This is the code to get the style that works for me:

    //-----------------------------------------------------------------------------
    
    // From: http://support.smartbear.com/viewarticle/62849/
    function getStyle(element, styleProp) {
      var document, style;
      var result;
    
      document = element.ownerDocument;
    
      if (aqObject.IsSupported(document, "defaultView")) {
        // Internet Explorer 9+, Firefox, Chrome, Safari, Opera
        style = document.defaultView.getComputedStyle(element, "");
        if (aqObject.IsSupported(style, styleProp))
          result = eval(aqString.Format("style.%s", styleProp));
        else if (aqObject.IsSupported(style, "getPropertyValue"))
          result = style.getPropertyValue(styleProp);
        else
          Log.Error(aqString.Format("%s element does not support %s style property",
              aqString.Quote(element.Name), aqString.Quote(styleProp)),
              aqString.Format("Element: %s\r\nComputed style:\r\n%s", element.FullName, style.cssText),
              BuiltIn.pmNormal, null, element.Parent.Picture());
      }
      else
        // Internet Explorer 7 - 8
        result = element.currentStyle.getPropertyValue(styleProp);
    
      return result;
    }
    //-----------------------------------------------------------------------------
    

     

    element parameter is web page element for which you are getting its style.

    styleProp is a name of the style you are looking for.

    For example:

    strFontSize = getStyle(oCell, "Font-size");
    strFontColorAct = getStyle(oCell, "Color");
    strBGColorAct = getStyle(oCell, "backgroundColor");

     

  • sedens's avatar
    sedens
    3 years ago

    Thank you! I found it, it was another child element that had the background color. Inspecting the element in the developer tools showed there were two different elements for the same field. Just needed to map to the correct element.