How might I simulate a private browsing experience in Watir? (Selenium) - ruby

Watir is a Selenium-based black-box testing tool that can automate tasks on the browser.
I would like to be able to open up a Watir::Browser.new that is in private browsing mode.
Thanks

For Firefox (I am not sure about the other browsers), you can setup the profile to have private browsing enabled:
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.privatebrowsing.dont_prompt_on_enter'] = true
profile['browser.privatebrowsing.autostart'] = true
b = Watir::Browser.new :firefox, :profile => profile
This was the solution from https://github.com/watir/watir-webdriver/issues/95.
It seems to work (at least the main menu says it is private browsing).

For Chrome
browser = Watir::Browser.new :chrome, switches: ['--incognito']

Related

How to launch IE inPrivate browsing with Ruby and Watir

I need to launch the Watir IE browser inPrivate mode.
Chrome`s icognito mode can be launched fairly easily with:
#browser = Watir::Browser.new :chrome, switches: ['--incognito']
I tried this in IE, but it doesn`t work
#browser = Watir::Browser.new :ie, switches: ['-private']
I tried some of the indications here, but did not succeed
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
with
ie.forceCreateProcessApi with true value and ie.browserCommandLineSwitches with -private

Watir with Firefox 48 - How do I use a custom profile?

I can't seem to find anything about this, and I'm starting to get upset, because this code used to work:
browser = Watir::Browser.new :firefox, :profile => "Anna"
However, now that code, while it will launch firefox successfully if I use :marionette => true, if I use :profile => "Anna" or even if I do this:
caps = Selenium::WebDriver::Remote::Capabilities.firefox({:profile => profile,:marionette=> true})
browser = Watir::Browser.new :firefox, :desired_capabilities => caps
Watir will still launch firefox and work properly, but it is still using its own profile. I have custom x509 certificates I need to use in that profile (and the site is throwing "This site is not secure" screens at me because it's still in development), so how can I use it? I know there's a way to do it, but I've been Googling for an hour now and have yet to find it. Removing :marionette => true will let the profile load properly, but since Firefox 48 doesn't support the old Firefox driver, I can't make it work.

How to update Capybara profile?

I am using code like this to set up Capybara profile:
Capybara.register_driver :selenium_focus do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
end
Later in the setup process, I want to update the profile. For example:
profile["focusmanager.testmode"] = true
How to update the profile after it has been set up with profile["focusmanager.testmode"] = true?
It's not really possible. The easiest solution is to register 2 drivers with the different settings wanted and then use the correct driver for each test

Watir with Tor browser

I've been playing with Watir and Tor browser and I can't get them to work.
The correct browser opens, however, I'm unable to open a website.
My code:
Selenium::WebDriver::Firefox.path = '\path\Tor Browser\Start Tor Browser.exe'
driver = Selenium::WebDriver.for :firefox
browser = Watir::Browser.new :firefox, :driver => driver
This results in a message box popping up, which says:
Your Firefox profile cannot be loaded. It may be missing or inaccessible.
The correct browser also opens up, however, the website doesn't.
I've also tried:
Selenium::WebDriver::Firefox.path = '\path\Tor Browser\Browser\firefox.exe'
driver = Selenium::WebDriver.for :firefox
browser = Watir::Browser.new :firefox, :driver => driver
With this, the message box doesn't appear, but still, the website is not loaded.
I'm not sure, if the problem is in my code or in the browser.
Thank you very much for any help!
Start Tor then run this, assuming your socks port is 9050
require 'watir-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.socks'] = "127.0.0.1"
profile['network.proxy.socks_port'] = 9050
profile['network.proxy.type'] = 1
$browser = Watir::Browser.new :firefox, :profile => profile
$browser.goto "whatsmyip.org"
Firefox and Tor are not the same browser. Watir uses webdriver API to control the browser. You can't use Firefox webdriver API to control another browser.
In your second example, browser don't open the site, but you don't tell him to. You should add :
browser.goto('http://my.example.com')
And don't forget to put a browser.quit at the end of your code to close the browser.

Using default Firefox profile in Watir Webdriver but switching off JavaScript

I would like to use my default profile in firefox when watir-webdriver launches a friefox browser, but then I want to switch off javascript in that browser this way:
browser = Watir::Browser.new :ff, :profile => "default"
browser.profile['javascript.enabled']=false
The second reference doesn't work, because the "profile" is not a member of the browser object. How can I access it? Or any other method to switch off javascript either in the default profile or in the running firefox window? I want to do this programmatically, because at the end of my Ruby script I would like to switch it on again.
I think you would do it like this:
profile = Selenium::WebDriver::Firefox::Profile.new
profile['javascript.enabled'] = false
browser = Watir::Browser.new :ff, :profile => profile

Resources