Popup blocking in Google Chrome causing issues with Capybara/Rspec tests
Asked Answered
P

7

11

I'm writing some automated tests using Capybara/RSpec, I choose/configure the driver by using this little bit of ruby:

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

I'm testing whether or not a button I click is opening a popup window and that the window is displaying the content it should. The issue is that when the test opens the window, the Google Chrome popup blocker blocks it, causing the tests to fail. Disabling the blocker from the options menu does not work. Also, I'm afraid that once I run these on the server it will cause the same issue.

Is there a way to disable the popup block for the tests automatically?

Patronize answered 12/10, 2011 at 15:50 Comment(1)
+1! we're having the same problem when using selenium WebDriver (chromedriver) to run automated tests...Being
B
8

We had a very similar problem. Like John says, the command-line switch no longer works. We tried using a custom profile, but it seemed to be overwritten.

Eventually solved it by manually disabling popups using WebDriver itself:

driver.get('chrome://settings/advanced')
driver.find_element_by_id('privacyContentSettingsButton').click()
driver.find_element_by_name('popups').click()

Which, I guess, is more like what the user would do anyway ;-)

Being answered 27/1, 2012 at 19:16 Comment(2)
I assume this would be done as a precondition test setup() before running the actual test right? Thanks for this tip.Investiture
This is great, but how do you actually find out the element by name? When my browser launches from Selenium, I have no option to right-click and then "Inspect", presumably because the popup itself is preventing me from interacting with the browser. EDIT: I solved my own problem. I can reference the button by its associated text (In my case, "You are not an authorized user"). Then I can use Selenium to click it.Mani
D
8

You can call driver with options.

ChromeOptions options = new ChromeOptions();
options.addArguments("-incognito");
options.addArguments("--disable-popup-blocking");

ChromeDriver driver = new ChromeDriver(options);
Demonolater answered 9/11, 2015 at 9:58 Comment(0)
E
3

Try this:

Capybara::Selenium::Driver.new(app, :browser => :chrome, :switches => %w[--disable-popup-blocking)

This is mentioned on the RubyBindings page on the Selenium wiki.

Enisle answered 12/10, 2011 at 16:19 Comment(2)
I have already tried that but I get the following error: unknown option: {:switches=>["--disable-popup-blocking"]}Patronize
Make sure you're on the latest version of the selenium-webdriver gem.Enisle
E
2

I don't think you can, at the moment. Having the same problem. It doesn't appear that in the current version of chrome, that disabling the popup blocker is a command line switch any more.

http://codesearch.google.com/codesearch#OAMlx_jo-ck/src/chrome/common/chrome_switches.cc&exact_package=chromium

Ellery answered 3/11, 2011 at 2:55 Comment(0)
L
1

JavaScript Version

You can do in JavaScript like so...

var chrome = require('selenium-webdriver/chrome.js');
var options = new chrome
              .Options()
              .addArguments('-incognito', '--disable-popup-blocking');

var driver = new webdriver.Builder()
    .forBrowser('chrome')
    .setChromeOptions(options)
    .build();

driver.manage().timeouts().setScriptTimeout(10000);

return driver;
Loran answered 20/5, 2016 at 14:24 Comment(0)
I
0

To work with latest chrome driver, try this

css_selector_for_iframe = 'iframe[name="settings"]'

driver.get('chrome://settings/content')
iframe = driver.find_element_by_css_selector(css_selector_for_iframe)
driver.switch_to_frame(iframe)
driver.find_element_by_name('popups').click()
click_element(driver, '#content-settings-overlay-confirm')
driver.switch_to_default_content()
Icarus answered 8/3, 2016 at 6:43 Comment(0)
N
-1

I tried the following setting chromeOptions.addArguments("--disable-web-security"); and it works correctly .. It disable all pops up

Nidify answered 24/6, 2019 at 10:5 Comment(1)
"--disable-web-security" sounds like a flag NOT to be switched off just for a popup blocking behaviour...Mandrel

© 2022 - 2024 — McMap. All rights reserved.