-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathBrowserTabsTests.cs
More file actions
182 lines (159 loc) · 5.92 KB
/
Copy pathBrowserTabsTests.cs
File metadata and controls
182 lines (159 loc) · 5.92 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms;
using NUnit.Framework;
using System.Linq;
namespace Aquality.Selenium.Tests.Integration
{
internal class BrowserTabsTests : UITest
{
private readonly WelcomeForm WelcomeForm = new();
protected virtual IBrowserWindowNavigation Tabs => AqualityServices.Browser.Tabs();
[SetUp]
public void Before()
{
WelcomeForm.Open();
}
[Test]
public void Should_BePossibleTo_OpenUrlInNew()
{
var url = WelcomeForm.Url;
var browser = AqualityServices.Browser;
Tabs.OpenInNew(url);
Assert.That(Tabs.Handles.Count, Is.EqualTo(2));
Assert.That(url, Is.EqualTo(browser.Driver.Url));
}
[Test]
public void Should_BePossibleTo_OpenUrlInNew_ViaJs()
{
var url = WelcomeForm.Url;
var browser = AqualityServices.Browser;
Tabs.OpenInNewViaJs(url);
Assert.That(Tabs.Handles.Count, Is.EqualTo(2));
Assert.That(url, Is.EqualTo(browser.Driver.Url));
}
[Test]
public void Should_BePossibleTo_OpenUriInNew()
{
var url = new Uri(WelcomeForm.Url);
var browser = AqualityServices.Browser;
Tabs.OpenInNew(url);
Assert.That(Tabs.Handles.Count, Is.EqualTo(2));
Assert.That(url, Is.EqualTo(new Uri(browser.Driver.Url)));
}
[Test]
public void Should_BePossibleTo_HandleTab()
{
var tabHandle = Tabs.CurrentHandle;
Assert.That(tabHandle, Is.Not.Empty, "Tab name should not be empty");
}
[Test]
public void Should_BePossibleTo_GetTabHandles()
{
var tabHandles = Tabs.Handles;
Assert.That(tabHandles.Count, Is.EqualTo(1), "Tab number should be correct");
Assert.That(tabHandles.First(), Is.Not.Empty, "Tab handle should not be empty");
}
[Test]
public void Should_BePossibleTo_OpenNew()
{
var tabHandle = Tabs.CurrentHandle;
Tabs.OpenNew();
var newTabHandle = Tabs.CurrentHandle;
Assert.That(Tabs.Handles.Count, Is.EqualTo(2), "New tab should be opened");
Assert.That(newTabHandle, Is.Not.EqualTo(tabHandle), "Browser should be switched to new tab");
Tabs.OpenNew(false);
Assert.That(Tabs.Handles.Count, Is.EqualTo(3), "New tab should be opened");
Assert.That(Tabs.CurrentHandle, Is.EqualTo(newTabHandle), "Browser should not be switched to new tab");
}
[Test]
public void Should_BePossibleTo_OpenNew_ViaJs()
{
var tabHandle = Tabs.CurrentHandle;
Tabs.OpenNewViaJs();
var newTabHandle = Tabs.CurrentHandle;
Assert.That(Tabs.Handles.Count, Is.EqualTo(2), "New tab should be opened");
Assert.That(newTabHandle, Is.Not.EqualTo(tabHandle), "Browser should be switched to new tab");
Tabs.OpenNewViaJs(false);
Assert.That(Tabs.Handles.Count, Is.EqualTo(3), "New tab should be opened");
Assert.That(Tabs.CurrentHandle, Is.EqualTo(newTabHandle), "Browser should not be switched to new tab");
}
[Test]
public void Should_BePossibleTo_CloseTab()
{
WelcomeForm.ClickElementalSelenium();
Assert.That(Tabs.Handles.Count, Is.EqualTo(2), "New tab should be opened");
Tabs.Close();
Assert.That(Tabs.Handles.Count, Is.EqualTo(1), "New tab should be closed");
}
[Test]
public void Should_BePossibleTo_SwitchToNew()
{
CheckSwitchingBy(2, () =>
{
Tabs.SwitchToLast();
});
}
[Test]
public void Should_BePossibleTo_SwitchToNew_AndClose()
{
CheckSwitchingBy(1, () =>
{
Tabs.SwitchToLast(true);
});
}
[Test]
public void Should_BePossibleTo_SwitchToNewByHandle()
{
CheckSwitchingBy(3, () =>
{
var tabHandle = Tabs.Handles.Last();
Tabs.OpenNew(false);
Tabs.SwitchTo(tabHandle);
});
}
[Test]
public void Should_BePossibleTo_SwitchToNewByHandle_AndClose()
{
CheckSwitchingBy(2, () =>
{
var tabHandle = Tabs.Handles.Last();
Tabs.OpenNew(false);
Tabs.SwitchTo(tabHandle, true);
});
}
[Test, Category(RetriesGroup), Retry(RetriesCount)]
public void Should_BePossibleTo_SwitchToNewByIndex()
{
CheckSwitchingBy(3, () =>
{
Tabs.OpenNew(false);
Tabs.SwitchTo(1);
});
}
[Test]
public void Should_BePossibleTo_SwitchToNewByIndex_AndClose()
{
CheckSwitchingBy(2, () =>
{
Tabs.OpenNew(false);
Tabs.SwitchTo(1, true);
});
}
[Test]
public void Should_BeThrow_IfSwitchToNew_ByIncorrectIndex()
{
Assert.Throws<ArgumentOutOfRangeException>(() => { Tabs.SwitchTo(10, true); });
}
private void CheckSwitchingBy(int expectedTabCount, Action switchMethod)
{
var tabHandle = Tabs.CurrentHandle;
Assert.That(tabHandle, Is.Not.Empty);
WelcomeForm.ClickElementalSelenium();
var newTabHandle = Tabs.Handles.Last();
switchMethod.Invoke();
Assert.That(Tabs.CurrentHandle, Is.EqualTo(newTabHandle), "Browser should be switched to correct tab");
Assert.That(Tabs.Handles.Count, Is.EqualTo(expectedTabCount), "Number of tabs should be correct");
}
}
}