Closing Tabs on default browser/chrome

Chrome, Android.
After a test, in which our app causes a browser to open, (the system default browser has been set to chrome) the number of tabs in that browser eventually grows. How do we close them? A few people have shown how we can happily close all tabs that we open during a test, that’s fine, but driver.close() can only close a handle it knows about or opened already.

  1. It’s impractical to close all browser tabs in test teardown, because sometimes a test will loose connection to the webdriver due to timeout so the driver.close() call is really not going to do anything useful as it does not have all open tabs handles
  2. Resetting the app data/ gets painful because then we need to go through whatever random chrome terms and conditions pop-ups go with that version of chrome. Is this what mostly people do do?
  3. Does not behave as one expects because driver.window_handles , only returns a single handle, it does not return any other tabs that were opened the day before.

Is targeting the browser as a native app and clicking X on all the tabs to the left of the topmost one a working solution? Anyone had luck using send-keys and CTRL+TAB perhaps? Although knt knowing how many times to tab is a mystery still, so if that works, do let us know a strategy that covers using CTRL + TAB.

Maybe try to disable welcome screen stuff for chrome. Then you can safely clear its data

Excellent I had suspected there was a way to do this. You are a font of knowledge on these things.
Will update (I hope) if I do get that to work.

1 Like

With iOS Safary has nice setting on phone to close all tabs every X. I set 1 day with all phones.
With Android i have one reset test in each suite that does some checks like add enough money, install fresh app on phone and so on. And one of step is just start Chrome, tap on tabs number in menu, select all and close them.