-
Notifications
You must be signed in to change notification settings - Fork 55
/
SeleniumHelper.cs
69 lines (61 loc) · 1.99 KB
/
SeleniumHelper.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
using System;
using System.Globalization;
using System.Reflection;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace Structura.GuiTests.SeleniumHelpers
{
//Specflow:
//[Binding]
public class SeleniumHelper
{
private static IWebDriver _driver;
public static void ResetDriver()
{
try
{
if (_driver != null)
{
Driver.Close();
Driver.Quit();
_driver = null;
}
}
catch (Exception ex) { }
}
public static IWebDriver Driver
{
get
{
if (_driver != null)
{
return _driver;
}
_driver = new DriverFactory().Create();
// Avoid synchronization issues by applying timed delay to each step if necessary
_driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMinutes((5)));
_driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMinutes(5));
return _driver;
}
}
//Specflow:
//[AfterTestRun]
public static void AfterTestRun()
{
ResetDriver();
}
public static void Wait(int miliseconds, int maxTimeOutSeconds = 60)
{
var wait = new WebDriverWait(Driver, new TimeSpan(0, 0, 1, maxTimeOutSeconds));
var delay = new TimeSpan(0, 0, 0, 0, miliseconds);
var timestamp = DateTime.Now;
wait.Until(webDriver => (DateTime.Now - timestamp) > delay);
}
public static string GetCosasBuildVersion()
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
var result = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.MinorRevision);
return result;
}
}
}