-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitTest1.cs
78 lines (68 loc) · 2.48 KB
/
UnitTest1.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
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using System;
namespace WebkitFailure
{
public class PassingTest
{
public IWebDriver Driver;
private readonly string _CBTusername = "<username>";
private readonly string _CBTauthkey = "<password>";
[SetUp]
public void Setup()
{
var caps = new DesiredCapabilities();
caps.SetCapability("username", _CBTusername);
caps.SetCapability("password", _CBTauthkey);
caps.SetCapability("browserName", "Safari");
// uncomment for passing test
caps.SetCapability("version", "12");
caps.SetCapability("platform", "Mac OSX 10.14");
// uncomment for failing test
//caps.SetCapability("version", "13");
//caps.SetCapability("platform", "Mac OSX 10.15");
caps.SetCapability("screenResolution", "1920x1200");
Driver = new RemoteWebDriver(new Uri("http://hub.crossbrowsertesting.com:80/wd/hub"), caps, TimeSpan.FromSeconds(180));
Driver.Manage().Window.Maximize();
}
private IWebElement ElementClick(IWebElement element)
{
bool elementClickable = true;
if (!element.Displayed) elementClickable = false;
if (!element.Enabled) elementClickable = false;
return elementClickable ? element : null;
}
public IWebElement GetElementOnceClickable(By elementLocator)
{
WebDriverWait wait = new WebDriverWait(Driver, new TimeSpan(0, 0, 60));
IWebElement element = wait.Until((d) =>
{
try
{
return ElementClick(d.FindElement(elementLocator));
}
catch (StaleElementReferenceException)
{
return null;
}
catch (NoSuchElementException)
{
return null;
}
});
return element;
}
[Test]
public void PassingTest1()
{
Driver.Navigate().GoToUrl("https://jsfiddle.net/matthewhorrocks/w42tn053/7/show/");
Driver.SwitchTo().Frame(0);
GetElementOnceClickable(By.Id("show")).Click();
GetElementOnceClickable(By.Id("showme"));
System.Threading.Thread.Sleep(10000);
Driver.Quit();
}
}
}