Hi All,
Below you can find the code to verify if the given text is present in the Putty Console window. Function require three parameters i.e. Object of putty, the text to verify on console and the position to search for the text( Here the allowed values are Start, End, Anywhere(default value)).
function searchTextInPuttyConsole(PuttyObject, TextToVerify, VerifyPosition)
{
  if(VerifyPosition === undefined || VerifyPosition == null || aqString.Trim(VerifyPosition) == "")
  {
    VerifyPosition = "anywhere";
  }
  //Set the position to its lower case letters
  VerifyPosition = aqString.Trim(aqString.ToLower(VarToStr(VerifyPosition)));
  //gets the console text
  var consoleText =GetPuttyConsoleText(PuttyObject);
  var consoleHasString = false;
  switch(VerifyPosition)
  {
    case "start": 
      if(aqString.Find(consoleText, TextToVerify) == 0)
      {
        consoleHasString = true;
      }
      break;
    case "anywhere":
      if(aqString.Find(consoleText, TextToVerify) >= 0)
      {
        consoleHasString = true;
      }
      break;
    case "end":
      if(aqString.Find(consoleText, TextToVerify, consoleText.length - TextToVerify.length) >= 0)
      {
        consoleHasString = true;
      }
      break;
  }
  if(consoleHasString)
  {
    Log.Message("The given putty console contains the text'");
  }
  else
  {
    Log.Error("The putty console does not contains text ");
  }
}
function GetPuttyConsoleText(PuttyObject)
{
  //Click the PuttyObject's
  PuttyObject.Click(PuttyObject.Left + 15, PuttyObject.Top + 15);
  aqUtils.Delay(200);
  PuttyObject.SystemMenu.Click("Copy All to Clipboard");
  //reads entire clipboard text
  var consoleText = VarToStr(Sys.Clipboard);
  //trims the consoletext
  consoleText = aqString.Trim(consoleText);
  //replaces unwanted spaces in the text read
  consoleText = aqString.Replace(consoleText, "     ", " ");
  consoleText = aqString.Replace(consoleText, "    ", " ");
  consoleText = aqString.Replace(consoleText, "   ", " ");
  consoleText = aqString.Replace(consoleText, "  ", " ");
  consoleText = aqString.Replace(consoleText, "  ", " ");
  return consoleText;
}
                       
                    
0 Comment(s)