forked from nikolay-advolodkin/dot-net-sauce
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathGetStartedIos.cs
62 lines (53 loc) · 2.58 KB
/
GetStartedIos.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
using System;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.iOS;
namespace Appium4.NUnit.Scripts.RealDevices.NativeApp.UP
{
[TestFixture]
[Parallelizable]
public class GetStartedIos
{
private static string HubUrl => "ondemand.us-west-1.saucelabs.com/wd/hub";
private IOSDriver<IOSElement> _driver;
[Test]
[Category("SimpleTest")]
[Category("NativeApp")]
public void ShouldOpenNativeIosApp()
{
var sauceUser = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);
var uri = $"https://{sauceUser}:{sauceAccessKey}@{HubUrl}";
var capabilities = new AppiumOptions();
//We can run on any version of the platform as long as it's the correct device
//Make sure to pick an Android or iOS device based on your app
capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPhone 11 Pro Max");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
capabilities.AddAdditionalCapability(MobileCapabilityType.Language, "en");
capabilities.AddAdditionalCapability("name", TestContext.CurrentContext.Test.Name);
/*
* You need to upload your own Native Mobile App to Sauce Storage!
* https://wiki.saucelabs.com/display/DOCS/Uploading+your+Application+to+Sauce+Storage
* You can use either storage:<app-id> or storage:filename=
*/
capabilities.AddAdditionalCapability("app",
"storage:filename=iOS.RealDevice.SauceLabs.Mobile.Sample.app.2.7.0.ipa");
//60 seconds for the connection timeout
_driver = new IOSDriver<IOSElement>(new Uri(uri), capabilities);
var windowHeight = int.Parse(_driver.Manage().Window.Size.Height.ToString());
Assert.Greater(windowHeight, 0);
}
//Never forget to pass the test status to Sauce Labs
[TearDown]
public void Teardown()
{
if (_driver == null) return;
var isTestPassed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed;
((IJavaScriptExecutor)_driver).ExecuteScript("sauce:job-result=" + (isTestPassed ? "passed" : "failed"));
_driver.Quit();
}
}
}