Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathRemoteWebDriverTest.cs
More file actions
Latest commit
161 lines (131 loc) · 6.14 KB
/
Copy pathRemoteWebDriverTest.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
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Collections.ObjectModel;
usingSystem.Diagnostics;
usingSystem.Threading;
usingOpenQA.Selenium;
usingOpenQA.Selenium.Remote;
usingNUnit.Framework;
usingSystem.IO;
namespacePerfectoLabSeleniumTestProject3
{
/// <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)]
publicclassRemoteWebDriverTest
{
privateRemoteWebDriverExtendeddriver;
StringdeviceOS,deviceVersion,deviceDescription;
StringexecutionID;
publicRemoteWebDriverTest(StringdeviceOS,StringdeviceVersion,StringdeviceDescription)
{
this.deviceOS=deviceOS;
this.deviceVersion=deviceVersion;
this.deviceDescription=deviceDescription;
}
[SetUp]
publicvoidPerfectoOpenConnection()
{
varbrowserName="mobileOS";
varhost="demo.perfectomobile.com";
DesiredCapabilitiescapabilities=newDesiredCapabilities(browserName,string.Empty,newPlatform(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);
varurl=newUri(string.Format("https://{0}/nexperience/perfectomobile/wd/hub",host));
System.Threading.Thread.Sleep(2000);
driver=newRemoteWebDriverExtended(newHttpAuthenticatedCommandExecutor(url),capabilities);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(40));
ICapabilitiescap=driver.Capabilities;
executionID=(String)cap.GetCapability("executionId");
Console.WriteLine(executionID);
}
[TearDown]
publicvoidPerfectoCloseConnection()
{
// 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
stringreportUrl=(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(Exceptionex)
{
Trace.WriteLine(string.Format("Error getting test logs: {0}",ex.Message));
}
driver.Quit();
}
[TestCase("myuser","mypassword",ExpectedResult=true)]
[TestCase("user2","mypassword",ExpectedResult=false)]
publicBooleanNavigatingToUrl(StringappUsername,stringappPassword)
{
driver.Navigate().GoToUrl("bbc.co.uk");
System.Threading.Thread.Sleep(3000);
driver.Context="WEBVIEW";
driver.FindElementByXPath("//*[@id=\"idcta-link\"]").Click();
Dictionary<String,Object>params7=newDictionary<String,Object>();
params7.Add("content","Sign in");
params7.Add("timeout","30");
Objectresult7=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);
returnelements1.Count>0;
}
}
publicclassCsvReader:IDisposable
{
privatestringpath;
privatestring[]currentData;
privateStreamReaderreader;
publicCsvReader(stringpath)
{
if(!File.Exists(path))thrownewInvalidOperationException("path does not exist");
this.path=path;
Initialize();
}
privatevoidInitialize()
{
FileStreamstream=newFileStream(path,FileMode.Open,FileAccess.Read);
reader=newStreamReader(stream);
}
publicboolNext()
{
stringcurrent=null;
if((current=reader.ReadLine())==null)returnfalse;
currentData=current.Split(',');
returntrue;
}
publicstringthis[intindex]
{
get{returncurrentData[index];}
}
publicvoidDispose()
{
reader.Close();
}
}
}