Skip to content

Commit

Permalink
Merge pull request #11 from IntelliTect/addDesktop
Browse files Browse the repository at this point in the history
Checking in windows desktop automated test wrapper and example projects
  • Loading branch information
PandaMagnus committed Dec 21, 2016
2 parents 6e1490f + c269beb commit 62ff08f
Show file tree
Hide file tree
Showing 41 changed files with 1,941 additions and 0 deletions.
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{02923D67-EE7B-4629-9903-4B4757FA1DFA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Calculator.AutomatedTests</RootNamespace>
<AssemblyName>Calculator.AutomatedTests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Helpers\CalculatorHelpers.cs" />
<Compile Include="Tests\BaseTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\ExampleCalculatorTest.cs" />
<Compile Include="Tests\TestConstants.cs" />
<Compile Include="Windows\CalculatorWindow.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\IntelliTect.TestTools.WindowsTestWrapper\IntelliTect.TestTools.WindowsTestWrapper.csproj">
<Project>{AFFE1E79-C820-495E-A6AA-0CF9BA076D9B}</Project>
<Name>IntelliTect.TestTools.WindowsTestWrapper</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,15 @@
using Calculator.AutomatedTests.Windows;
using Microsoft.VisualStudio.TestTools.UITesting;

namespace Calculator.AutomatedTests.Helpers
{
public class CalculatorHelpers
{
private readonly CalculatorWindow _CalculatorWindow = new CalculatorWindow();

public bool VerifyResults(string expectedValue)
{
return expectedValue == _CalculatorWindow.FindResultsControl()?.Name;
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Calculator.AutomatedTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Calculator.AutomatedTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("02923d67-ee7b-4629-9903-4b4757fa1dfa")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,28 @@
using Calculator.AutomatedTests.Helpers;
using Calculator.AutomatedTests.Windows;
using IntelliTect.TestTools.WindowsTestWrapper;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Calculator.AutomatedTests.Tests
{
[CodedUITest]
public partial class BaseTest
{
protected readonly CalculatorWindow CalcWindow = new CalculatorWindow();
protected readonly CalculatorHelpers CalcHelpers = new CalculatorHelpers();

[TestInitialize]
public void MyTestInitialize()
{
GenericPlaybackSettings.SetPlaybackSettings();
CalcWindow.LaunchApplicationUnderTest();
}

//[TestCleanup]
//public void MyTestCleanup()
//{

//}
}
}
@@ -0,0 +1,48 @@
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Calculator.AutomatedTests.Tests
{
[CodedUITest]
public class ExampleCalculatorTest : BaseTest
{
//TODO: Change these to data drive tests
[TestMethod]
public void SimpleAddition()
{
Mouse.Click(CalcWindow.CalculatorButton( "1" ));
Mouse.Click(CalcWindow.CalculatorButton(Add));
Mouse.Click(CalcWindow.CalculatorButton("1"));
Mouse.Click(CalcWindow.CalculatorButton(EqualButton));
Assert.IsTrue(CalcHelpers.VerifyResults( "2" ), "Calculator showed incorrect result");
Assert.IsFalse( CalcHelpers.VerifyResults( "0" ), "Result never changed from default 0");
}

[TestMethod]
public void SimpleSubtraction()
{
Mouse.Click(CalcWindow.CalculatorButton("2"));
Mouse.Click(CalcWindow.CalculatorButton(Subtract));
Mouse.Click(CalcWindow.CalculatorButton("1"));
Mouse.Click(CalcWindow.CalculatorButton(EqualButton));
Assert.IsTrue(CalcHelpers.VerifyResults("1"), "Calculator showed incorrect result");
Assert.IsFalse(CalcHelpers.VerifyResults("0"), "Result never changed from default 0");
}

[TestMethod]
public void DecimalCheck()
{
Mouse.Click(CalcWindow.CalculatorButton("1"));
Mouse.Click(CalcWindow.CalculatorButton(Decimal));
Mouse.Click(CalcWindow.CalculatorButton("2"));
Mouse.Click(CalcWindow.CalculatorButton("5"));
Mouse.Click(CalcWindow.CalculatorButton(Add));
Mouse.Click(CalcWindow.CalculatorButton("1"));
Mouse.Click(CalcWindow.CalculatorButton(Decimal));
Mouse.Click(CalcWindow.CalculatorButton("5"));
Mouse.Click(CalcWindow.CalculatorButton(EqualButton));
Assert.IsTrue(CalcHelpers.VerifyResults("2.75"), "Calculator showed incorrect result");
Assert.IsFalse(CalcHelpers.VerifyResults("0"), "Result never changed from default 0");
}
}
}
@@ -0,0 +1,12 @@
namespace Calculator.AutomatedTests.Tests
{
public partial class BaseTest
{
protected const string Add = "Add";
protected const string Subtract = "Subtract";
protected const string Multiply = "Multiply";
protected const string Divide = "Divide";
protected const string Decimal = "Decimal separator";
protected const string EqualButton = "Equals";
}
}
@@ -0,0 +1,27 @@
using System;
using IntelliTect.TestTools.WindowsTestWrapper;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

namespace Calculator.AutomatedTests.Windows
{
public class CalculatorWindow : DesktopControls
{
public override string AutWindowTitle => Aut?.Title;
public override string WindowClassName => Aut?.ClassName;

public void LaunchApplicationUnderTest()
{
LaunchApplication(Environment.SystemDirectory + @"\calc.exe");
}

public WinButton CalculatorButton( string buttonName )
{
return FindControlByName( buttonName, c => new WinButton( c ) );
}

public WinWindow FindResultsControl()
{
return FindControlByName( "Result", c => new WinWindow(c) );
}
}
}
@@ -0,0 +1,47 @@
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.UITesting;
using Notepad.AutomatedTests.Windows;

namespace Notepad.AutomatedTests.Helpers
{
public class NotepadWindowHelpers
{
private readonly NotepadWindow _NotepadWindow = new NotepadWindow();
private readonly SaveAsWindow _SaveAsWindow = new SaveAsWindow();

//TODO: Is there a better way to handle saving a document for a test? E.G. a randomly generated filename in the specified location?
//TODO: Assess if part of this should be pulled out and put into the wrapper Utilities.cs class
public void SaveDocument(string location, string filename)
{
//Check if doc with same name already exists in location before saving
string formattedPath = Path.Combine(location, filename);
if (File.Exists(formattedPath))
{
filename = GetUniqueFileName( formattedPath );
}
Mouse.Click();
Mouse.Click(_NotepadWindow.Save);
Mouse.Click(_SaveAsWindow.FindSaveLocationToolbar);
_SaveAsWindow.SaveAsBox.EditableItem = filename;
_SaveAsWindow.SaveButton.SetFocus();
SendKeys.SendWait("{ENTER}");
}

public static string GetUniqueFileName(string filePath)
{
string uniqueFileName = filePath;
for (int i = 0; File.Exists(uniqueFileName); uniqueFileName = AppendFileName(filePath, $" ({++i})"))
{ }
return uniqueFileName;
}

public static string AppendFileName(string filePath, string toAppend)
{
var dir = Path.GetDirectoryName(filePath);
var fileName = Path.GetFileNameWithoutExtension(filePath);
var extension = Path.GetExtension(filePath);
return Path.Combine(dir ?? "", string.Concat(fileName, toAppend, extension));
}
}
}

0 comments on commit 62ff08f

Please sign in to comment.