0

I know that it doesn't officially work. And most of the crutches found either do not work or are outdated. There are also workers, but there is a need to restart the browser, and it is desirable to avoid this. Help if you know how to solve it.

SL_
  • 1
  • 3
  • Do you mean that you want to use the cache ? –  Mar 20 '22 at 12:27
  • No I want to be able to interact with an open user browser via Selenium. – SL_ Mar 20 '22 at 12:43
  • Yes this is what I mean you want to use the cache in the browser read this post https://sqa.stackexchange.com/questions/45933/how-do-i-enable-chromedriver-to-use-browser-cache-or-local-storage-with-selenium –  Mar 20 '22 at 13:02
  • I may be wrong, but this code still opens a new browser window, and does not make a change to the active one. Perhaps you will understand my question better by reading this. https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session – SL_ Mar 20 '22 at 13:27

1 Answers1

0

I am not sure if I understand your question at the exact mean. However, you can create a base class for setup and launching the browser with the help of automation framework annotations. For example, in TestNG you can create a BaseTests class containing method and annotations:

    public class BaseTests {
    
        protected static WebDriver driver;
        protected static LoginPage loginPage;
    
    @BeforeClass
        public static void setUp() throws InterruptedException {
            System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
            driver = new ChromeDriver();
            driver.get(LOGIN_URL);
            loginPage = new LoginPage(driver);
 public static WebDriver getWebDriver() {
        return driver;
  }
    }

and create other classes that extend the BaseTests class. So you will not have to write to setup the driver and launch the browser in your every test class. In addition, you can add a tearDown method to quit the browser in your BaseTests class. So in every other class that extends BaseTests, the browser will be lunch before tests execution and close after every execution automatically.

Example of tearDown method

@AfterClass
    public static void tearDown() {
        driver.quit();
    }

Again, I am not sure that the point you are asking is this. But I hope it helps.

  • Yes, that's not what I was asking about, I need the browser launched by the user and not webdriver to be controlled by Selenium. As I said before, it can be done this way, https://cosmocode.io/how-to-connect-selenium-to-an-existing-browser-that-was-opened-manually/ but it has its drawbacks. I would like to be able to do it also without restarting the browser. – SL_ Mar 21 '22 at 00:58