forked from nikolay-advolodkin/dot-net-sauce
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathiOSExamples.cs
97 lines (86 loc) · 3.9 KB
/
iOSExamples.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using Common.SauceLabs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace Core.Appium.Examples.RealDevices.NativeApp.LegacyRdc
{
[TestClass]
public class IOSExamples
{
private static string RdcUsHubUrl => "https://us1.appium.testobject.com/wd/hub";
public const string APPIUM_VERSION = "1.16.0";
private IOSDriver<IOSElement> _driver;
private SessionId _sessionId;
public TestContext TestContext { get; set; }
[TestCleanup]
public void Teardown()
{
if (_driver == null) return;
_sessionId = _driver.SessionId;
_driver.Quit();
new SimpleSauce().Rdc.UpdateTestStatus(GetTestStatus(), _sessionId);
}
[TestMethod]
[TestCategory("Rdc")]
[TestCategory("NativeApp")]
[TestCategory("iOS")]
public void AnyIPhone()
{
var capabilities = new AppiumOptions();
//We can run on any iPhone Device
capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPhone.*");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
//TODO it's a best practice to set the appium version so that you're always getting the latest
capabilities.AddAdditionalCapability("appiumVersion", APPIUM_VERSION);
/*
* !!!!!!
* TODO first you must upload an app to RDC so that you get your app key
* Then, make sure you can hardcode it here just to get started
*/
capabilities.AddAdditionalCapability("testobject_api_key", new ApiKeys().Rdc.Apps.SampleAppIOS);
capabilities.AddAdditionalCapability("name", TestContext.TestName);
capabilities.AddAdditionalCapability("newCommandTimeout", 90);
//60 seconds for the connection timeout
_driver = new IOSDriver<IOSElement>(new Uri(RdcUsHubUrl), capabilities);
Assert.IsTrue(IsLoginButtonDisplayed());
}
[TestMethod]
[TestCategory("Rdc")]
[TestCategory("NativeApp")]
[TestCategory("iOS")]
public void IOS13()
{
var capabilities = new AppiumOptions();
//We can run on any iPhone Device
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "13");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
//TODO it's a best practice to set the appium version so that you're always getting the latest
capabilities.AddAdditionalCapability("appiumVersion", APPIUM_VERSION);
/*
* !!!!!!
* TODO first you must upload an app to RDC so that you get your app key
* Then, make sure you can hardcode it here just to get started
*/
capabilities.AddAdditionalCapability("testobject_api_key", new ApiKeys().Rdc.Apps.SampleAppIOS);
capabilities.AddAdditionalCapability("name", TestContext.TestName);
capabilities.AddAdditionalCapability("newCommandTimeout", 90);
//60 seconds for the connection timeout
_driver = new IOSDriver<IOSElement>(new Uri(RdcUsHubUrl), capabilities);
Assert.IsTrue(IsLoginButtonDisplayed());
}
private bool IsLoginButtonDisplayed()
{
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
var loginButton = wait.Until(ExpectedConditions.ElementIsVisible(MobileBy.AccessibilityId("test-LOGIN")));
return loginButton.Displayed;
}
private bool GetTestStatus()
{
return TestContext.CurrentTestOutcome == UnitTestOutcome.Passed;
}
}
}