forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add git ignore * add csharp sample tests * update readme * remove comments
- Loading branch information
Showing
14 changed files
with
625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Appium C# samples | ||
|
||
## Setup | ||
|
||
* Download [VisualStudio](https://visualstudio.microsoft.com/downloads/) | ||
* Open `test.sln` solution file with the Visual Studio | ||
|
||
## Running Tests | ||
|
||
* Get all packages | ||
* Run all tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{E22BA060-B513-4D45-885A-E7FEFBEEA667}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{E22BA060-B513-4D45-885A-E7FEFBEEA667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E22BA060-B513-4D45-885A-E7FEFBEEA667}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E22BA060-B513-4D45-885A-E7FEFBEEA667}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E22BA060-B513-4D45-885A-E7FEFBEEA667}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
|
||
namespace AppiumDotNetSamples.Helper | ||
{ | ||
public static class Env | ||
{ | ||
public static String rootDirectory = System.IO.Path.GetFullPath($"{System.AppDomain.CurrentDomain.BaseDirectory.ToString()}/../../../.."); | ||
|
||
static public bool IsSauce() | ||
{ | ||
return Environment.GetEnvironmentVariable("SAUCE_LABS") != null; | ||
} | ||
|
||
static public Uri ServerUri() | ||
{ | ||
String sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME"); | ||
String sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"); | ||
|
||
return (sauceUserName == null) || (sauceAccessKey == null) | ||
? new Uri("http://localhost:4723/wd/hub") | ||
: new Uri($"https://{sauceUserName}:{sauceAccessKey}@ondemand.saucelabs.com:80/wd/hub"); | ||
} | ||
|
||
public static TimeSpan INIT_TIMEOUT_SEC = TimeSpan.FromSeconds(180); | ||
public static TimeSpan IMPLICIT_TIMEOUT_SEC = TimeSpan.FromSeconds(10); | ||
} | ||
|
||
public static class App | ||
{ | ||
static public String IOSApp() | ||
{ | ||
return Env.IsSauce() ? "http://appium.github.io/appium/assets/TestApp7.1.app.zip" : $"{Env.rootDirectory}/apps/TestApp.app.zip"; | ||
} | ||
|
||
static public String IOSDeviceName() | ||
{ | ||
return Environment.GetEnvironmentVariable("IOS_DEVICE_NAME") ?? "iPhone 6s"; | ||
} | ||
|
||
static public String IOSPlatformVersion() | ||
{ | ||
return Environment.GetEnvironmentVariable("IOS_PLATFORM_VERSION") ?? "11.4"; | ||
} | ||
|
||
static public String AndroidApp() | ||
{ | ||
return Env.IsSauce() ? "http://appium.github.io/appium/assets/ApiDemos-debug.apk" : $"{Env.rootDirectory}/apps/ApiDemos-debug.apk"; | ||
} | ||
|
||
static public String AndroidDeviceName() | ||
{ | ||
return Environment.GetEnvironmentVariable("ANDROID_DEVICE_VERSION") ?? "Android"; | ||
} | ||
|
||
static public String AndroidPlatformVersion() | ||
{ | ||
return Environment.GetEnvironmentVariable("ANDROID_PLATFORM_VERSION") ?? "7.1"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using NUnit.Framework; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Enums; | ||
using OpenQA.Selenium.Appium.Android; | ||
using OpenQA.Selenium.Remote; | ||
using System; | ||
using AppiumDotNetSamples.Helper; | ||
|
||
namespace AppiumDotNetSamples | ||
{ | ||
[TestFixture()] | ||
public class AndroidBasicInteractionsTest | ||
{ | ||
private AndroidDriver<AndroidElement> driver; | ||
|
||
[SetUp()] | ||
public void BeforeAll() | ||
{ | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.SetCapability(MobileCapabilityType.BrowserName, ""); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformName, App.AndroidDeviceName()); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion()); | ||
capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2"); | ||
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Nexus"); | ||
capabilities.SetCapability("appActivity", ".app.SearchInvoke"); | ||
capabilities.SetCapability(MobileCapabilityType.App, App.AndroidApp()); | ||
|
||
driver = new AndroidDriver<AndroidElement>(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC); | ||
driver.Manage().Timeouts().ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC; | ||
} | ||
|
||
[TearDown()] | ||
public void AfterAll() | ||
{ | ||
driver.Quit(); | ||
} | ||
|
||
[Test()] | ||
public void TestShouldSendKetsToSearchBoxThenCheckTheValue() | ||
{ | ||
AndroidElement searchBoxElement = driver.FindElementById("txt_query_prefill"); | ||
searchBoxElement.SendKeys("Hello World!"); | ||
|
||
AndroidElement onSearchRequestButton = driver.FindElementById("btn_start_search"); | ||
onSearchRequestButton.Click(); | ||
|
||
AndroidElement seachText = driver.FindElementById("android:id/search_src_text"); | ||
Assert.AreEqual("Hello World!", seachText.Text); | ||
} | ||
|
||
[Test()] | ||
public void TestShouldClickAButtonThatOpensAnAlertAndThenDismissesIt() | ||
{ | ||
driver.StartActivity("io.appium.android.apis", ".app.AlertDialogSamples"); | ||
|
||
AndroidElement openDialogButton = driver.FindElementById("io.appium.android.apis:id/two_buttons"); | ||
openDialogButton.Click(); | ||
|
||
AndroidElement alertElement = driver.FindElementById("android:id/alertTitle"); | ||
String alertText = alertElement.Text; | ||
Assert.AreEqual("Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.", alertText); | ||
|
||
driver.FindElementById("android:id/button1").Click(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using NUnit.Framework; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Enums; | ||
using OpenQA.Selenium.Appium.Android; | ||
using OpenQA.Selenium.Remote; | ||
using System; | ||
using AppiumDotNetSamples.Helper; | ||
|
||
namespace AppiumDotNetSamples | ||
{ | ||
[TestFixture()] | ||
public class AndroidCreateSessionTest | ||
{ | ||
|
||
private AndroidDriver<AndroidElement> driver; | ||
|
||
[OneTimeSetUp()] | ||
public void BeforeAll() | ||
{ | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.SetCapability(MobileCapabilityType.BrowserName, ""); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformName, App.AndroidDeviceName()); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion()); | ||
capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2"); | ||
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Nexus"); | ||
capabilities.SetCapability(MobileCapabilityType.App, App.AndroidApp()); | ||
|
||
driver = new AndroidDriver<AndroidElement>(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC); | ||
driver.Manage().Timeouts().ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC; | ||
} | ||
|
||
[Test()] | ||
public void TestShouldCreateAndDestroyAndroidSessions() | ||
{ | ||
String currentActivity = driver.CurrentActivity; | ||
|
||
Assert.AreEqual(".ApiDemos", currentActivity); | ||
|
||
driver.Quit(); | ||
|
||
Assert.Throws<WebDriverException>( | ||
() => { currentActivity = driver.CurrentActivity; }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using NUnit.Framework; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Enums; | ||
using OpenQA.Selenium.Appium.Android; | ||
using OpenQA.Selenium.Remote; | ||
using System; | ||
using AppiumDotNetSamples.Helper; | ||
|
||
namespace AppiumDotNetSamples | ||
{ | ||
[TestFixture()] | ||
public class AndroidCreateWebSessionTest | ||
{ | ||
|
||
private IWebDriver driver; | ||
|
||
[OneTimeSetUp()] | ||
public void BeforeAll() | ||
{ | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.SetCapability(MobileCapabilityType.BrowserName, "Chrome"); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformName, App.AndroidDeviceName()); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion()); | ||
capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2"); | ||
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Nexus"); | ||
|
||
driver = new AndroidDriver<AppiumWebElement>(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC); | ||
driver.Manage().Timeouts().ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC; | ||
} | ||
|
||
[Test()] | ||
public void TestShouldCreateAndDestroyAndroidwebSessions() | ||
{ | ||
driver.Url = "https://www.google.com"; | ||
String title = driver.Title; | ||
|
||
Assert.AreEqual("Google", title); | ||
|
||
driver.Quit(); | ||
|
||
Assert.Throws<WebDriverException>( | ||
() => { title = driver.Title; }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using NUnit.Framework; | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Appium; | ||
using OpenQA.Selenium.Appium.Enums; | ||
using OpenQA.Selenium.Appium.Android; | ||
using OpenQA.Selenium.Remote; | ||
using System; | ||
using System.Collections.Generic; | ||
using AppiumDotNetSamples.Helper; | ||
|
||
namespace AppiumDotNetSamples | ||
{ | ||
[TestFixture()] | ||
public class AndroidSelectorsTest | ||
{ | ||
private AndroidDriver<AndroidElement> driver; | ||
|
||
[OneTimeSetUp()] | ||
public void BeforeAll() | ||
{ | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.SetCapability(MobileCapabilityType.BrowserName, ""); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformName, App.AndroidDeviceName()); | ||
capabilities.SetCapability(MobileCapabilityType.PlatformVersion, App.AndroidPlatformVersion()); | ||
capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2"); | ||
capabilities.SetCapability(MobileCapabilityType.DeviceName, "Nexus"); | ||
|
||
capabilities.SetCapability(MobileCapabilityType.App, App.AndroidApp()); | ||
|
||
driver = new AndroidDriver<AndroidElement>(Env.ServerUri(), capabilities, Env.INIT_TIMEOUT_SEC); | ||
driver.Manage().Timeouts().ImplicitWait = Env.IMPLICIT_TIMEOUT_SEC; | ||
} | ||
|
||
[OneTimeTearDown()] | ||
public void AfterAll() | ||
{ | ||
driver.Quit(); | ||
} | ||
|
||
[Test()] | ||
public void TestShouldFindElementsByAccessibilityId() | ||
{ | ||
ICollection<AndroidElement> elements = driver.FindElementsByAccessibilityId("Content"); | ||
Assert.AreEqual(1, elements.Count); | ||
} | ||
|
||
[Test()] | ||
public void TestShouldFindElementsById() | ||
{ | ||
ICollection<AndroidElement> elements = driver.FindElementsById("android:id/action_bar_container"); | ||
Assert.AreEqual(1, elements.Count); | ||
} | ||
|
||
[Test()] | ||
public void TestShouldFindElementsByClassName() | ||
{ | ||
ICollection<AndroidElement> elements = driver.FindElementsByClassName("android.widget.FrameLayout"); | ||
Assert.AreEqual(3, elements.Count); | ||
} | ||
|
||
[Test()] | ||
public void TestShouldFindElementsByXPath() | ||
{ | ||
ICollection<AndroidElement> elements = driver.FindElementsByXPath("//*[@class='android.widget.FrameLayout']"); | ||
Assert.AreEqual(3, elements.Count); | ||
} | ||
} | ||
} |
Oops, something went wrong.