Chrome switch "disable-internal-flash" does not disable Flash plugin - watir

What could be the reason that Chrome switch "disable-internal-flash" does not actually disable Flash plugin?
require "rubygems"
require "watir-webdriver"
b = Watir::Browser.new :chrome, :switches => %w[--disable-internal-flash]
Is there something wrong with code above or it may be caused by bug in Watir-Webdriver?

try --flash-disable-internal at the end.

This command line switch disabled the Flash plugin in my Chrome 39.0
--disable-bundled-ppapi-flash
Found it in here:
http://peter.sh/experiments/chromium-command-line-switches/#disable-plugins-discovery

Related

Current way of setting language in browsers?

I've been searching for a while about the recommended and current way of creating Watir::Browser.new for :chrome and set it to accept a certain language. However, this seems to be a topic with little interest, seems to be ever changing, etc.
So, please, can someone explain what the current and recommended way of setting Chrome's language is?
I'm not talking about Chrome's user interface but the Accept-Language HTTP header that later gets sent with the HTTP request so that an application can render it's web UI using the correct locale and language.
For Firefox this works but I have no luck for Chrome:
profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] = "ES"
caps = Selenium::WebDriver::Remote::Capabilities.firefox(firefox_profile: profile)
caps.platform = "Linux"
caps.version = 20
browser = Watir::Browser.new :firefox, :desired_capabilities => caps
Thanks.
The "intl.accept_languages" is a Chrome preference, so can be passed in as:
Watir::Browser.new :chrome, options: {prefs: {'intl' => {'accept_languages' => 'ES'}}}

How can I know if browser is Chrome vs Firefox from web extension popup JavaScript?

I am using the chrome namespace for both Chrome and Firefox, but would like to know which browser is running the web extension.
Links to extension resources have different schemes in Chrome and Firefox.
const isFirefox = chrome.runtime.getURL('').startsWith('moz-extension://');
const isChrome = chrome.runtime.getURL('').startsWith('chrome-extension://');
Check chrome.app which is absent in Firefox:
const isFirefox = !chrome.app;
Check for browser which is absent in Chrome:
const isFirefox = window.browser && browser.runtime;
(the additional check is to avoid false positives on pages that have an element with id="browser" that creates a named property on window object for this element)
Use the asynchronous browser.runtime.getBrowserInfo.
P.S. navigator.userAgent may be changed during debugging in devtools when switching to device mode or via about:config option in Firefox so it's an unreliable source.
This is what I do in my own extensions to check for Firefox (FF) vs Chrome:
const FF = typeof browser !== 'undefined';
Update: (1)
Here is an explanation .....
I am using the chrome namespace for both Chrome and Firefox, but would
like to know which browser is running the web extension.
AFA I understand, the question relates to extension code and not content code. I use above code in background script in "firefox-webextensions" or "google-chrome-extension" background script.
From then on then code would be:
if (FF) {...}
else { .... }
Once established, content script has no bearing on it.
In case of a developer who somehow decides to use id="browser" then a further step could be added which returns a boolean true|false e.g.
const FF = typeof browser !== 'undefined' && !!browser.runtime;
Worth nothing that the following returns an object or undefined and not a boolean
const isFirefox = window.browser && browser.runtime;
While it works fine in if() conditionals, it wont work in other situations where a boolean would be required (e.g. switch)
(1) Note: Marking down answers, discourages people from spending time and effort in answering questions in future.

How can I ignore tests when under a particular browser?

My suite of cucumbers gets run on both Firefox and Chrome. Some of them require a browser resize, which is horrible to deal with in Chrome. Since the behaviors that need the resize don't require cross browser testing, I'd like some way to ignore them when the detected browser is Chrome. Is there a way to do this? Perhaps with hooks or in the steps? I'm currently doing the resizing in Before and After hooks.
I don't know which web-driver you are using, but for watir-webdriver you can do the following:
You can determine which browser it is in the steps that you want to skip using the code in the below URL.
http://watirwebdriver.com/determining-which-browser/
Once you determine that it is chrome you can just skip that particular step.
In your test helper, you can add those methods :
def use_chrome_driver
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.current_driver = :selenium_chrome
end
def setup
Capybara.current_driver = :selenium
end
All your tests will use the selenium default webdriver, then when you need to use Chrome, just call the method use_chrome_driver at the beginning of your test like that :
def test_login_with_chrome
use_chrome_driver
...
end
You may also add into your helper your firefox driver with the correct browser size you need, and make it the default selenium browser.

Loading chrome with extension using watir-webdriver gives Timeout error

I have HTML Tidy extension installed in chrome.
When I do:
b = Watir::Browser.new :chrome
The Chrome browser opens up but without extension.
So I used following:
b = Watir::Browser.new (:chrome, :switches => %w[--load-extension=
"C:\Users\.....\AppData\Local\Google\Chrome\UserData\Default\Extensions\gljdonhfjnfdklljmfaabfpjlonflfnm"])
This opens the Chrome browser with an extension
But after few seconds it gives me error:
[0402/141412:ERROR:proxy_launcher.cc(551)] Failed to wait for testing
channel presence. test\automation\proxy_launcher.cc(477): error: Value
of: automation_proxy_.get()
Actual: false Expected: true Timeout::Error: Timeout::Error
I did a search and it looks like a chromedriver bug.
I am using Chromedriver version : 26.0.1383.0
Has anyone come across this issue? Can some one please suggest a work around if one is available?
The Ruby library Nokogiri can check for well formed markup. Then you are not dependant on browser things. You can capture the html from Watir-Webdriver. Or you can capture it from net/http.
require "net/http"
require "uri"
require "nokogiri"
uri = URI.parse("http://www.google.com")
response = Net::HTTP.get_response(uri)
puts parse_body(response.body)
def parse_body(response)
begin
return Nokogiri::XML(response) { |config| config.strict }
rescue Nokogiri::XML::SyntaxError => e
return "caught exception: #{e}"
end
end

Capybara use Internet Explorer as browser rather than Firefox

Hi is it possible to tell Capybara to use IE instead of always defaulting to Firefox?
I have to write some automated tests but the business only supports Internet Explorer so I need the tests to be run on this browser.
Thanks.
As marc_s suggested in the comments, you could try making IE the default browser on your test machine.
I also see some google hits about using Capybara with Selenium (remote control).
If you're interested, check the Selenium docs for how to specify the browser.
Edit It seems the tutorial I posted before was Rack-only. Not sure, but maybe this will work instead:
http://www.johng.co.uk/2010/10/13/run_capybara_and_cucumber_features_in_internet_explorer_on_remote_windows/
Capybara.app_host = "http://192.168.1.37:3000"
Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
Capybara::Driver::Selenium.new(app,
:browser => :remote,
:url => "http://192.168.1.127:4444/wd/hub",
:desired_capabilities => :internet_explorer)
end
It still requires Selenium.
Edit 2:
If you get this error:
Capybara::TimeoutError: failed to resynchronize, ajax request timed out
Then try adding this code to features/step_definitions/mydefiniation.rb:
Before do
page.driver.options[:resynchronize] = false
end
See this question about that specific problem: Using Capybara for AJAX integration tests
Use ->
ignore_mode = opts.delete(:introduce_flakiness_by_ignoring_security_domains) != false
Goto -> External Libraries- selenium-webdriver - lib - selenium - webdriver - ie - bridge.rb
Update module IE -> def initialize
It contains -
ignore_mode = opts.delete(:introduce_flakiness_by_ignoring_security_domains)
just add != false so that it becomes ->
ignore_mode = opts.delete(:introduce_flakiness_by_ignoring_security_domains) != false

Resources