|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using NUnit.Framework; |
5 | | - |
6 | | -namespace SimpleBrowser.UnitTests.OfflineTests |
7 | | -{ |
8 | | - [TestFixture] |
9 | | - public class WindowsAndFrames |
10 | | - { |
11 | | - [Test] |
12 | | - public void Clicking_Target_Blank() |
13 | | - { |
14 | | - Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
15 | | - HttpRequestLog lastRequest = null; |
16 | | - b.RequestLogged += (br, l) => |
17 | | - { |
18 | | - lastRequest = l; |
19 | | - }; |
20 | | - b.Navigate("http://localhost/movies/"); |
21 | | - Assert.That(b.Url == new Uri("http://localhost/movies/")); |
22 | | - var link = b.Find(ElementType.Anchor, FindBy.Text, "About us"); |
23 | | - link.Click(); |
24 | | - Assert.That(b.Url == new Uri("http://localhost/movies/")); |
25 | | - Assert.That(b.Windows.Count() == 2); |
26 | | - link.Click(); |
27 | | - Assert.That(b.Windows.Count() == 3); |
28 | | - var newBrowserWindow = b.Windows.First(br => br.WindowHandle != b.WindowHandle); |
29 | | - Assert.That(newBrowserWindow.Url == new Uri("http://localhost/movies/About")); |
30 | | - } |
31 | | - |
32 | | - [Test] |
33 | | - public void Holding_Ctrl_Shft_Opens_New_Window() |
34 | | - { |
35 | | - Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
36 | | - HttpRequestLog lastRequest = null; |
37 | | - b.RequestLogged += (br, l) => |
38 | | - { |
39 | | - lastRequest = l; |
40 | | - }; |
41 | | - b.Navigate("http://localhost/movies/"); |
42 | | - Assert.That(b.Url == new Uri("http://localhost/movies/")); |
43 | | - var link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
44 | | - link.Click(); |
45 | | - Assert.That(b.Windows.Count() == 1); |
46 | | - link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
47 | | - b.KeyState = KeyStateOption.Ctrl; |
48 | | - link.Click(); |
49 | | - Assert.That(b.Windows.Count() == 2); |
50 | | - link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
51 | | - b.KeyState = KeyStateOption.Shift; |
52 | | - link.Click(); |
53 | | - Assert.That(b.Windows.Count() == 3); |
54 | | - link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
55 | | - b.KeyState = KeyStateOption.Alt; |
56 | | - link.Click(); |
57 | | - Assert.That(b.Windows.Count() == 3); // alt does not open new browser |
58 | | - } |
59 | | - |
60 | | - |
61 | | - [Test] |
62 | | - public void Accessing_New_Windows_Using_Event() |
63 | | - { |
64 | | - Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
65 | | - Browser newlyOpened = null; |
66 | | - b.NewWindowOpened += (b1, b2) => |
67 | | - { |
68 | | - newlyOpened = b2; |
69 | | - }; |
70 | | - b.Navigate("http://localhost/movies/"); |
71 | | - Assert.That(b.Url == new Uri("http://localhost/movies/")); |
72 | | - var link = b.Find(ElementType.Anchor, FindBy.Text, "Details"); |
73 | | - b.KeyState = KeyStateOption.Ctrl; |
74 | | - link.Click(); |
75 | | - Assert.That(b.Windows.Count() == 2); |
76 | | - Assert.NotNull(newlyOpened); |
77 | | - Assert.That(b.Url.ToString() == "http://localhost/movies/"); |
78 | | - Assert.That(newlyOpened.Url.ToString() == "http://localhost/movies/Movies/Details/1"); |
79 | | - } |
80 | | - |
81 | | - |
82 | | - [Test] |
83 | | - public void ClosingBrowsers() |
84 | | - { |
85 | | - Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
86 | | - HttpRequestLog lastRequest = null; |
87 | | - b.RequestLogged += (br, l) => |
88 | | - { |
89 | | - lastRequest = l; |
90 | | - }; |
91 | | - b.Navigate("http://localhost/movies/"); |
92 | | - Assert.That(b.Url == new Uri("http://localhost/movies/")); |
93 | | - var link = b.Find(ElementType.Anchor, FindBy.Text, "About us"); |
94 | | - link.Click(); |
95 | | - Assert.That(b.Url == new Uri("http://localhost/movies/")); |
96 | | - Assert.That(b.Windows.Count() == 2); |
97 | | - b.Close(); |
98 | | - Assert.That(b.Windows.Count() == 1); |
99 | | - b.Windows.First().Close(); |
100 | | - Assert.That(b.Windows.Count() == 0); |
101 | | - Assert.Throws(typeof(ObjectDisposedException), () => { Uri s = b.Url; }); |
102 | | - } |
103 | | - [Test] |
104 | | - public void Page_With_IFrames() |
105 | | - { |
106 | | - Browser b = new Browser(Helper.GetFramesMock()); |
107 | | - HttpRequestLog lastRequest = null; |
108 | | - b.RequestLogged += (br, l) => |
109 | | - { |
110 | | - lastRequest = l; |
111 | | - }; |
112 | | - b.Navigate("http://localhost/"); |
113 | | - Assert.That(b.Frames.Count() == 2); |
114 | | - |
115 | | - // now navigate away to a page without frames |
116 | | - b.Navigate("http://localhost/bla"); |
117 | | - Assert.That(b.Frames.Count() == 0); |
118 | | - Assert.That(b.Windows.Count() == 1); |
119 | | - } |
120 | | - [Test] |
121 | | - public void GetAttribute_Backdoor_FrameHandle() |
122 | | - { |
123 | | - Browser b = new Browser(Helper.GetFramesMock()); |
124 | | - HttpRequestLog lastRequest = null; |
125 | | - b.RequestLogged += (br, l) => |
126 | | - { |
127 | | - lastRequest = l; |
128 | | - }; |
129 | | - b.Navigate("http://localhost/"); |
130 | | - var elm = b.Select("iframe"); |
131 | | - string handle = elm.GetAttribute("SimpleBrowser.WebDriver:frameWindowHandle"); |
132 | | - Assert.AreEqual(handle, "frame1"); |
133 | | - } |
134 | | - [Test] |
135 | | - public void Navigating_IFrames_Using_Target() |
136 | | - { |
137 | | - Browser b = new Browser(Helper.GetFramesMock()); |
138 | | - HttpRequestLog lastRequest = null; |
139 | | - b.RequestLogged += (br, l) => |
140 | | - { |
141 | | - lastRequest = l; |
142 | | - }; |
143 | | - b.Navigate("http://localhost/"); |
144 | | - Assert.That(b.Frames.Count() == 2); |
145 | | - Assert.That(b.Frames.First().Url == new Uri("http://localhost/subdirectory/frame.htm")); |
146 | | - |
147 | | - b.Find("framelink").Click(); |
148 | | - Assert.That(b.Frames.Count() == 2); |
149 | | - Assert.That(b.Url == new Uri("http://localhost/")); |
150 | | - Assert.That(b.Frames.First().Url == new Uri("http://localhost/bla.htm")); |
151 | | - |
152 | | - } |
153 | | - } |
154 | | -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using NUnit.Framework; |
| 5 | + |
| 6 | +namespace SimpleBrowser.UnitTests.OfflineTests |
| 7 | +{ |
| 8 | + [TestFixture] |
| 9 | + public class WindowsAndFrames |
| 10 | + { |
| 11 | + [Test] |
| 12 | + public void Clicking_Target_Blank() |
| 13 | + { |
| 14 | + Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
| 15 | + HttpRequestLog lastRequest = null; |
| 16 | + b.RequestLogged += (br, l) => |
| 17 | + { |
| 18 | + lastRequest = l; |
| 19 | + }; |
| 20 | + b.Navigate("http://localhost/movies/"); |
| 21 | + Assert.That(b.Url == new Uri("http://localhost/movies/")); |
| 22 | + var link = b.Find(ElementType.Anchor, FindBy.Text, "About us"); |
| 23 | + link.Click(); |
| 24 | + Assert.That(b.Url == new Uri("http://localhost/movies/")); |
| 25 | + Assert.That(b.Windows.Count() == 2); |
| 26 | + link.Click(); |
| 27 | + Assert.That(b.Windows.Count() == 3); |
| 28 | + var newBrowserWindow = b.Windows.First(br => br.WindowHandle != b.WindowHandle); |
| 29 | + Assert.That(newBrowserWindow.Url == new Uri("http://localhost/movies/About")); |
| 30 | + } |
| 31 | + |
| 32 | + [Test] |
| 33 | + public void Holding_Ctrl_Shft_Opens_New_Window() |
| 34 | + { |
| 35 | + Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
| 36 | + HttpRequestLog lastRequest = null; |
| 37 | + b.RequestLogged += (br, l) => |
| 38 | + { |
| 39 | + lastRequest = l; |
| 40 | + }; |
| 41 | + b.Navigate("http://localhost/movies/"); |
| 42 | + Assert.That(b.Url == new Uri("http://localhost/movies/")); |
| 43 | + var link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
| 44 | + link.Click(); |
| 45 | + Assert.That(b.Windows.Count() == 1); |
| 46 | + link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
| 47 | + b.KeyState = KeyStateOption.Ctrl; |
| 48 | + link.Click(); |
| 49 | + Assert.That(b.Windows.Count() == 2); |
| 50 | + link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
| 51 | + b.KeyState = KeyStateOption.Shift; |
| 52 | + link.Click(); |
| 53 | + Assert.That(b.Windows.Count() == 3); |
| 54 | + link = b.Find(ElementType.Anchor, FindBy.Text, "Home"); |
| 55 | + b.KeyState = KeyStateOption.Alt; |
| 56 | + link.Click(); |
| 57 | + Assert.That(b.Windows.Count() == 3); // alt does not open new browser |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + [Test] |
| 62 | + public void Accessing_New_Windows_Using_Event() |
| 63 | + { |
| 64 | + Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
| 65 | + Browser newlyOpened = null; |
| 66 | + b.NewWindowOpened += (b1, b2) => |
| 67 | + { |
| 68 | + newlyOpened = b2; |
| 69 | + }; |
| 70 | + b.Navigate("http://localhost/movies/"); |
| 71 | + Assert.That(b.Url == new Uri("http://localhost/movies/")); |
| 72 | + var link = b.Find(ElementType.Anchor, FindBy.Text, "Details"); |
| 73 | + b.KeyState = KeyStateOption.Ctrl; |
| 74 | + link.Click(); |
| 75 | + Assert.That(b.Windows.Count() == 2); |
| 76 | + Assert.NotNull(newlyOpened); |
| 77 | + Assert.That(b.Url.ToString() == "http://localhost/movies/"); |
| 78 | + Assert.That(newlyOpened.Url.ToString() == "http://localhost/movies/Movies/Details/1"); |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + [Test] |
| 83 | + public void ClosingBrowsers() |
| 84 | + { |
| 85 | + Browser b = new Browser(Helper.GetMoviesRequestMocker()); |
| 86 | + HttpRequestLog lastRequest = null; |
| 87 | + b.RequestLogged += (br, l) => |
| 88 | + { |
| 89 | + lastRequest = l; |
| 90 | + }; |
| 91 | + b.Navigate("http://localhost/movies/"); |
| 92 | + Assert.That(b.Url == new Uri("http://localhost/movies/")); |
| 93 | + var link = b.Find(ElementType.Anchor, FindBy.Text, "About us"); |
| 94 | + link.Click(); |
| 95 | + Assert.That(b.Url == new Uri("http://localhost/movies/")); |
| 96 | + Assert.That(b.Windows.Count() == 2); |
| 97 | + b.Close(); |
| 98 | + Assert.That(b.Windows.Count() == 1); |
| 99 | + b.Windows.First().Close(); |
| 100 | + Assert.That(b.Windows.Count() == 0); |
| 101 | + Assert.Throws(typeof(ObjectDisposedException), () => { Uri s = b.Url; }); |
| 102 | + } |
| 103 | + [Test] |
| 104 | + public void Page_With_IFrames() |
| 105 | + { |
| 106 | + Browser b = new Browser(Helper.GetFramesMock()); |
| 107 | + HttpRequestLog lastRequest = null; |
| 108 | + b.RequestLogged += (br, l) => |
| 109 | + { |
| 110 | + lastRequest = l; |
| 111 | + }; |
| 112 | + b.Navigate("http://localhost/"); |
| 113 | + Assert.That(b.Frames.Count() == 2); |
| 114 | + |
| 115 | + // now navigate away to a page without frames |
| 116 | + b.Navigate("http://localhost/bla"); |
| 117 | + Assert.That(b.Frames.Count() == 0); |
| 118 | + Assert.That(b.Windows.Count() == 1); |
| 119 | + } |
| 120 | + [Test] |
| 121 | + public void GetAttribute_Backdoor_FrameHandle() |
| 122 | + { |
| 123 | + Browser b = new Browser(Helper.GetFramesMock()); |
| 124 | + HttpRequestLog lastRequest = null; |
| 125 | + b.RequestLogged += (br, l) => |
| 126 | + { |
| 127 | + lastRequest = l; |
| 128 | + }; |
| 129 | + b.Navigate("http://localhost/"); |
| 130 | + var elm = b.Select("iframe"); |
| 131 | + string handle = elm.GetAttribute("SimpleBrowser.WebDriver:frameWindowHandle"); |
| 132 | + Assert.AreEqual(handle, "frame1"); |
| 133 | + } |
| 134 | + [Test] |
| 135 | + public void Navigating_IFrames_Using_Target() |
| 136 | + { |
| 137 | + Browser b = new Browser(Helper.GetFramesMock()); |
| 138 | + HttpRequestLog lastRequest = null; |
| 139 | + b.RequestLogged += (br, l) => |
| 140 | + { |
| 141 | + lastRequest = l; |
| 142 | + }; |
| 143 | + b.Navigate("http://localhost/"); |
| 144 | + Assert.That(b.Frames.Count() == 2); |
| 145 | + Assert.That(b.Frames.First().Url == new Uri("http://localhost/subdirectory/frame.htm")); |
| 146 | + |
| 147 | + b.Find("framelink").Click(); |
| 148 | + Assert.That(b.Frames.Count() == 2); |
| 149 | + Assert.That(b.Url == new Uri("http://localhost/")); |
| 150 | + Assert.That(b.Frames.First().Url == new Uri("http://localhost/bla.htm")); |
| 151 | + |
| 152 | + } |
| 153 | + [Test] |
| 154 | + public void Static_scoped_clear_works() |
| 155 | + { |
| 156 | + Browser b1 = new Browser(Helper.GetFramesMock()); |
| 157 | + Browser b2 = new Browser(Helper.GetFramesMock()); |
| 158 | + Browser.ClearWindows(); |
| 159 | + Assert.Throws(typeof(ObjectDisposedException), () => b1.Navigate("http://localhost/")); |
| 160 | + } |
| 161 | + [Test] |
| 162 | + public void Instance_scoped_clear_works() |
| 163 | + { |
| 164 | + Browser b1 = new Browser(Helper.GetFramesMock()); |
| 165 | + Browser b2 = new Browser(Helper.GetFramesMock()); |
| 166 | + b2.ClearWindowsInContext(); |
| 167 | + b1.Navigate("http://localhost/"); |
| 168 | + Assert.That(b1.Url.ToString() == "http://localhost/"); |
| 169 | + Assert.Throws(typeof(ObjectDisposedException), () => b2.Navigate("http://localhost/")); |
| 170 | + } |
| 171 | + } |
| 172 | +} |
0 commit comments