forked from nikolay-advolodkin/dot-net-sauce
-
Notifications
You must be signed in to change notification settings - Fork 33
/
NewWindow.cs
63 lines (51 loc) · 1.97 KB
/
NewWindow.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
using System;
using System.Collections.Generic;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
namespace Core.Selenium.Examples.Selenium4.NewFeatures
{
[TestClass]
public class NewWindow
{
public IWebDriver Driver { get; set; }
public TestContext TestContext { get; set; }
[TestInitialize]
public void Setup()
{
var browserOptions = new ChromeOptions();
browserOptions.PlatformName = "Windows 10";
browserOptions.BrowserVersion = "latest";
var sauceOptions = new Dictionary<string, object>();
sauceOptions.Add("name", TestContext.TestName);
sauceOptions.Add("username", Environment.GetEnvironmentVariable("SAUCE_USERNAME"));
sauceOptions.Add("accessKey", Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"));
browserOptions.AddAdditionalOption("sauce:options", sauceOptions);
var sauceUrl = new Uri("https://ondemand.us-west-1.saucelabs.com/wd/hub");
Driver = new RemoteWebDriver(sauceUrl, browserOptions);
}
[TestMethod]
public void NewWindowWindow()
{
Driver.SwitchTo().NewWindow(WindowType.Window);
Driver.Manage().Window.Position = new Point(100, 400);
Assert.AreEqual(2, Driver.WindowHandles.Count);
}
[TestMethod]
public void NewWindowTab()
{
Driver.SwitchTo().NewWindow(WindowType.Tab);
Assert.AreEqual(2, Driver.WindowHandles.Count);
}
[TestCleanup]
public void Teardown()
{
var isPassed = TestContext.CurrentTestOutcome == UnitTestOutcome.Passed;
var script = "sauce:job-result=" + (isPassed ? "passed" : "failed");
((IJavaScriptExecutor) Driver).ExecuteScript(script);
Driver?.Quit();
}
}
}