ReusableRemoteWebDriver extends RemoteWebDriver { public static RemoteWebDriver fromReusedSession(URL remoteAddress, Capabilities desiredCapabilities, SessionId sessionId) throws UnableReuseSessionException { RemoteWebDriver driver = new ReusableRemoteWebDriver(remoteAddress, desiredCapabilities, sessionId); checkReusability(sessionId, driver); return driver; } ReusableRemoteWebDriver(); protected  ReusableRemoteWebDriver(CommandExecutor executor, Capabilities capabilities, SessionId sessionId); protected  ReusableRemoteWebDriver(URL remoteAddress, Capabilities capabilities, SessionId sessionId); static RemoteWebDriver fromRemoteWebDriver(RemoteWebDriver remoteWebDriver); static RemoteWebDriver fromReusedSession(URL remoteAddress, Capabilities desiredCapabilities,
        SessionId sessionId);  }
@Test public void whenBrowserIsCreatedThenCouldBeReused(@Drone @Reusable RemoteWebDriver driver) throws UnableReuseSessionException { driver.navigate().to(SERVER_URL.toString()); new AugmentingEnhancer().deenhance(driver, Reusable.class); ReusableCapabilities reusedCapabilities = serializeDeserialize(ReusedSession.createReusableCapabilities(driver .getCapabilities())); SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString())); RemoteWebDriver reusedDriver = ReusableRemoteWebDriver.fromReusedSession(HUB_URL, reusedCapabilities.getDesiredCapabilities(), reusedSessionId); reusedDriver.navigate().to(HUB_URL.toString()); }
@Test public void whenBrowserIsCreatedAndQuitAndTriedToReuseThenItShouldThrowException( @Drone @Reusable RemoteWebDriver driver) { driver.navigate().to(SERVER_URL.toString()); new AugmentingEnhancer().deenhance(driver, Reusable.class); ReusableCapabilities reusedCapabilities = serializeDeserialize(ReusedSession.createReusableCapabilities(driver .getCapabilities())); SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString())); driver.quit(); try { ReusableRemoteWebDriver.fromReusedSession(HUB_URL, reusedCapabilities.getDesiredCapabilities(), reusedSessionId); fail("Original driver had quited before, so session should not be reusable"); } catch (UnableReuseSessionException e) { } }