-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserStackNUnitTest.cs
More file actions
129 lines (107 loc) · 3.8 KB
/
BrowserStackNUnitTest.cs
File metadata and controls
129 lines (107 loc) · 3.8 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
using NUnit.Framework;
using OpenQA.Selenium.Remote;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using OpenQA.Selenium.Appium.Android;
using BrowserStack;
using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium;
namespace android
{
public class BrowserStackNUnitTest
{
protected AndroidDriver<AndroidElement> driver;
protected string profile;
protected string device;
private Local browserStackLocal;
public BrowserStackNUnitTest(string profile, string device)
{
this.profile = profile;
this.device = device;
}
[SetUp]
public void Init()
{
NameValueCollection caps = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection;
NameValueCollection devices = ConfigurationManager.GetSection("environments/" + device) as NameValueCollection;
DesiredCapabilities capability = new DesiredCapabilities();
foreach (string key in caps.AllKeys)
{
capability.SetCapability(key, caps[key]);
}
foreach (string key in devices.AllKeys)
{
capability.SetCapability(key, devices[key]);
}
String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
if (username == null)
{
username = ConfigurationManager.AppSettings.Get("user");
}
String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
if (accesskey == null)
{
accesskey = ConfigurationManager.AppSettings.Get("key");
}
capability.SetCapability("browserstack.user", username);
capability.SetCapability("browserstack.key", accesskey);
String appId = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_ID");
if (appId != null)
{
capability.SetCapability("app", appId);
}
if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true")
{
browserStackLocal = new Local();
List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("key", accesskey)
};
browserStackLocal.start(bsLocalArgs);
}
driver = new AndroidDriver<AndroidElement>(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capability);
}
public void SWipeUntilelementVisible(string ElementID)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
var SendRequirementForScroll = wait.Until(x => x.FindElements(By.XPath(ElementID)));
bool visible = false;
int counter = 0;
try
{
while (visible == false)
{
if (counter == 0 && visible == false)
{
driver.Swipe(525, 1520, 518, 630, 0);
counter++;
}
else
{
driver.Swipe(525, 1520, 518, 630, 0);
var SendRequirementForScrollTmp = wait.Until(x => x.FindElements(By.XPath(ElementID)));
if (SendRequirementForScrollTmp.Count > 0)
{
counter++;
visible = true;
Console.WriteLine("Element became visible");
break;
}
}
}
}
catch { }
}
[TearDown]
public void Cleanup()
{
driver?.Quit();
if (browserStackLocal != null)
{
browserStackLocal.stop();
}
}
}
}