forked from nikolay-advolodkin/dot-net-sauce
-
Notifications
You must be signed in to change notification settings - Fork 33
/
CustomCapabilitiesTests.cs
119 lines (109 loc) · 4.74 KB
/
CustomCapabilitiesTests.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
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
using System;
using System.Collections.Generic;
using Common.SauceLabs;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace Selenium3.Nunit.Scripts.SaucePerformance
{
[TestFixture]
[Category("performance")]
public class CustomCapabilitiesTests
{
public RemoteWebDriver Driver { get; set; }
[Test]
public void NetworkThrottleOffline()
{
var throttleCondition = new Dictionary<string, object>
{
["condition"] = "offline"
};
((IJavaScriptExecutor)Driver).ExecuteScript("sauce:throttleNetwork", throttleCondition);
Driver.Navigate().GoToUrl("http://www.saucedemo.com");
Assert.Throws<WebDriverTimeoutException>(() => isDisplayed());
}
private bool isDisplayed()
{
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
return wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("btn_action"))).Displayed;
}
[Test]
public void NetworkThrottle3G()
{
var throttleCondition = new Dictionary<string, object>
{
["condition"] = "Regular 3G"
};
((IJavaScriptExecutor)Driver).ExecuteScript("sauce:throttleNetwork", throttleCondition);
Driver.Navigate().GoToUrl("http://www.saucedemo.com");
}
[Test]
[Description("Broken, there's a bug")]
public void ReplaceImages()
{
Driver.Navigate().GoToUrl("http://www.wswebcreation.nl/");
var sauceInterceptConditions = new Dictionary<string, object>
{
["url"] = "**/*.jpg",
["redirect"] = "https://www.tvvantoen.nl/wp-content/themes/website/data/php/timthumb.php?src=https://www.tvvantoen.nl/wp-content/uploads/the-a-team-poster.jpg&w=700&q=100"
};
((IJavaScriptExecutor)Driver).ExecuteScript("sauce:intercept", sauceInterceptConditions);
Driver.Navigate().GoToUrl("http://www.wswebcreation.nl/");
}
[Test]
public void ReplaceSingleImage()
{
Driver.Navigate().GoToUrl("https://www.saucedemo.com/inventory.html");
var sauceInterceptConditions = new Dictionary<string, object>
{
["url"] = "https://www.saucedemo.com/img/sauce-backpack-1200x1500.jpg",
["redirect"] = "https://i.pinimg.com/originals/be/82/15/be821544fc5f328567cb538f96edb49a.jpg"
};
((IJavaScriptExecutor)Driver).ExecuteScript("sauce:intercept", sauceInterceptConditions);
Driver.Navigate().GoToUrl("https://www.saucedemo.com/inventory.html");
}
[Test]
public void GetSauceMetrics()
{
//https://wiki.saucelabs.com/display/DOCS/Custom+Sauce+Labs+WebDriver+Extensions+for+Network+and+Log+Commands
//this works
var performanceMetrics = new Dictionary<string, object>();
performanceMetrics["type"] = "sauce:metrics";
var output = ((IJavaScriptExecutor)Driver).ExecuteScript("sauce:log", performanceMetrics);
((IJavaScriptExecutor)Driver).ExecuteScript("sauce:network");
}
[SetUp]
public void RunBeforeEveryTest()
{
var sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);
var chromeOptions = new ChromeOptions()
{
BrowserVersion = "latest",
PlatformName = "Windows 10",
UseSpecCompliantProtocol = true
};
var sauceOptions = new Dictionary<string, object>
{
["username"] = sauceUserName,
["accessKey"] = sauceAccessKey,
["name"] = TestContext.CurrentContext.Test.Name,
["extendedDebugging"] = true,
["capturePerformance"] = true,
["crmuxdriverVersion"] = "beta"
};
chromeOptions.AddAdditionalCapability("sauce:options", sauceOptions, true);
Driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"),
chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(600));
}
[TearDown]
public void CleanUp()
{
var isPassed = TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed;
new SauceJavaScriptExecutor(Driver).LogTestStatus(isPassed);
Driver.Quit();
}
}
}