title: How to open an browser using the same session in Selenium Webdriver?
body: <p>I have an application automation framework where the application is actually being treated as a browser. Now, here is my functionality.</p>
  
  <p>Normally it launches the login page always. Now my test case requires that I crash the application first and then relaunch it which will direct to some 'error report' page instead of launching the login page this time. </p>
  
  <p>If I do this from command prompt this functionality works fine because every command prompt window is a session, so basically it crashes and reopens in the same session.</p>
  
  <p>Now this does not work when running through webdriver, because everytime the @BeforeClass runs, it creates a new instance of the application and hence i directs to the login page again instead of directing to the error page.</p>
  
  <p>Any suggestions on how to achieve crashing and repoening the app in the same session would be of great help. I am only providing a small portion of the code from where the driver is being invoked.</p>
  
  <pre><code>protected void setupChromeRemoteDriver(String hubUrl, String platformName) throws IOException {
  
          Platform platform = (platformName != null) ? Platform.valueOf(platformName) : Platform.ANY;
  
          DesiredCapabilities capabilities = DesiredCapabilities.chrome();
          capabilities.setBrowserName("chrome");
          capabilities.setPlatform(platform);
          capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
  
          Set&lt;Cookie&gt; cookies = driver.manage().getCookies();
          for(Cookie cookie : cookies){
              driver.manage().addCookie(cookie);
          }
  
          driver = new CustomRemoteWebDriver(new URL(hubUrl), capabilities);
          driver.manage().window().maximize();
          driver.manage().timeouts().implicitlyWait(Constants.ELEMENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
      }
  </code></pre>
  
  <p><strong>CrashApplication.java</strong></p>
  
  <pre><code>public void crashUTAApp(){
          String filePath = Constants.CRASHAPP_BATCHFILE_LOCATION;
          try{
              Process process = Runtime.getRuntime().exec(filePath); 
              if(null != process &amp;&amp; process.waitFor() == 0 &amp;&amp; process.exitValue() == 0){
                  Reporter.log("App Crashed");
              }else{
                  Reporter.log("Failed to crash app");
              }
          }catch(Exception e){
              e.printStackTrace();
          }
      } 
  </code></pre>