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

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.

Related

how to set download preferences in watir webdriver for internet explorer....what is the code need to be done

I am using ruby with watir-webdriver.
when downloading a file with chrome,code is there for setting preferences.
What is the procedure for doing the same with internet explorer
i had tried same preference setting that worked for chrome. But it failed in IE.
require 'watir-webdriver'
Watir.default_timeout = 90
prefs = {
:download => {
:prompt_for_download => false,
:default_directory => "#{custom_download_path}"
}
}
$browser = Watir::Browser.new :chrome, :prefs => prefs
IE version :10+
Platform : windows 7..
You should ask yourself what you are really testing here. Beyond 'is the file available and served correctly to a download request', doing file downloads using different browsers starts to be more of a test of the browser itself than your website/server code. This is the sort of test I'd do on a single browser to verify the download link points to the right file, and call it good. For other browsers maybe just verify that the user can see the download link, and that the URL for the download is correct. Or if you really need to examine the file itself, then get the link address, and just download the file with curl or something similar.

Automate Chrome Extensions With Selenium and Ruby

I am currently working on an automation project where I need to use Ruby/Selenium to discover specific http headers returned to the user after authentication to a web app. I am able to automate the web app just fine; however, when I try to use a Chrome extension the browser returns the following error:
The webpage at chrome-extension://[extension address] might be temporarily down or it may have moved permanently to a new web address.
After looking into this, it appears that the Selenium web driver is using a different Chrome profile than my regular Chrome profile. As such, I was wondering if someone knew if there is a way to to tell Selenium to use my regular Chrome profile with the extension loaded or build a new profile and install the extension during runtime.
So far, most of the answers I have found were centralized around Python and Java. Please let me know if I can provide more information.
To launch Chrome with the default profile on Windows:
require 'selenium-webdriver'
switches = ['user-data-dir='+ENV['LOCALAPPDATA']+'\\Google\\Chrome\\User Data']
driver = Selenium::WebDriver.for :chrome, :switches => switches
driver.navigate.to "https://www.google.co.uk"
Or to add an extension to the created profile:
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome,
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome({
'chromeOptions' => {
'extensions' => [
Base64.strict_encode64(File.open('C:\\App\\extension.crx', 'rb').read)
]
}
})
driver.navigate.to "https://www.google.co.uk"

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.

Above the fold screenshots using watir-webdriver

I'm using watir-webdriver for screenshots, and now it is only giving me full site screenshots. How can I see just what is above the fold?
Current code:
driver = Webdriver::UserAgent.driver(:browser => :firefox, :agent => :iphone, :orientation => ;landscape)
browser = Watir::Browser.new driver
browser.goto "http://forefathersgroup.com"
browser.driver.save_screenshot "forefathers.png
There is no way to get only visible part of the page using watir-webdriver, because selenium, which is used in this library does not provide such functionality.
So one of possible solutions is crop a screenshot after its creation

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