-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSauceTest.cs
82 lines (72 loc) · 2.92 KB
/
SauceTest.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
79
80
81
82
using System;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using System.Collections.Generic;
namespace NUnit3_Tutorial
{
[TestFixture("chrome", "46", "Windows 7", "", "")]
[TestFixture("internet explorer", "10", "Windows 7", "", "")]
[TestFixture("firefox", "42", "Windows 8.1", "", "")]
[TestFixture("iPhone", "9.0", "OS X 10.10", "iPad Retina", "landscape")]
[TestFixture("Android", "5.1", "Linux", "Android Emulator", "landscape")]
[TestFixture("Android", "4.4", "Linux", "Android Emulator", "portriat")]
[Parallelizable(ParallelScope.Fixtures)]
public class SauceTest
{
private IWebDriver driver;
private String browser;
private String version;
private String os;
private String deviceName;
private String deviceOrientation;
public SeleniumTest(String browser, String version, String os, String deviceName, String deviceOrientation)
{
this.browser = browser;
this.version = version;
this.os = os;
this.deviceName = deviceName;
this.deviceOrientation = deviceOrientation;
}
[SetUp]
public void Init()
{
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability(CapabilityType.BrowserName, browser);
caps.SetCapability(CapabilityType.Version, version);
caps.SetCapability(CapabilityType.Platform, os);
caps.SetCapability("deviceName", deviceName);
caps.SetCapability("deviceOrientation", deviceOrientation);
caps.SetCapability("username", System.Environment.GetEnvironmentVariable("SAUCE_USERNAME"));
caps.SetCapability("accessKey", System.Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"));
caps.SetCapability("name", TestContext.CurrentContext.Test.Name);
driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps, TimeSpan.FromSeconds(840));
}
[Test]
public void googleTest()
{
driver.Navigate().GoToUrl("http://www.google.com");
StringAssert.Contains("Google", driver.Title);
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Sauce Labs");
query.Submit();
}
[TearDown]
public void CleanUp()
{
bool passed = TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed;
try
{
// Logs the result to Sauce Labs
((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (passed ? "passed" : "failed"));
}
finally
{
// Terminates the remote webdriver session
driver.Quit();
}
}
}
}