This is a migrated thread and some comments may be shown as answers.

Anyway to run a test from a button on a form

7 Answers 581 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark Oliver
Top achievements
Rank 1
Mark Oliver asked on 04 Apr 2011, 12:00 AM
Hi Telerik Team,

My boss would like me to create unit tests that can be started on a windows form button click.
Is there anyway to do this?

Basically I have added a new windows form project called "TheTester" and on a button click run the test. I added the reference to the "TestExample" project and set "TheTester" as the startup project. "TheTester" recognizes "TestExample" until I run the project then somehow loses the reference. (Code below)

Also, is there a way that when I click "Convert all steps to code" then delete the ".aii" file while still keeping the pages.g.vb file intact? 


Any assistance would be much appreciated.

Imports ArtOfTest.WebAii.Controls.HtmlControls
Imports ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts
Imports ArtOfTest.WebAii.Core
Imports ArtOfTest.WebAii.ObjectModel
Imports ArtOfTest.WebAii.TestAttributes
Imports ArtOfTest.WebAii.TestTemplates
Imports ArtOfTest.WebAii.Win32.Dialogs
 
Imports ArtOfTest.WebAii.Silverlight
Imports ArtOfTest.WebAii.Silverlight.UI
 
Imports Microsoft.VisualStudio.TestTools.UnitTesting
 
Namespace TestExample1
    ''' <summary>
    ''' Summary description for GoogleTelerikUnitTest
    ''' </summary>
    <TestClass()> _
    Public Class GoogleTelerikUnitTest
        Inherits BaseTest
 
#Region "[Setup / TearDown]"
 
        Private testContextInstance As TestContext = Nothing
        ''' <summary>
        '''Gets or sets the VS test context which provides
        '''information about and functionality for the
        '''current test run.
        '''</summary>
        Public Property TestContext() As TestContext
            Get
                Return testContextInstance
            End Get
            Set(ByVal value As TestContext)
                testContextInstance = value
            End Set
        End Property
 
 
        'Use ClassInitialize to run code before running the first test in the class
        <ClassInitialize()> _
        Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
        End Sub
        Private _pages As Pages
 
        Public ReadOnly Property Pages As Pages
            Get
                If (_pages Is Nothing) Then
                    _pages = New Pages(Manager.Current)
                End If
                Return _pages
            End Get
        End Property
 
 
        ' Use TestInitialize to run code before running each test
        <TestInitialize()> _
        Public Sub MyTestInitialize()
            '#region WebAii Initialization
 
            ' Initializes WebAii manager to be used by the test case.
            ' If a WebAii configuration section exists, settings will be
            ' loaded from it. Otherwise, will create a default settings
            ' object with system defaults.
            '
            ' Note: We are passing in a delegate to the VisualStudio
            ' testContext.WriteLine() method in addition to the Visual Studio
            ' TestLogs directory as our log location. This way any logging
            ' done from WebAii (i.e. Manager.Log.WriteLine()) is
            ' automatically logged to the VisualStudio test log and
            ' the WebAii log file is placed in the same location as VS logs.
            '
            ' If you do not care about unifying the log, then you can simply
            ' initialize the test by calling Initialize() with no parameters;
            ' that will cause the log location to be picked up from the config
            ' file if it exists or will use the default system settings (C:\WebAiiLog\)
            ' You can also use Initialize(LogLocation) to set a specific log
            ' location for this test.
 
            ' Pass in 'true' to recycle the browser between test methods
            Initialize(False, Me.TestContext.TestLogsDir, New TestContextWriteLine(AddressOf Me.TestContext.WriteLine))
 
            ' If you need to override any other settings coming from the
            ' config section you can comment the 'Initialize' line above and instead
            ' use the following:
 
            '
            '
            '            // This will get a new Settings object. If a configuration
            '            // section exists, then settings from that section will be
            '            // loaded
            '
            '            Settings settings = GetSettings();
            '
            '            // Override the settings you want. For example:
            '            settings.DefaultBrowser = BrowserType.FireFox;
            '
            '            // Now call Initialize again with your updated settings object
            '            Initialize(settings, new TestContextWriteLine(AddressOf this.TestContext.WriteLine));
            '
            '
 
 
            ' Set the current test method. This is needed for WebAii to discover
            ' its custom TestAttributes set on methods and classes.
            ' This method should always exist in [TestInitialize()] method.
            SetTestMethod(Me, DirectCast(TestContext.Properties("TestName"), String))
 
            '
            ' Place any additional initialization here
            '
 
        End Sub
 
        ' Use TestCleanup to run code after each test has run
        <TestCleanup()> _
        Public Sub MyTestCleanup()
 
            '
            ' Place any additional cleanup here
            '
 
            '#region WebAii CleanUp
 
            ' Shuts down WebAii manager and closes all browsers currently running
            ' after each test. This call is ignored if recycleBrowser is set
            Me.CleanUp()
 
        End Sub
 
        'Use ClassCleanup to run code after all tests in a class have run
        <ClassCleanup()> _
        Public Shared Sub MyClassCleanup()
            ' This will shut down all browsers if
            ' recycleBrowser is turned on. Else
            ' will do nothing.
            ShutDown()
        End Sub
#End Region
 
        <TestMethod()> Public Sub GoogleTelerik()
            'Launch an instance of the browser
            Manager.LaunchNewBrowser()
 
            'Navigate to : 'http://google.co.nz/'
            ActiveBrowser.NavigateTo("http://google.co.nz/")
 
            'Set 'QText' text to 'telerik'
            Pages.Google.QText.Wait.ForExists(5000)
            Pages.Google.QText.Text = "telerik"
 
            'Click 'BtnGSubmit'
            Pages.Google.BtnGSubmit.Click(False)
            'Click 'TelerikEmTag'
            Pages.TelerikGoogleSearch.TelerikEmTag.Click(False)
        End Sub
 
    End Class
End Namespace

Public Class Form1
 
    Private Sub RunTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunTest.Click
        Dim theTest As New TestExample.TestExample1.GoogleTelerikUnitTest()
        theTest.MyTestInitialize()
        theTest.GoogleTelerik()
    End Sub
End Class

7 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 07 Apr 2011, 10:32 PM
Hello Mark Oliver,

Actually I would like to propose that you NOT convert your .aii tests to code and run them directly from your WinForms application using code like this:

ArtOfTest.WebAii.Design.Execution.RunHelper.Test(@"c:\testprojectdir\test.aii", @"c:\testprojectdir\bin\debug\testproject.dll");

Will this approach work for you?

Greetings,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark Oliver
Top achievements
Rank 1
answered on 11 Apr 2011, 11:10 PM
Hi Cody,

That solution would be ideal.

Currently I have implemented the solution above but when I run the windows form application outside of visual studio the browser opens but it doesn't actually run the test. Is there a way that I can run the test on the button click outside of VS?

As described I have two projects within the one solution; one with the tests, one with the windows form application. The application project references the test project (via .dll).

Also, can I install this windows form application on another computer and run the test without having to install Telerik Web Test Studio?


0
Cody
Telerik team
answered on 11 Apr 2011, 11:37 PM
Hello Mark Oliver,

To make your current approach work you'll have to change things around a bit:

1: Get rid of all of the decorations (ClassInitialize, TestInitialize, TestMethod, etc.). Since you're trying to call it as a function of your own application instead of as a VS test, you treat it as such.
2) Move all of the setup and tear down code into the GoogleTelerik function

That should get you going.

Regards,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark Oliver
Top achievements
Rank 1
answered on 19 Apr 2011, 12:06 AM
Hi Cody,

I've done as you suggested and can now run the tests outside of visual studio from a button click on a windows form application in Chrome and Firefox but am currently trying to execute the test in Internet Explorer. 

Inside of visual studio the test runs perfectly. 

Below is the error:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.


************** Exception Text **************
System.ApplicationException: Exception thrown attempting to launch Internet Explorer. Please make sure Internet Explorer is properly installed and you are able to launch it. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ArtOfTest.Common.Win32.WindowManager.Attach(IntPtr& handle, Boolean findTabWindow, Boolean loadClr, IntPtr& hookId)
   at ArtOfTest.WebAii.BrowserSpecialized.InternetExplorer.InternetExplorerActions.LaunchNewBrowserInstance(Int32 timeout, ProcessWindowStyle windowStyle, String pipename)
   --- End of inner exception stack trace ---
   at ArtOfTest.WebAii.BrowserSpecialized.InternetExplorer.InternetExplorerActions.LaunchNewBrowserInstance(Int32 timeout, ProcessWindowStyle windowStyle, String pipename)
   at ArtOfTest.WebAii.Core.Manager.LaunchNewBrowser(BrowserType browserToLaunch, Boolean waitForBrowserToConnect, ProcessWindowStyle windowStyle, String arguments)
   at ArtOfTest.WebAii.Core.Manager.LaunchNewBrowser(BrowserType browserToLaunch, Boolean waitForBrowserToConnect, ProcessWindowStyle windowStyle)
   at TestProject.Tests.GoogleTelerikUnitTest.GoogleTelerik() in C:\Users\MOliver\Documents\Test Application\TestProject\TestProject\GoogleTelerikUnitTest.vb:line 175
   at TestProject.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\MOliver\Documents\Test Application\TestProject\TestProject\Form1.vb:line 5
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)




************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.225 (RTMGDR.030319-2200)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
TestProject
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/MOliver/Documents/Test%20Application/TestProject/TestProject/bin/Debug/TestProject.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
ArtOfTest.WebAii
    Assembly Version: 2010.3.1421.0
    Win32 Version: 2010.3.1421.0
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/ArtOfTest.WebAii/2010.3.1421.0__4fd5f65be123776c/ArtOfTest.WebAii.dll
----------------------------------------
Microsoft.VisualStudio.QualityTools.UnitTestFramework
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.30319.1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualStudio.QualityTools.UnitTestFramework/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
----------------------------------------
ArtOfTest.Common
    Assembly Version: 2010.3.1421.0
    Win32 Version: 2010.3.1421.0
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/ArtOfTest.Common/2010.3.1421.0__14a0200bfcbb7b62/ArtOfTest.Common.dll
----------------------------------------
UIAutomationClient
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationClient/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationClient.dll
----------------------------------------
UIAutomationTypes
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
UIAutomationProvider
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
UIAutomationClientsideProviders
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationClientsideProviders/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationClientsideProviders.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
WindowsBase
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
ArtOfTest.InternetExplorer
    Assembly Version: 2010.3.1421.0
    Win32 Version: 2010.3.1421.0
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/ArtOfTest.InternetExplorer/2010.3.1421.0__5339893a7cefe4d6/ArtOfTest.InternetExplorer.dll
----------------------------------------


************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.


For example:


<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>


When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

0
Cody
Telerik team
answered on 19 Apr 2011, 10:21 PM
Hi Mark Oliver,

Does IE launch i.e. can you see the browser window open when you attempt to execute the test? I am wondering if this could be a permission type issue. If you're running Vista or Win 7 or Win 2008 try turning UAC off (see attached screenshot), and/or running your .exe as an administrator. Right click on your .exe and select Run as administrator from the popup context menu.

Greetings,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark Oliver
Top achievements
Rank 1
answered on 20 Apr 2011, 03:28 AM
Hi Cody,

I have tried changing the UAC and running the executable as administrator but to no avail. It launches an Internet Explorer browser (using IE 8) and then produces the error. 

The line of code that follows fails to execute according to the error
(waitForBrowserToConnect, ProcessWindowStyle windowStyle) at TestProject.Tests.GoogleTelerikUnitTest.GoogleTelerik() in C:\Users\MOliver\Documents\Test Application\TestProject\TestProject\GoogleTelerikUnitTest.vb:line 175):
Manager.LaunchNewBrowser(BrowserType.InternetExplorer)

I now have the windows form application and the test within the one project.

All the appropriate DLL's are all included in the project.
0
Cody
Telerik team
answered on 25 Apr 2011, 07:48 PM
Hello Mark Oliver,

I have my own example Windows form application successfully executing tests in IE. We must be overlooking something, but I don't know what it is without being able to look through your entire code. Would it be possible to upload your entire project (put it into a .zip file first)? Once I receive it I'll load it into VS, compile it and try running outside of VS.

The next best alternative is to setup a GoToMeeting and we look at this together on your machine.

All the best,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Mark Oliver
Top achievements
Rank 1
Answers by
Cody
Telerik team
Mark Oliver
Top achievements
Rank 1
Share this question
or