Adding example for .NET

This commit is contained in:
Dan Cuellar
2013-02-12 09:58:06 -08:00
parent e266b54ae5
commit 9a5a4c65fc
5 changed files with 202 additions and 0 deletions
+1
View File
@@ -6,6 +6,7 @@ sample-code/apps/TestApp/build
sample-code/apps/WebViewApp/build
*.sublime-*
sample-code/apps/UICatalog*
sample-code/examples/dotnet/SimpleTest/*.userprefs
sample-code/examples/php/composer.lock
sample-code/examples/php/composer.phar
sample-code/examples/php/vendor
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleTest", "SimpleTest\SimpleTest.csproj", "{3C18D9A2-C814-408E-932F-00577CB8491B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C18D9A2-C814-408E-932F-00577CB8491B}.Debug|x86.ActiveCfg = Debug|x86
{3C18D9A2-C814-408E-932F-00577CB8491B}.Debug|x86.Build.0 = Debug|x86
{3C18D9A2-C814-408E-932F-00577CB8491B}.Release|x86.ActiveCfg = Release|x86
{3C18D9A2-C814-408E-932F-00577CB8491B}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = SimpleTest\SimpleTest.csproj
EndGlobalSection
EndGlobal
@@ -0,0 +1,27 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("SimpleTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("danc")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using OpenQA.Selenium.Remote;
namespace SimpleTest
{
class MainClass
{
public static void Main (string[] args)
{
// find the test application
Console.WriteLine("Finding Test App");
string appPath = _GetTestAppPath();
Console.WriteLine("Using Test App @ \"" + appPath + "\"");
// set up the remote web driver
Console.WriteLine("Connecting to Appium server");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("browserName", "iOS");
capabilities.SetCapability("platform", "Mac");
capabilities.SetCapability("version", "6.0");
capabilities.SetCapability("app", appPath);
RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);
// enter random numbers in all text fields
Console.WriteLine("Entering addends");
List<int> addends = new List<int>();
Random randomNumberGenerator = new Random();
var elements = driver.FindElementsByTagName("textField");
foreach(var element in elements)
{
int randomNumber = randomNumberGenerator.Next(0,10);
element.SendKeys(randomNumber.ToString());
addends.Add(randomNumber);
}
// calculate the expected result
int expectedResult = 0;
foreach(int i in addends)
expectedResult += i;
Console.WriteLine("Submitting the form");
// submit for computation
var buttons = driver.FindElementsByTagName("button");
buttons[0].Click();
// validate the computation
var staticTexts = driver.FindElementsByTagName("staticText");
int actualResult = int.Parse(staticTexts[0].Text);
bool pass = expectedResult == actualResult;
_LogWithColor(pass, "EXPECTED: " + expectedResult.ToString() + " ACTUAL: " + actualResult.ToString());
// shutdown
driver.Quit();
}
/// <summary>uses spotlight to find the path to the compiled test app</summary>
/// <returns>the path to the Test App</returns>
private static string _GetTestAppPath()
{
ProcessStartInfo appFinderStartInfo = new ProcessStartInfo("/usr/bin/mdfind", "-name \"TestApp.app\"");
appFinderStartInfo.RedirectStandardOutput = true;
appFinderStartInfo.UseShellExecute = false;
Process appFinder = Process.Start(appFinderStartInfo);
appFinder.WaitForExit();
string appPath = null;
foreach(string path in appFinder.StandardOutput.ReadToEnd().Split(new char[] {'\n','\r'}))
{
if (!path.Trim().EndsWith(".dSYM") && path.Contains("simulator"))
{
appPath = path.Trim();
break;
}
}
return appPath;
}
/// <summary>logs statements in green if they pass and red if they fail</summary>
/// <param name="pass"><c>true<c/c> if the message is related to a test passing, <c>false</c> otherwise</param>
/// <param name="message">message to log</param>
private static void _LogWithColor(bool pass, string message)
{
var originalColor = Console.ForegroundColor;
Console.ForegroundColor = pass ? ConsoleColor.Green : ConsoleColor.Red;
Console.WriteLine(message);
Console.ForegroundColor = originalColor;
}
}
}
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3C18D9A2-C814-408E-932F-00577CB8491B}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SimpleTest</RootNamespace>
<AssemblyName>SimpleTest</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<Externalconsole>True</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<Externalconsole>True</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Castle.Core">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Selenium.WebDriverBackedSelenium">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\Selenium.WebDriverBackedSelenium.dll</HintPath>
</Reference>
<Reference Include="ThoughtWorks.Selenium.Core">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\ThoughtWorks.Selenium.Core.dll</HintPath>
</Reference>
<Reference Include="WebDriver">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\WebDriver.dll</HintPath>
</Reference>
<Reference Include="WebDriver.Support">
<HintPath>..\..\..\..\..\..\test\trunk\main\ExternalLibraries\Selenium\WebDriver.Support.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>