locked
Data Driven CodedUI Test - Can't find TreeView item on second iteration, Module Setup

    Question

  • Hello,

    Please tell me if I am approaching this completely wrong, however I added a module to my test project so I could call commonly used functions from there instead of adding them to every test. Is this the correct approach?

    If it is, I am seeing an issue where on my second iteration it can't find a tree view and so falls over.

    I then copied all my function back into my CodedUI test and it runs fine, I believe it might have something to do with the code that is always at the bottom of a codedUI test:

        Public ReadOnly Property uimap As IECCScalableAutomation.UIMap

            Get

                If (Me.map Is Nothing) Then

                    Me.map = New ieccscalableautomation.uimap()

                End If

     

                Return Me.map

            End Get

        End Property

        Private map As IECCScalableAutomation.UIMa

     

    Would I need something like that at the bottom of my module? Can you please advice the best approach to have a central store of common functions? The fact it runs fine the first time, I am guessing its struggling to create a new UIMap?

    Al help appreciated

    Regards

    Tuesday, July 27, 2010 8:46 AM

Answers

  • You can do one of the following

    1. Write all these methods in the UIMap.vb file.

    2. If you choose to write as a different module, then pass the UIMap as the first argument to each method.

    Vinoth.

    Wednesday, July 28, 2010 6:46 AM

All replies

  • The UIMap is a repository of both controls and recorded actions.

    Controls cannot be shared across tests. So you've to re-create the UIMap to ensure that we don't hold on to old references.

    Vinoth.

    Tuesday, July 27, 2010 3:01 PM
  • So can my approach not be done?

    I have a module which contains several functions which include Map.etcetc recorded functions.

    Then from my TestMethod vb file i am calling the functions from the module so execute my actions. These works fine for the first iteration, but on the second iteration it complains it can't find the control? Why is this? Do i need to refresh the map?

    From what you say, is it not possible to have a central storage of functions and ui.map actions? So if i have recorded a function full of IF statements and actions, can i not use that in multiple tests?

    So what if my application changed, that would mean i would have to edit everything single test, instead of being able to just change it in one place.

    Tuesday, July 27, 2010 3:13 PM
  • I think there is a disconnect here. I assume you've moved a map containing common UI actions to a different module. In that case, you need to refresh the map for each iteration else we'll be holding on to old references.

    If my understanding is not correct, please post a snippet of what you've done.

    Vinoth.

     

    Tuesday, July 27, 2010 3:38 PM
  • I have a module which contains functions as follows and has the following map code which i took from the codedui test and stuck at the bottom so its looks like this:

    So this is from file: Module - AutomationFunctions

    Module moduleAutomationFunctions
      'Library for all our scalable functions
    
      Public ReadOnly Property UIMap As IECCScalableAutomation.UIMap
        Get
          If (map Is Nothing) Then
            map = New IECCScalableAutomation.UIMap()
          End If
    
          Return map
        End Get
      End Property
      Public map As IECCScalableAutomation.UIMap
    
      Public Sub VerifyPuttyIsLoaded()
    
        'Verifies that it is indeed Putty that loaded. Checks that the class name is PuTTYConfigBox
        Try
          UIMap.VerifyPuttyIsLoaded()
          Console.WriteLine("Verified that it was Putty that loaded")
        Catch ex As Exception
          Console.WriteLine("The application that was loaded was not Putty", ex.Message)
          Assert.Fail("The application that was loaded was not Putty")
        End Try
      End Sub
    
      Public Sub SelectRequiredVM(ByVal RequiredSession As String)
    
        'Sets the Item to be selected from the listbox to be the one defined in 'RequiredSession'
        UIMap.SelectRequiredSessionParams.UIItemListSelectedItemsAsString = RequiredSession
    
        Try
          'Executes the actions required to select the required session from the list and click load
          UIMap.SelectRequiredSession()
          Console.WriteLine(RequiredSession & " selected from listbox")
        Catch ex As Exception
          Console.WriteLine(RequiredSession & " not in the listbox", ex.Message)
          Assert.Fail("Required Session is not in the listbox")
        End Try
    
      End Sub

    This from within the testmethod within my codedUI test i call the functions from the module as follows:

    This is taken from CodedUITest - IECCAutomation.vb

        'Start of configuring Putty and Connecting to the VM
    
        'Calls the LoadPutty function passing in the location of the putty executable
        LoadPutty("C:\Documents and Settings\dr25630\My Documents\putty.exe")
    
        'Function to verify that Putty has loaded
        VerifyPuttyIsLoaded()
    
        'Calls the SelectRequiredVM function passing the required session to load
        SelectRequiredVM("Scaleable Test VM3")
    

     So i think i understand your UIMap refreshing, but where should i do it? Do i call a function from the Module that can refresh the UIMap or do i have to do it within the CodedUI Test file?

    I am new to this, so if this is completely wrong please do tell me, and explain how i can do it. My end goal is to have a set of Common functions, i can call from a number of CodedUI tests so that when things change i only have to edit my module file and not all the tests.

    Tuesday, July 27, 2010 3:50 PM
  • You can do one of the following

    1. Write all these methods in the UIMap.vb file.

    2. If you choose to write as a different module, then pass the UIMap as the first argument to each method.

    Vinoth.

    Wednesday, July 28, 2010 6:46 AM
  • Hello Vinoth

    Thanks for the response, i moved them to UIMap.vb and it runs fine there on the second iteration.

    My question now is, in one of my functions / method i use data from my CSV file. But now i have moved it to UIMap it says that it doesnt know what "TestContext.DataRow("TestCommand" & X.ToString))" is. Can you call your csv file direct from the UIMap.vb or is this not possiblle?

    Regards

    Wednesday, July 28, 2010 8:35 AM
  • You've to pass the TestContext object to the method in UIMap.vb file. Please refer to http://blogs.msdn.com/b/gautamg/archive/2009/12/18/why-is-coded-ui-test-generated-code-not-a-straight-line-code.aspx for tricks on customizing the code.

    Vinoth.

    Wednesday, July 28, 2010 9:19 AM