forked from PerfectoCode/Community-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppiumWindTunnel.cs
144 lines (124 loc) · 6.13 KB
/
AppiumWindTunnel.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
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 OpenQA.Selenium.Appium.MultiTouch;
using System.Threading;
using System.Collections.ObjectModel;
namespace KeepRefVars
{
[TestClass]
public class AppiumTest
{
private AndroidDriver<IWebElement> driver;
//private IOSDriver<IWebElement> driver;
[TestInitialize]
public void PerfectoOpenConnection()
{
DesiredCapabilities capabilities = new DesiredCapabilities(string.Empty, string.Empty, new Platform(PlatformType.Any));
var host = <your cloud>;
capabilities.SetCapability("user", <username>);
//TODO: Provide your password
capabilities.SetCapability("password", <password>);
//TODO: Provide your device ID
capabilities.SetCapability("deviceName", <your device>);
// Use this method if you want the script to share the devices with the Perfecto Lab plugin.
capabilities.SetPerfectoLabExecutionId(host);
// Use the automationName capability to defined the required framework - Appium (this is the default) or PerfectoMobile.
//capabilities.SetCapability("automationName", "PerfectoMobile");
// Application settings examples.
// For Android:
capabilities.SetCapability("appPackage", "com.google.android.keep");
// adding a Wind Tunnel persona - Sara
capabilities.SetCapability("windTunnelPersona", "Sara");
var url = new Uri(string.Format("https://{0}/nexperience/perfectomobile/wd/hub", host));
driver = new AndroidDriver<IWebElement>(url, capabilities);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
}
[TestCleanup]
public void PerfectoCloseConnection()
{
driver.Close();
// In case you want to download the report or the report attachments, do it here.
try
{
driver.DownloadReport(DownloadReportTypes.pdf, "C:\\testCS\\report_KeepRefVar");
// 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
By newList = By.XPath("//*[@resource-id='com.google.android.keep:id/new_list_button']");
By titleF = By.XPath("//*[@resource-id='com.google.android.keep:id/editable_title']");
By newItem = By.XPath("//*[@resource-id='com.google.android.keep:id/add_item_text_view']");
By addItem = By.XPath("//*[@resource-id='com.google.android.keep:id/add_item_extra_text_view']");
By descLine = By.XPath("//*[@resource-id='com.google.android.keep:id/description' and @focusable='true']");
IWebElement field;
//first point of interest
WindTunnelUtils.PointOfInterest(driver, "Adding the list", PointOfInterestStatus.Success);
String title = "Test Scripting";
field = driver.FindElement(newList);
field.Click();;
// give the list a title - that can be checked on the main Note-board display
field = driver.FindElement(titleF);
field.SendKeys(title);
// app is now ready to accept text for the first list item
field = driver.FindElement(newItem);
field.Click();
field.SendKeys("Select app to test");
// click the add field
field = driver.FindElement(addItem);
field.Click();
// Enter the second line in the list
field = driver.FindElement(newItem);
field.SendKeys("Write the script");
// click the add field
field = driver.FindElement(addItem);
field.Click();
// return to the Note-board
field = driver.FindElementByClassName("android.widget.ImageButton");
field.Click();
// Second POI - completed the list.
WindTunnelUtils.PointOfInterest(driver, "Completed entry", PointOfInterestStatus.Success);
try
{
//Verify that new note appears on the Note-board
field = driver.FindElementByXPath("//*[@resource-id=\"com.google.android.keep:id/title\" and @text=\"" + title + "\"]");
WindTunnelUtils.PointOfInterest(driver, "Found list on NoteBoard", PointOfInterestStatus.Success);
}
catch (NoSuchElementException f)
{
Trace.WriteLine("Did not find the note on the NoteBoard");
WindTunnelUtils.PointOfInterest(driver, "Failed to find list on NoteBoard", PointOfInterestStatus.Failure);
}
// cleanup the application before closing the connection
String cmnd = "mobile:application:clean";
Dictionary<String, Object> pars = new Dictionary<String, Object>();
pars.Add("name", "keep");
driver.ExecuteScript(cmnd, pars);
}
catch (Exception e)
{
Trace.WriteLine("Script failed with the exception:" + e.Message);
}
}
}
}