0

I want to disable chrome notifications. I know the below code works but driver = new ChromeDriver(ops) invokes a new browser window but....

ChromeOptions ops = new ChromeOptions();
ops.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", "./lib/chromedriver");
driver = new ChromeDriver(ops);

...my Base class below already invokes a browser window:

    @Override
    @Parameters({"baseUrl","seleniumUrl", "browser"})
    @BeforeMethod

    public void onTestSetup(String baseUrl, String seleniumUrl, String browser, ITestContext ctx, Method method)
    {       

   super.onTestSetup(baseUrl, seleniumUrl, browser, ctx, method);
   settings = new Settings();
   driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);  
   driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);   
   homeob = PageFactory.initElements(driver, HomePgObj.class);
}

public synchronized void loginApp(String user, String pwd) throws InterruptedException
{
   homeob = PageFactory.initElements(driver, HomePgObj.class);
   homeob.login(user, pwd);
}

So the problem here using ChromeOptions opens up a second browser window. How can I solve this?

Afsal
  • 404
  • 3
  • 7
  • 24
  • There isn't a way currently to modify chrome options of an already initialized chromerdiver. You might be able to get away with navigating to chrome://settings/ and manually adding certain sites to the blocked list, but this could get hairy since there are a bunch of shadow-roots, so you'd have to do most of it in javascript. If you're interested in that I can whip up some code, but this might be a bit much for your application. – MentallyRecursive Dec 12 '19 at 23:56
  • The easiest thing would be to modify the driver you are getting from your base class. I'm guessing that's not an option? – MentallyRecursive Dec 12 '19 at 23:59
  • Yes, I am unable to modify chromedriver. Changing it from chrome://settings/ won't work too as each time a test is run a new instance of chrome is opened with default settings.@MentallyRecursive – Afsal Dec 13 '19 at 18:46

0 Answers0