|
12 | 12 | import org.openqa.selenium.remote.RemoteWebDriver;
|
13 | 13 | import org.openqa.selenium.testing.JUnit4TestBase;
|
14 | 14 |
|
| 15 | +import java.util.Set; |
| 16 | + |
15 | 17 | import static org.junit.Assert.assertEquals;
|
16 | 18 | import static org.junit.Assert.assertNotNull;
|
17 | 19 | import static org.junit.Assert.assertNull;
|
| 20 | +import static org.junit.Assert.assertTrue; |
18 | 21 | import static org.junit.Assert.fail;
|
19 | 22 | import static org.openqa.selenium.Platform.WINDOWS;
|
20 | 23 | import static org.openqa.selenium.Platform.LINUX;
|
@@ -235,6 +238,79 @@ public void testRestoreSizeAndPosition() {
|
235 | 238 | }
|
236 | 239 | }
|
237 | 240 |
|
| 241 | + @Test |
| 242 | + public void testCanUsedOpenWindowFromPrevSessionIfCapReuseUISetToTrue() { |
| 243 | + |
| 244 | + WebDriver prevDriver = null; |
| 245 | + try { |
| 246 | + DesiredCapabilities caps = DesiredCapabilities.qtwebkit(); |
| 247 | + QtWebDriverExecutor executor = QtWebKitDriver.createDefaultExecutor(); |
| 248 | + prevDriver = new RemoteWebDriver(executor, caps); |
| 249 | + prevDriver.get("qtwidget://XPathElementFindingTestWidget"); |
| 250 | + assertEquals(prevDriver.getTitle(), "Application Window"); |
| 251 | + |
| 252 | + desiredCapabilities.setCapability(QtWebKitDriver.REUSE_UI, true); |
| 253 | + driver = CreateWebDriver(); |
| 254 | + |
| 255 | + Set<String> allWindowHandles = driver.getWindowHandles(); |
| 256 | + assertEquals(2, allWindowHandles.size()); |
| 257 | + |
| 258 | + for (String handle : allWindowHandles) { |
| 259 | + driver.switchTo().window(handle); |
| 260 | + if (driver.getTitle().equals("Application Window")) { |
| 261 | + break; |
| 262 | + } |
| 263 | + } |
| 264 | + assertEquals(driver.getTitle(), "Application Window"); |
| 265 | + |
| 266 | + } catch (RuntimeException e) { |
| 267 | + e.printStackTrace(); |
| 268 | + fail("Should not to be here ..."); |
| 269 | + } finally { |
| 270 | + // if this caps set to 'true' prevDriver will be closed when new driver creates |
| 271 | + } |
| 272 | + } |
| 273 | + |
| 274 | + @Test |
| 275 | + public void testCanNotStartOtherSessionIfCapReuseUISetToFalse() { |
| 276 | + |
| 277 | + desiredCapabilities.setCapability(QtWebKitDriver.REUSE_UI, false); |
| 278 | + WebDriver otherDriver = null; |
| 279 | + try { |
| 280 | + driver = CreateWebDriver(); |
| 281 | + driver.get("qtwidget://XPathElementFindingTestWidget"); |
| 282 | + assertEquals(driver.getTitle(), "Application Window"); |
| 283 | + DesiredCapabilities caps = DesiredCapabilities.qtwebkit(); |
| 284 | + QtWebDriverExecutor executor = QtWebKitDriver.createDefaultExecutor(); |
| 285 | + otherDriver = new RemoteWebDriver(executor, caps); |
| 286 | + fail("Should not have success ..."); |
| 287 | + } catch (RuntimeException e) { |
| 288 | +// expected |
| 289 | + } finally { |
| 290 | + if (otherDriver != null) |
| 291 | + otherDriver.quit(); |
| 292 | + } |
| 293 | + } |
| 294 | + |
| 295 | + @Test |
| 296 | + public void testCanNotStartOtherSessionIfCapReuseUIDoesNotSet() { |
| 297 | + WebDriver otherDriver = null; |
| 298 | + try { |
| 299 | + driver = CreateWebDriver(); |
| 300 | + driver.get("qtwidget://XPathElementFindingTestWidget"); |
| 301 | + assertEquals(driver.getTitle(), "Application Window"); |
| 302 | + DesiredCapabilities caps = DesiredCapabilities.qtwebkit(); |
| 303 | + QtWebDriverExecutor executor = QtWebKitDriver.createDefaultExecutor(); |
| 304 | + otherDriver = new RemoteWebDriver(executor, caps); |
| 305 | + fail("Should not have success ..."); |
| 306 | + } catch (RuntimeException e) { |
| 307 | +// expected |
| 308 | + } finally { |
| 309 | + if (otherDriver != null) |
| 310 | + otherDriver.quit(); |
| 311 | + } |
| 312 | + } |
| 313 | + |
238 | 314 | private DesiredCapabilities desiredCapabilities;
|
239 | 315 | private DesiredCapabilities requiredCapabilities;
|
240 | 316 |
|
|
0 commit comments