|
42 | 42 |
|
43 | 43 | # switching by name not yet supported by safari
|
44 | 44 | not_compliant_on :browser => [:ie, :iphone, :safari] do
|
| 45 | + after do |
| 46 | + reset_driver! |
| 47 | + end |
| 48 | + |
45 | 49 | it "should switch to a window and back when given a block" do
|
46 | 50 | driver.navigate.to url_for("xhtmlTest.html")
|
47 | 51 |
|
|
54 | 58 |
|
55 | 59 | wait.until { driver.title == "XHTML Test Page" }
|
56 | 60 |
|
57 |
| - reset_driver! |
58 | 61 | end
|
59 | 62 |
|
60 | 63 | it "should handle exceptions inside the block" do
|
|
69 | 72 |
|
70 | 73 | driver.title.should == "XHTML Test Page"
|
71 | 74 |
|
72 |
| - reset_driver! |
73 | 75 | end
|
74 | 76 |
|
75 | 77 | it "should switch to a window" do
|
|
81 | 83 | driver.switch_to.window("result")
|
82 | 84 | wait.until { driver.title == "We Arrive Here" }
|
83 | 85 |
|
84 |
| - reset_driver! |
85 | 86 | end
|
86 | 87 |
|
87 | 88 | it "should use the original window if the block closes the popup" do
|
|
97 | 98 |
|
98 | 99 | driver.current_url.should include("xhtmlTest.html")
|
99 | 100 | driver.title.should == "XHTML Test Page"
|
100 |
| - reset_driver! |
| 101 | + end |
| 102 | + |
| 103 | + it "should close current window when more than two windows exist" do |
| 104 | + driver.navigate.to url_for("xhtmlTest.html") |
| 105 | + driver.find_element(:link, "Create a new anonymous window").click |
| 106 | + driver.find_element(:link, "Open new window").click |
| 107 | + |
| 108 | + expect(driver.window_handles.size).to eq 3 |
| 109 | + |
| 110 | + driver.switch_to.window(driver.window_handle) {driver.close} |
| 111 | + expect(driver.window_handles.size).to eq 2 |
| 112 | + end |
| 113 | + |
| 114 | + it "should close another window when more than two windows exist" do |
| 115 | + driver.navigate.to url_for("xhtmlTest.html") |
| 116 | + driver.find_element(:link, "Create a new anonymous window").click |
| 117 | + driver.find_element(:link, "Open new window").click |
| 118 | + |
| 119 | + expect(driver.window_handles.size).to eq 3 |
| 120 | + |
| 121 | + window_to_close = driver.window_handles.last |
| 122 | + |
| 123 | + driver.switch_to.window(window_to_close) {driver.close} |
| 124 | + expect(driver.window_handles.size).to eq 2 |
| 125 | + end |
| 126 | + |
| 127 | + it "should iterate over open windows when current window is not closed" do |
| 128 | + driver.navigate.to url_for("xhtmlTest.html") |
| 129 | + driver.find_element(:link, "Create a new anonymous window").click |
| 130 | + driver.find_element(:link, "Open new window").click |
| 131 | + |
| 132 | + new_window = driver.window_handles.find do |wh| |
| 133 | + driver.switch_to.window(wh) { driver.title == "We Arrive Here" } |
| 134 | + end |
| 135 | + |
| 136 | + driver.switch_to.window(new_window) |
| 137 | + driver.title.should == "We Arrive Here" |
| 138 | + end |
| 139 | + |
| 140 | + it "should iterate over open windows when current window is closed" do |
| 141 | + driver.navigate.to url_for("xhtmlTest.html") |
| 142 | + driver.find_element(:link, "Create a new anonymous window").click |
| 143 | + driver.find_element(:link, "Open new window").click |
| 144 | + |
| 145 | + driver.close |
| 146 | + |
| 147 | + new_window = driver.window_handles.find do |wh| |
| 148 | + driver.switch_to.window(wh) { driver.title == "We Arrive Here" } |
| 149 | + end |
| 150 | + |
| 151 | + driver.switch_to.window(new_window) |
| 152 | + driver.title.should == "We Arrive Here" |
| 153 | + end |
| 154 | + |
| 155 | + it "should switch to a window and execute a block when current window is closed" do |
| 156 | + driver.navigate.to url_for("xhtmlTest.html") |
| 157 | + driver.find_element(:link, "Open new window").click |
| 158 | + |
| 159 | + driver.switch_to.window("result") |
| 160 | + wait.until { driver.title == "We Arrive Here" } |
| 161 | + |
| 162 | + driver.close |
| 163 | + |
| 164 | + driver.switch_to.window(driver.window_handles.first) do |
| 165 | + wait.until { driver.title == "XHTML Test Page" } |
| 166 | + end |
| 167 | + |
| 168 | + driver.title.should == "XHTML Test Page" |
101 | 169 | end
|
102 | 170 | end
|
103 | 171 |
|
|
0 commit comments