mirror of
https://github.com/appium/appium.git
synced 2026-02-11 04:20:00 -06:00
better dotnet samples
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class AndroidComplexTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
DesiredCapabilities capabilities = Env.isSauce () ?
|
||||
Caps.getAndroid18Caps (Apps.get ("androidApiDemos")) :
|
||||
Caps.getAndroid19Caps (Apps.get ("androidApiDemos"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "android - complex");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void FindElementTestCase ()
|
||||
{
|
||||
driver.FindElementByXPath ("//android.widget.TextView[@text='Animation']");
|
||||
Assert.AreEqual( driver.FindElementByXPath ("//android.widget.TextView").Text,
|
||||
"API Demos");
|
||||
IList<IWebElement> els = driver.FindElementsByXPath ("//android.widget.TextView[contains(@text, 'Animat')]");
|
||||
els = Filters.FilterDisplayed (els);
|
||||
if (!Env.isSauce ()) {
|
||||
Assert.AreEqual (els [0].Text, "Animation");
|
||||
}
|
||||
driver.FindElementByName ("App").Click();
|
||||
Thread.Sleep (3000);
|
||||
els = driver.FindElementsByAndroidUIAutomator ("new UiSelector().clickable(true)");
|
||||
Assert.GreaterOrEqual (els.Count, 10);
|
||||
Assert.IsNotNull (
|
||||
driver.FindElementByXPath("//android.widget.TextView[@text='Action Bar']"));
|
||||
els = driver.FindElementsByXPath ("//android.widget.TextView");
|
||||
els = Filters.FilterDisplayed (els);
|
||||
Assert.AreEqual (els[0].Text, "API Demos");
|
||||
driver.Navigate ().Back ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void ScrollTestCase ()
|
||||
{
|
||||
driver.FindElementByXPath ("//android.widget.TextView[@text='Animation']");
|
||||
IList<IWebElement> els = driver.FindElementsByXPath ("//android.widget.TextView");
|
||||
var loc1 = els [7].Location;
|
||||
var loc2 = els [3].Location;
|
||||
var swipe = Actions.Swipe (driver, loc1.X, loc1.Y, loc2.X, loc2.Y, 800);
|
||||
swipe.Perform ();
|
||||
}
|
||||
|
||||
private IWebElement FindTouchPaint(){
|
||||
try {
|
||||
return driver.FindElementByName ("Touch Paint");
|
||||
} catch (NoSuchElementException) {
|
||||
var els = driver.FindElementsByClassName ("android.widget.TextView");
|
||||
var loc1 = els [els.Count - 1].Location;
|
||||
var loc2 = els [0].Location;
|
||||
var swipe = Actions.Swipe (driver, loc1.X, loc1.Y, loc2.X, loc2.Y, 800);
|
||||
swipe.Perform ();
|
||||
return FindTouchPaint ();
|
||||
}
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void DrawSmileyTestCase ()
|
||||
{
|
||||
driver.FindElementByName ("Graphics").Click ();
|
||||
var el = FindTouchPaint ();
|
||||
el.Click ();
|
||||
Thread.Sleep (5000);
|
||||
ITouchAction a1 = new TouchAction ();
|
||||
a1.Press (140, 100).Release ();
|
||||
ITouchAction a2 = new TouchAction ();
|
||||
a2.Press (250, 100).Release ();
|
||||
ITouchAction smile = new TouchAction ();
|
||||
smile
|
||||
.Press (110, 200)
|
||||
.MoveTo(1, 1)
|
||||
.MoveTo(1, 1)
|
||||
.MoveTo(1, 1)
|
||||
.MoveTo(1, 1)
|
||||
.MoveTo(1, 1)
|
||||
.MoveTo(2, 1)
|
||||
.MoveTo(2, 1)
|
||||
.MoveTo(2, 1)
|
||||
.MoveTo(2, 1)
|
||||
.MoveTo(2, 1)
|
||||
.MoveTo(3, 1)
|
||||
.MoveTo(3, 1)
|
||||
.MoveTo(3, 1)
|
||||
.MoveTo(3, 1)
|
||||
.MoveTo(3, 1)
|
||||
.MoveTo(4, 1)
|
||||
.MoveTo(4, 1)
|
||||
.MoveTo(4, 1)
|
||||
.MoveTo(4, 1)
|
||||
.MoveTo(4, 1)
|
||||
.MoveTo(5, 1)
|
||||
.MoveTo(5, 1)
|
||||
.MoveTo(5, 1)
|
||||
.MoveTo(5, 1)
|
||||
.MoveTo(5, 1)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, 0)
|
||||
.MoveTo(5, -1)
|
||||
.MoveTo(5, -1)
|
||||
.MoveTo(5, -1)
|
||||
.MoveTo(5, -1)
|
||||
.MoveTo(5, -1)
|
||||
.MoveTo(4, -1)
|
||||
.MoveTo(4, -1)
|
||||
.MoveTo(4, -1)
|
||||
.MoveTo(4, -1)
|
||||
.MoveTo(4, -1)
|
||||
.MoveTo(3, -1)
|
||||
.MoveTo(3, -1)
|
||||
.MoveTo(3, -1)
|
||||
.MoveTo(3, -1)
|
||||
.MoveTo(3, -1)
|
||||
.MoveTo(2, -1)
|
||||
.MoveTo(2, -1)
|
||||
.MoveTo(2, -1)
|
||||
.MoveTo(2, -1)
|
||||
.MoveTo(2, -1)
|
||||
.MoveTo(1, -1)
|
||||
.MoveTo(1, -1)
|
||||
.MoveTo(1, -1)
|
||||
.MoveTo(1, -1)
|
||||
.MoveTo(1, -1)
|
||||
.Release();
|
||||
|
||||
IMultiAction m = new MultiAction (driver);
|
||||
m.Add (a1).Add(a2).Add(smile);
|
||||
m.Perform ();
|
||||
Thread.Sleep (10000);
|
||||
driver.Navigate ().Back ();
|
||||
Thread.Sleep (1000);
|
||||
driver.Navigate ().Back ();
|
||||
Thread.Sleep (1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class AndroidLocalServerTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
LocalServer server = new LocalServer (3001);
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
server.Start ();
|
||||
DesiredCapabilities capabilities = Env.isSauce () ?
|
||||
Caps.getAndroid18Caps (Apps.get ("androidApiDemosLocal")) :
|
||||
Caps.getAndroid19Caps (Apps.get ("androidApiDemosLocal"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "android - local server");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
server.Stop ();
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void OpenAppTestCase ()
|
||||
{
|
||||
Assert.IsNotNull (driver.FindElementByAccessibilityId("Graphics"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class AndroidSimpleTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
DesiredCapabilities capabilities = Env.isSauce () ?
|
||||
Caps.getAndroid18Caps (Apps.get ("androidApiDemos")) :
|
||||
Caps.getAndroid19Caps (Apps.get ("androidApiDemos"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "android - simple");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void FindElementTestCase ()
|
||||
{
|
||||
driver.FindElementByAccessibilityId ("Graphics").Click ();
|
||||
Assert.IsNotNull (driver.FindElementByAccessibilityId ("Arcs"));
|
||||
driver.Navigate ().Back ();
|
||||
Assert.IsNotNull (driver.FindElementByName ("App"));
|
||||
var els = driver.FindElementsByAndroidUIAutomator ("new UiSelector().clickable(true)");
|
||||
Assert.AreEqual (els.Count, 12);
|
||||
els = driver.FindElementsByAndroidUIAutomator ("new UiSelector().enabled(true)");
|
||||
Assert.GreaterOrEqual (els.Count, 20);
|
||||
Assert.IsNotNull (driver.FindElementByXPath ("//android.widget.TextView[@text='API Demos']"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class AndroidWebviewTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
DesiredCapabilities capabilities = Env.isSauce () ?
|
||||
Caps.getAndroid18Caps (Apps.get ("selendroidTestApp")) :
|
||||
Caps.getAndroid19Caps (Apps.get ("selendroidTestApp"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "android - webview");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void FindElementTestCase ()
|
||||
{
|
||||
driver.FindElementByName ("buttonStartWebviewCD").Click ();
|
||||
Thread.Sleep (5000);
|
||||
if (!Env.isSauce ()) {
|
||||
// Contexts don't work in android 4.3.3
|
||||
var contexts = driver.GetContexts ();
|
||||
string webviewContext = null;
|
||||
for (int i = 0; i < contexts.Count; i++) {
|
||||
Console.WriteLine (contexts [i]);
|
||||
if (contexts [i].Contains ("WEBVIEW")) {
|
||||
webviewContext = contexts [i];
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull (webviewContext);
|
||||
driver.SetContext (webviewContext);
|
||||
var el = driver.FindElementById ("name_input");
|
||||
el.Clear ();
|
||||
el.SendKeys ("Appium User");
|
||||
el.SendKeys (Keys.Return);
|
||||
Assert.IsTrue (driver.PageSource.Contains ("This is my way of saying hello"));
|
||||
Assert.IsTrue (driver.PageSource.Contains ("Appium User"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7A830071-06AC-4E20-9FBB-CAA395387A7C}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>AppiumDotNetSample</RootNamespace>
|
||||
<AssemblyName>AppiumDotNetSample</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WebDriver">
|
||||
<HintPath>..\packages\Selenium.WebDriver.2.42.0\lib\net40\WebDriver.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="appium-dotnet-driver">
|
||||
<HintPath>..\packages\Appium.WebDriver.1.0.0\lib\net40\appium-dotnet-driver.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="helpers\Actions.cs" />
|
||||
<Compile Include="helpers\AppiumServers.cs" />
|
||||
<Compile Include="helpers\Apps.cs" />
|
||||
<Compile Include="helpers\Caps.cs" />
|
||||
<Compile Include="helpers\Env.cs" />
|
||||
<Compile Include="helpers\Filters.cs" />
|
||||
<Compile Include="helpers\LocalServer.cs" />
|
||||
<Compile Include="AndroidComplexTest.cs" />
|
||||
<Compile Include="AndroidLocalServerTest.cs" />
|
||||
<Compile Include="AndroidSimpleTest.cs" />
|
||||
<Compile Include="AndroidWebviewTest.cs" />
|
||||
<Compile Include="IosActionsTest.cs" />
|
||||
<Compile Include="IosComplexTest.cs" />
|
||||
<Compile Include="IosLocalServerTest.cs" />
|
||||
<Compile Include="IosSimpleTest.cs" />
|
||||
<Compile Include="IosWebviewTest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<None Include="AppiumDotNetSample.csproj" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,89 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class IosActionsTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
DesiredCapabilities capabilities = Caps.getIos71Caps (Apps.get("iosTestApp"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "ios - actions");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void SimpleActionTestCase ()
|
||||
{
|
||||
IWebElement el = driver.FindElementByAccessibilityId ("ComputeSumButton");
|
||||
ITouchAction action = new TouchAction(driver);
|
||||
action.Press(el, 10, 10).Release();
|
||||
action.Perform ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void MultiActionTestCase ()
|
||||
{
|
||||
IWebElement el = driver.FindElementByAccessibilityId ("ComputeSumButton");
|
||||
ITouchAction a1 = new TouchAction(driver);
|
||||
a1.Tap(el, 10, 10);
|
||||
ITouchAction a2 = new TouchAction(driver);
|
||||
a2.Tap(el);
|
||||
IMultiAction m = new MultiAction (driver);
|
||||
m.Add (a1).Add (a2);
|
||||
m.Perform ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void SwipeTestCase ()
|
||||
{
|
||||
driver.FindElementByName ("Test Gesture").Click ();
|
||||
Thread.Sleep (1000);
|
||||
|
||||
driver.FindElementByName ("OK").Click ();
|
||||
Thread.Sleep (1000);
|
||||
|
||||
Point loc = driver.FindElementByXPath ("//UIAMapView[1]").Location;
|
||||
ITouchAction swipe = Actions.Swipe (driver, loc.X, loc.Y, loc.X + 150, loc.Y, 800);
|
||||
swipe.Perform ();
|
||||
}
|
||||
}
|
||||
}
|
||||
211
sample-code/examples/dotnet/AppiumDotNetSample/IosComplexTest.cs
Normal file
211
sample-code/examples/dotnet/AppiumDotNetSample/IosComplexTest.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class IosComplexTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void beforeAll(){
|
||||
DesiredCapabilities capabilities = Caps.getIos71Caps (Apps.get("iosUICatalogApp"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "ios - complex");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void afterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
private void ClickMenuItem(string name)
|
||||
{
|
||||
IWebElement el;
|
||||
try {
|
||||
el = driver.FindElementByName (name);
|
||||
} catch {
|
||||
var els = driver.FindElementByClassName ("UIATableView")
|
||||
.FindElements(By.ClassName ("UIATableCell"));
|
||||
el = Filters.FirstWithName (els, name);
|
||||
}
|
||||
el.Click();
|
||||
Thread.Sleep (1000);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void PrintNameTestCase ()
|
||||
{
|
||||
var els = driver.FindElementByClassName ("UIATableView")
|
||||
.FindElements(By.ClassName ("UIATableCell"));
|
||||
for (int i = 0; i < els.Count; i++)
|
||||
{
|
||||
Console.WriteLine (els [i].GetAttribute ("name"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void FindElementTestCase ()
|
||||
{
|
||||
// first view in UICatalog is a table
|
||||
var el = driver.FindElementByClassName ("UIATableView");
|
||||
Assert.IsNotNull (el);
|
||||
// check the number of cells/rows inside the table
|
||||
IList<IWebElement> els = el.FindElements (By.ClassName ("UIATableCell"));
|
||||
els = Filters.FilterDisplayed (els);
|
||||
Assert.Greater (els.Count, 6);
|
||||
// various checks
|
||||
Assert.IsNotNull (els[0].GetAttribute("name"));
|
||||
Assert.IsNotNull (driver.FindElementByClassName ("UIANavigationBar"));
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void SwitchContextTestCase ()
|
||||
{
|
||||
ClickMenuItem ("Web View, AAPLWebViewController");
|
||||
// get the contexts and switch to webview
|
||||
Assert.AreEqual(driver.GetContexts(),
|
||||
new List<string> {"NATIVE_APP", "WEBVIEW_1"});
|
||||
driver.SetContext ("WEBVIEW_1");
|
||||
// find the store link
|
||||
Thread.Sleep (1000);
|
||||
Assert.IsNotNull(driver.FindElementById ("gn-apple"));
|
||||
// leave the webview
|
||||
driver.SetContext ("NATIVE_APP");
|
||||
//Verify we are out of the webview
|
||||
Assert.IsNotNull(driver.FindElementByClassName ("UIAScrollView"));
|
||||
|
||||
driver.Navigate().Back ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void LocationTestCase ()
|
||||
{
|
||||
IList<IWebElement> els = driver.FindElementsByClassName ("UIATableCell");
|
||||
els = Filters.FilterDisplayed (els);
|
||||
var loc = els [2].Location;
|
||||
Assert.AreEqual (loc.X, 0);
|
||||
Assert.Greater (loc.Y, 100);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void ScreenshotTestCase ()
|
||||
{
|
||||
Screenshot screenshot = driver.GetScreenshot ();
|
||||
Assert.IsNotNull (screenshot);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void EditTextFieldTestCase ()
|
||||
{
|
||||
ClickMenuItem ("Text Fields, AAPLTextFieldViewController");
|
||||
// get the field and the default/empty text
|
||||
var el = driver.FindElementByClassName ("UIATextField");
|
||||
var defaultValue = el.GetAttribute ("value");
|
||||
// type something
|
||||
el.SendKeys ("1234 appium");
|
||||
Assert.AreEqual(el.GetAttribute("value"), "1234 appium");
|
||||
driver.FindElementByName ("Done").Click();
|
||||
Thread.Sleep (1000);
|
||||
el.Clear ();
|
||||
Assert.AreEqual(el.GetAttribute("value"), defaultValue);
|
||||
|
||||
driver.Navigate().Back ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void AlertTestCase ()
|
||||
{
|
||||
ClickMenuItem ("Alert Views, AAPLAlertViewController");
|
||||
{
|
||||
// trigger simple alert
|
||||
driver.FindElementByName ("Simple").Click ();
|
||||
IAlert alert = driver.SwitchTo ().Alert ();
|
||||
Assert.IsTrue (alert.Text.Contains ("A Short Title Is Best"));
|
||||
alert.Dismiss ();
|
||||
}
|
||||
{
|
||||
// trigger modal alert with cancel & ok buttons
|
||||
driver.FindElementByName ("Okay / Cancel").Click ();
|
||||
IAlert alert = driver.SwitchTo ().Alert ();
|
||||
Assert.IsTrue (alert.Text.Contains ("A Short Title Is Best"));
|
||||
alert.Accept ();
|
||||
}
|
||||
|
||||
driver.Navigate().Back ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void SliderTestCase ()
|
||||
{
|
||||
ClickMenuItem ("Sliders, AAPLSliderViewController");
|
||||
// retrieve slider, check initial value
|
||||
var slider = (AppiumWebElement) driver.FindElementByClassName ("UIASlider");
|
||||
Assert.AreEqual (slider.GetAttribute("value"), "42%");
|
||||
// change value
|
||||
slider.SetImmediateValue ("0%");
|
||||
Assert.AreEqual (slider.GetAttribute("value"), "0%");
|
||||
|
||||
driver.Navigate().Back ();
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void ElementSizeTestCase ()
|
||||
{
|
||||
var s1 = driver.FindElementByClassName ("UIATableView").Size;
|
||||
var s2 = driver.FindElementByClassName ("UIATableCell").Size;
|
||||
Assert.AreEqual (s1.Width, s2.Width);
|
||||
Assert.AreNotEqual (s1.Height, s2.Height);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void SourceTestCase ()
|
||||
{
|
||||
// main menu source
|
||||
var mainMenuSource = driver.PageSource;
|
||||
Assert.IsTrue (mainMenuSource.Contains("UIAStaticText"));
|
||||
Assert.IsTrue (mainMenuSource.Contains("Text Fields"));
|
||||
// text fields section source
|
||||
ClickMenuItem ("Text Fields, AAPLTextFieldViewController");
|
||||
var textFieldSectionSource = driver.PageSource;
|
||||
Assert.IsTrue (textFieldSectionSource.Contains("UIAStaticText"));
|
||||
Assert.IsTrue (textFieldSectionSource.Contains("Text Fields"));
|
||||
Assert.AreNotEqual (textFieldSectionSource, mainMenuSource);
|
||||
|
||||
driver.Navigate().Back ();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class IosLocalServerTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
LocalServer server = new LocalServer (3000);
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
server.Start ();
|
||||
DesiredCapabilities capabilities = Caps.getIos71Caps (Apps.get("iosWebviewAppLocal"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "ios - local server");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
server.Stop ();
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void GetPageTestCase ()
|
||||
{
|
||||
driver.FindElementByXPath("//UIATextField[@value='Enter URL']")
|
||||
.SendKeys("http://localhost:3000/index.html");
|
||||
driver.FindElementByName ("Go").Click ();
|
||||
driver.FindElementByClassName ("UIAWebView").Click (); // dismissing keyboard
|
||||
Thread.Sleep (3000);
|
||||
driver.SetContext ("WEBVIEW");
|
||||
Thread.Sleep (1000);
|
||||
var wowEl = driver.FindElementById ("wow");
|
||||
Assert.IsTrue (wowEl.Text.Contains("so cool"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class IosSimpleTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
DesiredCapabilities capabilities = Caps.getIos71Caps (Apps.get("iosTestApp"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "ios - simple");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
private int Populate() {
|
||||
IList<string> fields = new List<string> ();
|
||||
fields.Add ("IntegerA");
|
||||
fields.Add ("IntegerB");
|
||||
int sum = 0;
|
||||
for (int i = 0; i < fields.Count; i++) {
|
||||
IWebElement el = driver.FindElementByName (fields[i]);
|
||||
int x = rnd.Next (1, 10);
|
||||
el.SendKeys("" + x);
|
||||
sum += x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void ComputeSumTestCase ()
|
||||
{
|
||||
// fill form with random data
|
||||
int sumIn = Populate ();
|
||||
|
||||
// compute and check the sum
|
||||
driver.FindElementByAccessibilityId ("ComputeSumButton").Click ();
|
||||
Thread.Sleep (1000);
|
||||
IWebElement sumEl = driver.FindElementByIosUIAutomation ("elements().withName(\"Answer\");");
|
||||
int sumOut = Convert.ToInt32 (sumEl.Text);
|
||||
Assert.AreEqual (sumIn, sumOut);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Appium.Samples.Helpers;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Remote;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
|
||||
namespace Appium.Samples
|
||||
{
|
||||
[TestFixture ()]
|
||||
public class IosWebviewTest
|
||||
{
|
||||
private AppiumDriver driver;
|
||||
private bool allPassed = true;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void BeforeAll(){
|
||||
DesiredCapabilities capabilities = Caps.getIos71Caps (Apps.get("iosWebviewApp"));
|
||||
if (Env.isSauce ()) {
|
||||
capabilities.SetCapability("username", Env.getEnvVar("SAUCE_USERNAME"));
|
||||
capabilities.SetCapability("accessKey", Env.getEnvVar("SAUCE_ACCESS_KEY"));
|
||||
capabilities.SetCapability("name", "ios - webview");
|
||||
capabilities.SetCapability("tags", new string[]{"sample"});
|
||||
}
|
||||
Uri serverUri = Env.isSauce () ? AppiumServers.sauceURI : AppiumServers.localURI;
|
||||
driver = new AppiumDriver(serverUri, capabilities, Env.INIT_TIMEOUT_SEC);
|
||||
driver.Manage().Timeouts().ImplicitlyWait(Env.IMPLICIT_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void AfterAll(){
|
||||
try
|
||||
{
|
||||
if(Env.isSauce())
|
||||
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (allPassed ? "passed" : "failed"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
driver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void AfterEach(){
|
||||
allPassed = allPassed && (TestContext.CurrentContext.Result.State == TestState.Success);
|
||||
}
|
||||
|
||||
[Test ()]
|
||||
public void GetPageTestCase ()
|
||||
{
|
||||
driver.FindElementByXPath("//UIATextField[@value='Enter URL']")
|
||||
.SendKeys("https://www.google.com");
|
||||
driver.FindElementByName ("Go").Click ();
|
||||
driver.FindElementByClassName ("UIAWebView").Click (); // dismissing keyboard
|
||||
driver.SetContext ("WEBVIEW");
|
||||
Thread.Sleep (3000);
|
||||
var el = driver.FindElementByName ("q");
|
||||
el.SendKeys ("sauce labs");
|
||||
el.SendKeys(Keys.Return);
|
||||
Thread.Sleep (1000);
|
||||
Assert.IsTrue (driver.Title.Contains("sauce labs"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"DEV": false,
|
||||
"SAUCE": false,
|
||||
"SAUCE_USERNAME": "<SAUCE_USERNAME>",
|
||||
"SAUCE_ACCESS_KEY": "<SAUCE_ACCESS_KEY>"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class Actions
|
||||
{
|
||||
public static ITouchAction Swipe(AppiumDriver driver, int startX, int startY, int endX, int endY,
|
||||
int duration) {
|
||||
ITouchAction touchAction = new TouchAction(driver)
|
||||
.Press (startX, startY)
|
||||
.Wait (duration)
|
||||
.MoveTo (endX, endY)
|
||||
.Release ();
|
||||
return touchAction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class AppiumServers
|
||||
{
|
||||
public static Uri localURI = new Uri("http://127.0.0.1:4723/wd/hub");
|
||||
public static Uri sauceURI = new Uri("http://ondemand.saucelabs.com:80/wd/hub");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class Apps
|
||||
{
|
||||
static Dictionary<string, string> DEV = new Dictionary<string, string> {
|
||||
{ "iosTestApp", "sample-code/apps/TestApp/build/Release-iphonesimulator/TestApp.app" },
|
||||
{ "iosWebviewApp", "sample-code/apps/WebViewApp/build/Release-iphonesimulator/WebViewApp.app" },
|
||||
{ "iosUICatalogApp", "sample-code/apps/UICatalog/build/Release-iphonesimulator/UICatalog.app" },
|
||||
{ "androidApiDemos", "sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk" },
|
||||
{ "selendroidTestApp", "sample-code/apps/selendroid-test-app.apk" },
|
||||
{ "iosWebviewAppLocal", "sample-code/apps/WebViewApp/build/Release-iphonesimulator/WebViewApp.app" },
|
||||
{ "androidApiDemosLocal", "sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk" }
|
||||
};
|
||||
|
||||
static Dictionary<string, string> DEFAULT = new Dictionary<string, string> {
|
||||
{ "iosTestApp", "http://appium.github.io/appium/assets/TestApp7.1.app.zip" },
|
||||
{ "iosWebviewApp", "http://appium.github.io/appium/assets/WebViewApp7.1.app.zip" },
|
||||
{ "iosUICatalogApp", "http://appium.github.io/appium/assets/UICatalog7.1.app.zip" },
|
||||
{ "androidApiDemos", "http://appium.github.io/appium/assets/ApiDemos-debug.apk" },
|
||||
{ "selendroidTestApp", "http://appium.github.io/appium/assets/selendroid-test-app-0.10.0.apk" },
|
||||
{ "iosWebviewAppLocal", "http://localhost:3000/WebViewApp7.1.app.zip" },
|
||||
{ "androidApiDemosLocal", "http://localhost:3001/ApiDemos-debug.apk" }
|
||||
};
|
||||
|
||||
public static string get(string appKey) {
|
||||
if (Env.isDev()) {
|
||||
return DEV[appKey];
|
||||
} else {
|
||||
return DEFAULT[appKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using OpenQA.Selenium.Remote;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class Caps
|
||||
{
|
||||
public static DesiredCapabilities getIos71Caps (string app) {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.SetCapability("browserName", "");
|
||||
capabilities.SetCapability("appium-version", "1.0");
|
||||
capabilities.SetCapability("platformName", "iOS");
|
||||
capabilities.SetCapability("platformVersion", "7.1");
|
||||
capabilities.SetCapability("deviceName", "iPhone Simulator");
|
||||
capabilities.SetCapability("app", app);
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public static DesiredCapabilities getAndroid18Caps (string app) {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.SetCapability("browserName", "");
|
||||
capabilities.SetCapability("appium-version", "1.0");
|
||||
capabilities.SetCapability("platformName", "Android");
|
||||
capabilities.SetCapability("platformVersion", "4.3");
|
||||
capabilities.SetCapability("deviceName", "Android Emulator");
|
||||
capabilities.SetCapability("app", app);
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public static DesiredCapabilities getAndroid19Caps (string app) {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.SetCapability("browserName", "");
|
||||
capabilities.SetCapability("appium-version", "1.0");
|
||||
capabilities.SetCapability("platformName", "Android");
|
||||
capabilities.SetCapability("platformVersion", "4.4.2");
|
||||
capabilities.SetCapability("deviceName", "Android Emulator");
|
||||
capabilities.SetCapability("app", app);
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public static DesiredCapabilities getSelendroid16Caps (string app) {
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.SetCapability("browserName", "");
|
||||
capabilities.SetCapability("appium-version", "1.0");
|
||||
capabilities.SetCapability("platformName", "Android");
|
||||
capabilities.SetCapability("platformVersion", "4.1");
|
||||
capabilities.SetCapability("automationName", "selendroid");
|
||||
capabilities.SetCapability("deviceName", "Android Emulator");
|
||||
capabilities.SetCapability("app", app);
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.MultiTouch;
|
||||
using OpenQA.Selenium.Appium.Interfaces;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class Env
|
||||
{
|
||||
public static TimeSpan INIT_TIMEOUT_SEC = TimeSpan.FromSeconds(180);
|
||||
public static TimeSpan IMPLICIT_TIMEOUT_SEC = TimeSpan.FromSeconds(5);
|
||||
public static string ASSETS_ROOT_DIR = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory +
|
||||
"../../../assets");
|
||||
public static string APPIUM_ASSETS_ROOT_DIR = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory +
|
||||
"../../../../../../assets");
|
||||
|
||||
private static Dictionary<string, string> env;
|
||||
private static bool initialized = false;
|
||||
private static void Init() {
|
||||
try {
|
||||
if(!initialized)
|
||||
{
|
||||
initialized = true;
|
||||
string path = AppDomain.CurrentDomain.BaseDirectory + "../../";
|
||||
StreamReader sr = new StreamReader(path + "env.json");
|
||||
string jsonString = sr.ReadToEnd();
|
||||
JavaScriptSerializer ser = new JavaScriptSerializer();
|
||||
env = ser.Deserialize<Dictionary<string, string>>(jsonString);
|
||||
}
|
||||
} catch {
|
||||
env = new Dictionary<string, string> ();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool isTrue(string val) {
|
||||
if (val != null) {
|
||||
val = val.ToLower ().Trim ();
|
||||
}
|
||||
return (val == "true") || (val == "1");
|
||||
}
|
||||
|
||||
static public bool isSauce() {
|
||||
Init ();
|
||||
return (env.ContainsKey("SAUCE") && isTrue(env["SAUCE"])) || isTrue( Environment.GetEnvironmentVariable ("SAUCE") );
|
||||
}
|
||||
|
||||
static public bool isDev() {
|
||||
Init ();
|
||||
return (env.ContainsKey("DEV") && isTrue(env["DEV"])) || isTrue( Environment.GetEnvironmentVariable ("DEV") );
|
||||
}
|
||||
|
||||
static public string getEnvVar(string name){
|
||||
if (env.ContainsKey(name) && (env [name] != null)) {
|
||||
return env [name];
|
||||
} else {
|
||||
return Environment.GetEnvironmentVariable (name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenQA.Selenium;
|
||||
using System.Collections;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class Filters
|
||||
{
|
||||
public static IWebElement FirstWithName(IList<IWebElement> els, string name)
|
||||
{
|
||||
for (int i = 0; i < els.Count; i++)
|
||||
{
|
||||
if (els [i].GetAttribute ("name") == name) {
|
||||
return els[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IList<IWebElement> FilterWithName(IList<IWebElement> els, string name)
|
||||
{
|
||||
var res = new List<IWebElement> ();
|
||||
for (int i = 0; i < els.Count; i++)
|
||||
{
|
||||
if (els [i].GetAttribute ("name") == name) {
|
||||
res.Add(els [i]);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IList<IWebElement> FilterDisplayed(IList<IWebElement> els)
|
||||
{
|
||||
var res = new List<IWebElement> ();
|
||||
for (int i = 0; i < els.Count; i++)
|
||||
{
|
||||
IWebElement el = els [i];
|
||||
if (els [i].Displayed ) {
|
||||
res.Add(els [i]);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using Appium.Samples.Helpers;
|
||||
|
||||
namespace Appium.Samples.Helpers
|
||||
{
|
||||
public class LocalServer
|
||||
{
|
||||
private Thread listenThread;
|
||||
private HttpListener httpListener;
|
||||
private bool listening;
|
||||
private string listenBaseAddress;
|
||||
|
||||
public LocalServer (int port)
|
||||
{
|
||||
listenBaseAddress = "http://localhost:" + port;
|
||||
}
|
||||
|
||||
public void Start() {
|
||||
httpListener = new HttpListener();
|
||||
httpListener.Prefixes.Add(new Uri(listenBaseAddress).ToString());
|
||||
httpListener.Start();
|
||||
listening = true;
|
||||
|
||||
listenThread = new Thread(Listen);
|
||||
listenThread.Start();
|
||||
listenThread.IsBackground = true;
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
listening = false;
|
||||
}
|
||||
|
||||
private void Process(HttpListenerContext context)
|
||||
{
|
||||
string filename = context.Request.Url.AbsolutePath;
|
||||
filename = filename.Substring(1);
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
filename = "index.html";
|
||||
if(filename == "index.html") {
|
||||
filename = Path.Combine(Env.ASSETS_ROOT_DIR, filename);
|
||||
} else {
|
||||
filename = Path.Combine(Env.APPIUM_ASSETS_ROOT_DIR, filename);
|
||||
}
|
||||
|
||||
try {
|
||||
Stream input = new FileStream(filename, FileMode.Open);
|
||||
byte[] buffer = new byte[1024*16];
|
||||
int nbytes;
|
||||
while ((nbytes = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
context.Response.OutputStream.Write(buffer, 0, nbytes);
|
||||
input.Close();
|
||||
|
||||
} catch (System.IO.FileNotFoundException) {
|
||||
}
|
||||
context.Response.OutputStream.Close();
|
||||
}
|
||||
|
||||
private void Listen() {
|
||||
while (httpListener.IsListening && listening) {
|
||||
|
||||
HttpListenerContext context;
|
||||
try {
|
||||
context = httpListener.GetContext();
|
||||
string httpMethod = context.Request.HttpMethod;
|
||||
string rawUrl = context.Request.RawUrl;
|
||||
Console.WriteLine("Processing call to {0} {1}", httpMethod, rawUrl);
|
||||
Process (context);
|
||||
} catch (HttpListenerException e) {
|
||||
Console.Error.WriteLine(e.Message);
|
||||
Console.Error.WriteLine(e.StackTrace);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Appium.WebDriver" version="1.0.0" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net40" />
|
||||
<package id="Selenium.WebDriver" version="2.42.0" targetFramework="net40" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user