Forum Discussion

sindhu10's avatar
sindhu10
Contributor
7 years ago
Solved

How to check WinformsObject Exists or not

Hi,

i am trying to check WinformsObject exists or not but the  below code is not working 

if(Sys.Process.WaitWinFormsObject("DisplayScheduleMessage").Exists)

{

   Sys.Process.WinFormsObject("DisplayScheduleMessage").Close();

}

else

{

   Log.Message("Window doesnt exists continue next step");

}

 

Please advise.

 

 

Thanks,

  • OK then...



    I used the following code to get the list of ManualTests. Basically, the code scans the current project file for the items that end with '.tcMT' which is the extension of the files with Manual Tests.



    I believe that you can adopt this to iterate through all project files within your test suite and search not for Manual but for Keyword tests.


    '-------------------------------------------------------------------------------



    Function GetManualTestsCollection

      Const cProcName = "GetManualTestsCollection"

      Dim cProcNameMsgPrefix

      cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "



      Const cExt = ".tcMT"



      Dim Doc

      Dim ManualTestCollection

      Dim Nodes

      Dim Node

      Dim strManTCName

      Dim i



      Set ManualTestCollection = CreateObject("Scripting.Dictionary")

      Set GetManualTestsCollection = ManualTestCollection



      If ("" = BuiltIn.GetCOMServerPath("Msxml2.DOMDocument.4.0")) Then InstallMSXML



      ' Create COM object

      Set Doc = Sys.OleObject("Msxml2.DOMDocument.4.0")

      Doc.async = False



      ' Load data from the current project file

      Call Doc.load(Project.FileName)



      ' Report an error, if, for instance, the markup or file structure is invalid

      If (Doc.parseError.errorCode <> 0) Then

        s = "Reason:" & vbTab & Doc.parseError.reason & vbCrLf & _

            "Line:"   & vbTab & CStr(Doc.parseError.line) & vbCrLf & _

            "Pos:"    & vbTab & CStr(Doc.parseError.linePos) & vbCrLf & _

            "Source:" & vbTab & Doc.parseError.srcText

        ' Post an error to the log and exit

        Call Log.Error(cProcNameMsgPrefix & "Error when parsing the project file.", _

            Project.FileName & vbCrLf & s)

        Set Doc = Nothing

        Exit Function

      End If



      ' Use an XPath expression to obtain the list of Manual tests nodes

    '/Nodes/Node[@name="root"]/Node[@name="child list"]/Node/Node[@name="item data"]/Prp[@name="storage"]

    '/Nodes/Node//*/Prp[@name="storage"]

    '//Prp[@name="storage"]

    '  Set Nodes = Doc.selectNodes("//Prp[@name=""storage""]")

    '  Set Nodes = Doc.selectNodes("//Node[contains(@name,"".tcmt"")]")

      ' Case insensitive search for the 'name' nodes that contain the cExt ('.tcMT') extension

      ' Based on:

      ' http://stackoverflow.com/questions/614797/xpath-find-a-node-that-has-a-given-attribute-whose-value-contains-a-string

      ' http://www.dotnetspider.com/resources/470-Doing-case-InSensitve-comparisons-using-XPa-X.aspx

      'Set Nodes = Doc.selectNodes("//Node[contains(translate(@name, ""abcdefghijklmnopqrstuvwxyz"", ""ABCDEFGHIJKLMNOPQRSTUVWXYZ""),translate(""" & cExt & """, ""abcdefghijklmnopqrstuvwxyz"",""ABCDEFGHIJKLMNOPQRSTUVWXYZ""))]")



      ' Return 'name' nodes that ends on cExt value (case insensitive compare)

      ' Case insensitive search for the 'name' nodes that end on the cExt ('.tcMT') extension

      ' Based on:

      ' http://stackoverflow.com/questions/614797/xpath-find-a-node-that-has-a-given-attribute-whose-value-contains-a-string

      ' http://www.dotnetspider.com/resources/470-Doing-case-InSensitve-comparisons-using-XPa-X.aspx

      ' http://bytes.com/topic/xml/answers/726552-xpath-query-ends

      Set Nodes = Doc.selectNodes("//Node[substring(translate(@name, ""abcdefghijklmnopqrstuvwxyz"", ""ABCDEFGHIJKLMNOPQRSTUVWXYZ""), string-length(@name) - string-length(""" & cExt & """) + 1, string-length(@name)) = translate(""" & cExt & """, ""abcdefghijklmnopqrstuvwxyz"",""ABCDEFGHIJKLMNOPQRSTUVWXYZ"")]")



      ' Process the nodes

      For Each Node In Nodes

        For i = 0 To Node.attributes.length-1

    '      If ("value" = Node.attributes(i).name) Then

          If ("name" = Node.attributes(i).name) Then

            strManTCName = Node.attributes(i).text 'e.g. ManualTests\ManualTest1\ManualTest1.tcMT

    '        If (0 = aqString.Compare(aqFileSystem.GetFileExtension(cExt), _

    '            aqFileSystem.GetFileExtension(strManTCName), False)) Then ' case insensitive compare

              ' get file name (without path and ext.)

              strManTCName = Utilities.ChangeFileExt(aqFileSystem.GetFileName(strManTCName), "")

              If ("" <> strManTCName) Then ManualTestCollection.Add strManTCName, Eval(strManTCName)

    '        End If

          End If

        Next

      Next



      Set Doc = Nothing

    End Function

    '-------------------------------------------------------------------------------

     


5 Replies

    • sindhu10's avatar
      sindhu10
      Contributor

      Thanks and even i tried giving wait , but its not working

       if(Sys.Process("*").WaitWinFormsObject("DisplayScheduleMessage", 1000).Exists)

       {

         Sys.Process("*").WinFormsObject("DisplayScheduleMessage").Close();

       

      }

      else

       {

         Log.Message("Programme assigned");

       

      }

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Keep in mind that Sys.Process('*') will return the first process it finds in the search... which may not be your application.  You need to specify what process in order to detect the Winform.

         

        Also... you say, "It's not working"... can you be more specific?  What is happening? Any errors? What's in the log?