I am facing the issue that while executing my test script on jenkin machine the headless browser is not maximizing but on my local machine it is working fine.First it was failing on local as well but after using the code :
Before do |scenario|
DataMagic.load_for_scenario(scenario)
#browser = Watir::Browser.new :chrome, headless:true
screen_width = #browser.execute_script("return screen.width;")
screen_height = #browser.execute_script("return screen.height;")
#browser.driver.manage.window.resize_to(screen_width,screen_height)
#browser.driver.manage.window.move_to(0,0)
end
but after using this it worked on local and failed on local. So guys please let me know resolution for the same.
Thanks
Related
I'm using Cuprite driver for Capybara in my Ruby feature specs.
The specs run fine locally but fail with the error, Chrome process did not produce websocket url within 2 seconds, when the specs are run on our CI server. The CI server runs the specs within a Docker container.
The Docker image installs a recent version of Chrome, 77.0, from the Google PPA.
The driver needs to be configured to pass the --no-sandbox option to Chrome:
Capybara.register_driver :cuprite do |app|
browser_options = {}.tap do |opts|
opts['no-sandbox'] = nil if ENV['CI']
end
Capybara::Cuprite::Driver.new(app, browser_options: browser_options)
end
I was just struggling with this issue on GitHub Actions. It turns out that the default process_timeout of 1 second is just too short, so Chrome didn't have time to start on the CI servers. It now works for me after extending process_timeout to a much larger value (20 seconds.) Here's the full code for my Capybara :cuprite driver:
Capybara.register_driver(:cuprite) do |app|
browser_options = {}
browser_options['no-sandbox'] = nil if ENV['CI']
headless = !ENV['SHOW_BROWSER']
Capybara::Cuprite::Driver.new(
app,
browser_options: browser_options,
headless: headless,
process_timeout: 20
)
end
Capybara.javascript_driver = :cuprite
I am using windows 10 32 bit ruby version 233, I am facing these issues with running the tests on a ie 11 browser and the chrome browser for the tests(using page object) that are already running on firefox browser,
ISSUE with IE: Watir::Exception::NoMatchingWindowFoundException:
browser window was closed (eval):1:in `process_watir_call'
ISSUE with Chrome: Errno::ECONNREFUSED: Failed to open TCP connection
to 127.0.0.1:9515 (No connection could be made because the target
machine actively refused it. - connect(2) for "127.0.0.1" port 9515)
i have used the following hooks for ie and chrome:
Before do
case $browser
when 'mozilla'
#browser = Watir::Browser.new :firefox
#browser.window.maximize
when 'chrome'
#browser = Watir::Browser.new :chrome, :profile => "default"
when 'ie'
#browser = Watir::Browser.new :ie
# #browser.window.maximize
# #browser.visible = true
else
#browser = Watir::Browser.new :firefox
#browser.window.maximize
end
# #browser = Watir::Browser.new :firefox
# #browser.window.maximize
# this file contains test data that needs to be changed if tests are being executed in a different environment
$test_data = YAML.load_file('features/support/input_data/data/login_information.yml')
# this file contains base URL that needs to be changed if tests are being executed in a different environment
FigNewton.load('default.yml')
end
I was able to run a small sample test on a separate project from ruby mine with Watir gem.
Is there any way to make it work on the existing firefox tests?
The problem with chrome has been fixed by using the right chromedriver version, but still having problems with the IE using watir.
Found the solution for IE too its something to do with the internet options security and lower down the security level and uncheck the Enable Protected Mode.
I'm developing automated tests with Capybara on ruby. And I'm struggling to solve this error for days. I've tried to change chrome/chromedriver versions to every combination on earth and still getting errors! I've also reinstalled cucumber/ruby/devkit etc..
By the way, my automated tests were working pretty well, and suddenly they were not anymore.
Someone helps please!
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.3/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': session not created exception (Selenium::WebDriver::Error::SessionNotCreatedError)
from disconnected: Unable to receive message from renderer
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10586 x86_64)
require 'capybara'
require 'selenium-webdriver'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome
)
end
Selenium::WebDriver::Chrome.driver_path = 'C:\tools\chromedriver.exe'
Selenium::WebDriver::Chrome.path = 'C:\tools\chrome64_54.0.2840.71\chrome.exe'
Capybara.default_driver = :selenium
url = "https://github.com/jnicklas/capybara"
internet = Capybara::Session.new(:selenium)
internet.visit url
sleep(20)
I would suggest try downgrading your Chrome version to v54 or v50 and try then. From your error log it seems a http request is not being established and so the webdriver is unable to create a session. Integrate a Selenium standalone server in your project and try running the tests then. The latest version is v3.0.1, you can download it from here:
http://www.seleniumhq.org/download/
I'm trying to change webdriver in ruby to open a tor browser instead of the default firefox broswer. I'm using the following code and I have a tor browser open before I run this code.
path='C:\Users\Bonnnie\Downloads\Tor Browser\App\tor.exe'
Selenium::WebDriver::Firefox.path = path
driver = Selenium::WebDriver.for :firefox
I get the following error:
unable to obtain stable firefox connection in 60 seconds
I think I might be linking to the wrong tor file.
The following worked for me with selenium-webdriver 2.48.1 and Tor Browser Bundle 5.0.3 on Ubuntu Linux 15.04.
require 'selenium-webdriver'
tor_dir = '/opt/tor-browser_en-US'
# The Tor binary relies on these shared libraries
ENV['LD_LIBRARY_PATH']= [
File.join(tor_dir, 'Browser/'),
File.join(tor_dir, 'Browser/TorBrowser/Tor/')
].join(':')
Selenium::WebDriver::Firefox::Binary.path =
File.join(tor_dir, 'Browser/firefox')
profile = Selenium::WebDriver::Firefox::Profile.new(
File.join(tor_dir, 'Browser/TorBrowser/Data/Browser/profile.default'))
driver = Selenium::WebDriver.for :firefox, :profile => profile
driver.get('https://check.torproject.org/')
require 'selenium-webdriver'
tor_dir = '/home/me/tor-browser_en-US' # change as necessary
options = Selenium::WebDriver::Firefox::Options.new
options.binary = File.join(tor_dir, 'Browser/firefox')
proxy = Selenium::WebDriver::Proxy.new(socks: '127.0.0.1:9050')
proxy.socks_version = 5
options.proxy = proxy
driver = Selenium::WebDriver.for :firefox, options: options
driver.get('https://check.torproject.org')
driver.title
=> "Congratulations. This browser is configured to use Tor."
I had to set the browser proxy to use my locally running tor, as Selenium evidently doesn't use the one bundled with Tor Browser Bundle. With no proxy set I get Selenium::WebDriver::Error::UnknownError: Reached error page: about:neterror?e=proxyConnectFailure..
I am running cucumber tests with Webrat in external mode that is using Selenium. In production we are running behind https and so we are required to run our cucumber tests on https.
Is there any place we can specify that cucumber, webrat, or selenium needs to be using https? Ideally this could be specified through a parameter that is given to Webrat.
I have seen some stuff that looks like it might be possible if I override the default SeleniumClientDriver that comes bundled under the selenium.rb file.
env.rb =>
Webrat.configure do |config|
config.mode = :selenium
config.aplication_address = 'localhost'
config.aplication_port = 11090
config.selenium_server_address = 'localhost'
config.selenium_server_port = 4444
config.selenium_browser_key = '*iexploreproxy'
config.application_framework = :external
end
World do
session = Webrat::SeleniumSession.new
session.extend(Webrat::Methods)
session.extend(Webrat::Selenium::Methods)
session.extend(Webrat::Selenium::Matchers)
session
end
Thanks for any help!
This apparently is not something that the webrat team has decided to support.
So a team member changed the source to allow that this can be specified through env.rb properties. The pull request can be found here.