Maintain and re-use existing webdriver browser instance - java

前端 未结 4 1331
不思量自难忘°
不思量自难忘° 2021-01-16 03:19

Basically every time I run my java code from eclipse, webdriver launches a new ie browser and executes my tests successfully for the most part. However, I have a lot of test

4条回答
  •  -上瘾入骨i
    2021-01-16 03:31

    Actually you can re-use the same session again..

    In node client you can use following code to attach to existing selenium session

    var browser = wd.remote('http://localhost:4444/wd/hub');
    browser.attach('df606fdd-f4b7-4651-aaba-fe37a39c86e3', function(err, capabilities) {
      // The 'capabilities' object as returned by sessionCapabilities
      if (err) { /* that session doesn't exist */ }
      else {
        browser.elementByCss("button.groovy-button", function(err, el) {
          ...
        });
      }
    });
    ...
    browser.detach();
    

    To get selenium session id,

    driver.getSessionId();
    

    Note: This is available in Node Client only.. To do the same thing in JAVA or C#, you have to override execute method of selenium to capture the sessionId and save it in local file and read it again to attach with existing selenium session

提交回复
热议问题