-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathWindowsTest.cs
49 lines (43 loc) · 1.77 KB
/
WindowsTest.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Collections.Generic;
namespace SeleniumDocs.Interactions
{
[TestClass]
public class WindowsTest
{
[TestMethod]
public void TestWindowCommands()
{
WebDriver driver = new ChromeDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
// Navigate to Url
driver.Url="https://www.selenium.dev/selenium/web/window_switching_tests/page_with_frame.html";
//fetch handle of this
String currHandle = driver.CurrentWindowHandle;
Assert.IsNotNull(currHandle);
//click on link to open a new window
driver.FindElement(By.LinkText("Open new window")).Click();
//fetch handles of all windows, there will be two, [0]- default, [1] - new window
IList<string> windowHandles = new List<string>(driver.WindowHandles);
driver.SwitchTo().Window(windowHandles[1]);
//assert on title of new window
String title = driver.Title;
Assert.AreEqual("Simple Page", title);
//closing current window
driver.Close();
//Switch back to the old tab or window
driver.SwitchTo().Window(windowHandles[0]);
//Opens a new tab and switches to new tab
driver.SwitchTo().NewWindow(WindowType.Tab);
Assert.AreEqual("", driver.Title);
//Opens a new window and switches to new window
driver.SwitchTo().NewWindow(WindowType.Window);
Assert.AreEqual("", driver.Title);
//quitting driver
driver.Quit(); //close all windows
}
}
}