-
Notifications
You must be signed in to change notification settings - Fork 56
/
AppiumNativeErrandsIos.cs
169 lines (143 loc) · 6.63 KB
/
AppiumNativeErrandsIos.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Remote;
using System.Threading;
using System.Diagnostics;
namespace PrefectoLabTemplateProject
{
[TestClass]
public class AppiumTest
{
private IOSDriver<IWebElement> driver;
[TestInitialize]
public void PerfectoOpenConnection()
{
DesiredCapabilities capabilities = new DesiredCapabilities(string.Empty, string.Empty, new Platform(PlatformType.Any));
var host = <your cloud>;
// Upload the application file to the Repository
PrefectoLabExtension.UploadMedia(host, "[email protected]", "sas17dec",
"C:\\test\\applications\\Errands.ipa", "PRIVATE:applications/Errands.ipa");
capabilities.SetCapability("user", <username>);
capabilities.SetCapability("password", <password>);
// Provide your device ID
capabilities.SetCapability("deviceName", "E0F246F08B30E68780F75B511A52C9B346D7D7B6");
// Use this method if you want the script to share the devices with the Perfecto Lab plugin.
capabilities.SetPrefectoLabExecutionId(host);
// Use the automationName capability to defined the required framework - Appium (this is the default) or PerfectoMobile.
//capabilities.SetCapability("automationName", "PerfectoMobile");
// Application settings examples.
capabilities.SetCapability("app", "PRIVATE:applications/Errands.ipa");
// For iOS:
capabilities.SetCapability("bundleId", "com.yoctoville.errands");
capabilities.SetCapability("autoLaunch", true);
capabilities.SetCapability("fullReset", true);
var url = new Uri(string.Format("https://{0}/nexperience/perfectomobile/wd/hub", host));
//driver = new AndroidDriver<IWebElement>(url, capabilities);
driver = new IOSDriver<IWebElement>(url, capabilities);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
}
[TestCleanup]
public void PerfectoCloseConnection()
{
driver.Close();
// In case you want to down the report or the report attachments, do it here.
try
{
driver.DownloadReport(DownloadReportTypes.pdf, "C:\\testCS\\reportErrands");
// driver.DownloadAttachment(DownloadAttachmentTypes.video, "C:\\test\\report\\video", "flv");
// driver.DownloadAttachment(DownloadAttachmentTypes.image, "C:\\test\\report\\images", "jpg");
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("Error getting test logs: {0}", ex.Message));
}
driver.Quit();
}
[TestMethod]
public void AppiumTestMethod()
{
//Write your test here
try
{
// write your code here
// press Don't Allow button on Notifications screen if it appears
try
{
//IWebElement alert = driver.FindElementByXPath("//UIAAlert[contains(@name, \"Send You Notifications\")]");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));
driver.FindElementByName("Don't Allow").Click();
}
catch (NoSuchElementException n1)
{
Trace.WriteLine("No notifications popup, just plow ahead!");
}
// press OK button on Welcome popup if it appears
try
{
IWebElement header = driver.FindElementByName("Welcome");
IWebElement okBtn = driver.FindElementByName("OK");
okBtn.Click();
}
catch (NoSuchElementException n1)
{
Trace.WriteLine("No welcome popup, just plow ahead!");
}
// Press "New Note" button (on right end of header)
driver.FindElementByName("add os7").Click();
// Verify that arrive at the New Task screen
try
{
IWebElement nTask = driver.FindElementByName("New Task");
}
catch (NoSuchElementException n)
{
Trace.WriteLine("Did not reach New Task window!");
throw n;
}
// Enter a title for the new task
IWebElement title = driver.FindElementByIosUIAutomation("UIATarget.localTarget().frontMostApp().mainWindow().textFields()[0]");
title.SendKeys("Prepare the script for Native Application");
// Enter text into the Details field
IWebElement detail = driver.FindElementByIosUIAutomation(".textFields()[1]");
detail.SendKeys("Select an application, upload, and use Object Spy");
// Click "Done" to go to next stage
driver.FindElementByName("Done").Click();
// Click on the Due Date field to select the due date
try
{
driver.FindElementByXPath("//UIAStaticText[@name='Due Date']").Click();
}
catch (NoSuchElementException n)
{
Trace.WriteLine("Not showing second stage display!");
throw n;
}
// select that task is due next week
driver.FindElementByName("+1 Week").Click();
// Click "Done" to complete the task definition
driver.FindElementByName("Done").Click();
// Verify that task is listed
try
{
IWebElement nTask = driver.FindElementByName("Prepare the script for Native Application");
}
catch (NoSuchElementException n)
{
Trace.WriteLine("The task is not listed!");
throw n;
}
}
catch (Exception e)
{
Trace.WriteLine("Failed due to an exception:" + e.Message);
}
}
}
}