-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathRemoteWebDriverTest.cs
More file actions
161 lines (131 loc) · 6.14 KB
/
RemoteWebDriverTest.cs
File metadata and controls
161 lines (131 loc) · 6.14 KB
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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using NUnit.Framework;
using System.IO;
namespace PerfectoLabSeleniumTestProject3
{
/// <summary>
/// Summary description for RemoteWebDriverTest
///
/// For programming samples and updated templates refer to the Perfecto GitHub at: https://github.com/PerfectoCode
/// </summary>
[TestFixture("Android", "6.0.1", "ShirPhilipp")]
[TestFixture("iOS", "9.2.1", "Shir Philipp")]
[Parallelizable(ParallelScope.Fixtures)]
public class RemoteWebDriverTest
{
private RemoteWebDriverExtended driver;
String deviceOS, deviceVersion, deviceDescription;
String executionID;
public RemoteWebDriverTest(String deviceOS, String deviceVersion, String deviceDescription)
{
this.deviceOS = deviceOS;
this.deviceVersion = deviceVersion;
this.deviceDescription = deviceDescription;
}
[SetUp]
public void PerfectoOpenConnection()
{
var browserName = "mobileOS";
var host = "demo.perfectomobile.com";
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, string.Empty, new Platform(PlatformType.Any));
capabilities.SetCapability("user", "");
//TODO: Provide your password
capabilities.SetCapability("password", "");
//TODO: Provide your device ID
capabilities.SetCapability("platformName", deviceOS);
Console.WriteLine(this.deviceOS + this.deviceVersion + this.deviceDescription);
capabilities.SetCapability("platformVersion", deviceVersion);
capabilities.SetCapability("description", deviceDescription);
capabilities.SetPerfectoLabExecutionId(host);
// Add a persona to your script (see https://community.perfectomobile.com/posts/1048047-available-personas)
//capabilities.SetCapability(WindTunnelUtils.WIND_TUNNEL_PERSONA_CAPABILITY, WindTunnelUtils.GEORGIA);
// Name your script
capabilities.SetCapability("scriptName", "VSSimpleFixture_"+deviceOS);
var url = new Uri(string.Format("https://{0}/nexperience/perfectomobile/wd/hub", host));
System.Threading.Thread.Sleep(2000);
driver = new RemoteWebDriverExtended(new HttpAuthenticatedCommandExecutor(url), capabilities);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(40));
ICapabilities cap = driver.Capabilities;
executionID = (String)cap.GetCapability("executionId");
Console.WriteLine(executionID);
}
[TearDown]
public void PerfectoCloseConnection()
{
// Retrieve the URL of the Single Test Report, can be saved to your execution summary and used to download the report at a later point
string reportUrl = (string)(driver.Capabilities.GetCapability(WindTunnelUtils.SINGLE_TEST_REPORT_URL_CAPABILITY));
Console.WriteLine(reportUrl);
driver.Close();
// In case you want to download the report or the report attachments, do it here.
try
{
driver.DownloadReport(DownloadReportTypes.pdf, "C:\\reports\\report"+executionID);
// 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();
}
[TestCase("myuser", "mypassword", ExpectedResult = true)]
[TestCase("user2", "mypassword", ExpectedResult = false)]
public Boolean NavigatingToUrl(String appUsername, string appPassword)
{
driver.Navigate().GoToUrl("bbc.co.uk");
System.Threading.Thread.Sleep(3000);
driver.Context = "WEBVIEW";
driver.FindElementByXPath("//*[@id=\"idcta-link\"]").Click();
Dictionary<String, Object> params7 = new Dictionary<String, Object>();
params7.Add("content", "Sign in");
params7.Add("timeout", "30");
Object result7 = driver.ExecuteScript("mobile:checkpoint:text", params7);
driver.FindElementByXPath("//*[@id=\"username-input\"]").SendKeys(appUsername);
driver.FindElementByXPath("//*[@id=\"password-input\"]").SendKeys(appPassword);
driver.FindElementByXPath("//*[@id=\"submit-button\"]").Click();
System.Threading.Thread.Sleep(3000);
ReadOnlyCollection<IWebElement> elements1 = driver.FindElementsByXPath("//*[text()=\"Sorry, your account is locked\"]");
Console.WriteLine("Is account locked? " +elements1.Count);
return elements1.Count > 0;
}
}
public class CsvReader : IDisposable
{
private string path;
private string[] currentData;
private StreamReader reader;
public CsvReader(string path)
{
if (!File.Exists(path)) throw new InvalidOperationException("path does not exist");
this.path = path;
Initialize();
}
private void Initialize()
{
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
reader = new StreamReader(stream);
}
public bool Next()
{
string current = null;
if ((current = reader.ReadLine()) == null) return false;
currentData = current.Split(',');
return true;
}
public string this[int index]
{
get { return currentData[index]; }
}
public void Dispose()
{
reader.Close();
}
}
}