New dotnet code sample

This commit is contained in:
sebv
2014-04-18 18:35:05 +08:00
parent 9e97f76039
commit ddad985d0e
11 changed files with 206 additions and 187 deletions

View File

@@ -0,0 +1,4 @@
bin/
obj/
packages/

View File

@@ -0,0 +1,58 @@
<?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>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7ED8B080-7820-4D7A-95D2-B53F55028F59}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>AppiumDriverDemo</RootNamespace>
<AssemblyName>AppiumDriverDemo</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>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="appium-dotnet-driver">
<HintPath>packages\Appium.WebDriver.0.1\lib\net40\appium-dotnet-driver.dll</HintPath>
</Reference>
<Reference Include="WebDriver">
<HintPath>packages\Selenium.WebDriver.2.41.0\lib\net40\WebDriver.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="Newtonsoft.Json">
<HintPath>packages\Newtonsoft.Json.6.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProgramTest.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppiumDriverDemo", "AppiumDriverDemo.csproj", "{7ED8B080-7820-4D7A-95D2-B53F55028F59}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7ED8B080-7820-4D7A-95D2-B53F55028F59}.Debug|x86.ActiveCfg = Debug|x86
{7ED8B080-7820-4D7A-95D2-B53F55028F59}.Debug|x86.Build.0 = Debug|x86
{7ED8B080-7820-4D7A-95D2-B53F55028F59}.Release|x86.ActiveCfg = Release|x86
{7ED8B080-7820-4D7A-95D2-B53F55028F59}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = AppiumDriverDemo.csproj
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,12 @@
using System;
namespace AppiumDriverDemo
{
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine ("Run the unit tests!");
}
}
}

View File

@@ -0,0 +1,94 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Text.RegularExpressions;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium;
namespace AppiumDriverDemo
{
[TestFixture ()]
public class ProgramTest
{
private AppiumDriver driver;
[TestFixtureSetUp]
public void beforeAll(){
// 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("device", "iPhone Simulator");
capabilities.SetCapability("deviceName", "iPhone Retina (4-inch 64-bit)");
capabilities.SetCapability("platform", "ios");
capabilities.SetCapability("version", "7.1");
capabilities.SetCapability("app", appPath);
driver = new AppiumDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);
}
[TestFixtureTearDown]
public void afterAll(){
// shutdown
driver.Quit();
}
[Test ()]
public void RegularWebdriverMethodsTestCase ()
{
// 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);
Assert.AreEqual (actualResult.ToString(), expectedResult.ToString());
}
[Test ()]
public void AppiumDriverMethodsTestCase ()
{
// Using appium extension methods
AppiumWebElement el = (AppiumWebElement) driver.FindElementByIosUIAutomation(".elements()");
el.SetImmediateValue ("abc");
Assert.False (driver.IsAppInstalled("RamdomApp"));
}
/// <summary>retrieves the path of the locally installed app</summary>
/// <returns>the path to the Test App</returns>
private static string _GetTestAppPath()
{
string appiumDir = Regex.Replace(System.Reflection.Assembly.GetExecutingAssembly().Location, "/appium/.*$", "/appium");
return appiumDir + "/sample-code/apps/TestApp/build/Release-iphonesimulator/TestApp.app";
}
}
}

View File

@@ -0,0 +1,22 @@
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 ("AppiumDriverDemo")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("baba")]
[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("")]

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Appium.WebDriver" version="0.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net40" />
<package id="NUnit" version="2.6.3" targetFramework="net40" />
<package id="Selenium.WebDriver" version="2.41.0" targetFramework="net40" />
</packages>