Starting an application with coded UI tests in VS 2010
-
01-10-2019 - |
Question
When I recorded a test with the recorder in Visual Studio 2010 Premium, I noticed that the recorder doesn't generate the code to start the program.
Steps to repro:
- Add a new Coded UI test to a VB .NET testing project
- Click "OK" to use "Record actions, edit UI map or add assertions"
- Click the record button to start recording.
- Press CTRL+F5 in Visual Studio to start your program
- Click the "Generate Code" button.
- Observe that no code is generated as far as running things go.
Considering that starting a program is a rather important part of testing a program, I'm sure there's a solution for this problem.
Solution
Take a look at the SO question VS 2010 Coded UI Test - Launch Referenced Application
It may answer your question.
OTHER TIPS
Add this to your UIMap.vb file:
(Be certain to change the EXE to match your own)
Namespace RouteManagement_UI_Tests
Partial Public Class UIMap
Public Sub StartApp()
Dim RMS As ApplicationUnderTest = ApplicationUnderTest.Launch(Me.StartAppParams.ExePath, Me.StartAppParams.AlternateExePath)
End Sub
Public Overridable ReadOnly Property StartAppParams() As StartAppParams
Get
If (Me.mStartAppParams Is Nothing) Then
Me.mStartAppParams = New StartAppParams()
End If
Return Me.mStartAppParams
End Get
End Property
Private mStartAppParams As StartAppParams
End Class
Public Class StartAppParams
#Region "Fields"
'''<summary>
'''</summary>
Public ExePath As String = "C:\Somebinary.exe"
'''<summary>
'''</summary>
Public AlternateExePath As String = "%VisualStudioDir%\Somebinary.exe"
#End Region
End Class
End Namespace
Then refer to this method in your test code as follows:
Public Class CodedUITest1
<TestMethod()>
Public Sub Test1()
With Me.UIMap
.StartApp()
.ExitApp()
End With
End Sub
End Class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow