How to run selenium grid with ruby watir? - ruby

I'm working on Ruby Watir project. Currently, I want to execute test script on Selenium grid. My test script is:
caps = Selenium::WebDriver::Remote::Capabilities.chrome
browser = Watir::Browser.new(:remote, url: '<url>:4444/wd/hub', desired_capabilities: caps)
But I got the error message:
NoMethodError: undefined method `remote' for Selenium::WebDriver::Options:Class
Can anyone to help me resolve this problem.
Thanks in advance.

You should be able to use:
browser = Watir::Browser.new(:chrome, url: '<url>:4444/wd/hub')

Related

Setting the headless option for my selenium driver

I'm setting up tests using rspec and capybara within wsl2. I have had to use a remote selenium server because wsl2 can't open browser windows. I would like to set the headless option on my configuration but I am unable to find documentation that would help me.
My code is as follows within rails_helper.rb:
`
Rspec.configure do |config|
config.before(:each, type: :system) do
driven_by :selenium, using: :remote,
options: {
browser: :chrome,
url: 'http://192.168.56.1:4444'}
end
end
`
I want to put something into options like args: 'headless', but that just gives me an unknown keyword error. I've tried looking up documentation in the webdrivers gem, chromedriver, rspec, selenium, and capybara. They either don't have anything or they will have a different format that won't work when I try to include it.
I can't think of any more places to look so I'm asking a question.

Headless Browser (Chrome)maximize issue on jenkins, using cucumber watir

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

How can I hide the Fire Fox browser window when using the Ruby Watir gem? [duplicate]

according to this: https://developer.mozilla.org/en-US/Firefox/Headless_mode firefox 57+, has the ability to run in headless mode.
i tried to use it with this:
omg3r = Watir::Browser.new :firefox, profile: 'omg3r', args: "-headless"
and i couldn't find an example to how to properly send arguments to firefox in watir.
help please
If you are using Watir 6.9 you can try:
omg3r = Watir::Browser.new :firefox, profile: 'omg3r', headless: true
http://watir.com/watir-6-9/
example your browser is in case statement as firefox-remote
when "firefox-remote"
options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
browser = Watir::Browser.new :firefox, options: options

How to write a simple Cucumber script

I'm following the tutorial to run my first Cucumber script:
Feature: guru99 Demopage Login
In order to Login in Demopage we have to enter login details
Scenario:
Register On Guru99 Demopage without email
Given I am on the Guru99 homepage
When enter blank details for register
Then error email shown
I have the project in Idea but when I run it I get errors.
When using chrome:
Failed to open TCP connection to 127.0.0.1:9515 (No connection could be made because the target machine actively refused it.
I have no idea how to resolve it.
When using Firefox, the script successfully opens the browser but fails after that:
require 'watir'
require 'colorize'
Selenium::WebDriver::Firefox::Binary.path='C:\soft\Mozilla Firefox\firefox.exe'
case ENV['BROWSER']
when 'chrome'
browser = Watir::Browser.new :chrome
when 'firefox'
browser = Watir::Browser.new :firefox
end
Given(/^I am on the Guru99 homepage$/)do
#browser = Watir::Browser.new :firefox
#browser.goto "http://demo.guru99.com"
end
When(/^enter blank details for register$/) do
browser.text_filed(:name,"emaiid").set("")
browser.button(:name,"btnLogin").click
end
Then(/^error email shown$/) do
puts "Email is Required!".red
browser.close
end
And returns:
NoMethodError: undefined method `text_filed' for nil:NilClass
on this line:
browser.text_filed(:name,"emaiid").set("")
I found some references that I need to write a class to call a method. I tried it but didn't succeed.
Connection refused, I'm unsure but "Watir+Cucumber Connection refused" looks a fix.
Copy pasta:
AfterConfiguration do |config|
yourCodeStartUp() # Put your SETUP code here including the launch of webdriver
at_exit
yourCodeTearDown() # Put your CLOSING routine here
puts 'stopped'
end
end
The code error is a typo, it should be browser.text_field(...
Regarding the issue you are observing on chrome, it sounds like you need to update chromedriver (and make sure the exe is in PATH). If you are running chrome v56-58, you need ChromeDriver 2.29.
Regarding the NoMethodError: undefined method error, you have a typo when you call the text_field method (i.e. browser.text_filed).
Nope, I was mistaken, I had an older version of chromedriver. Now it's running in chrome as well. Thank you very much. Appreciate your time!
So, the answers are:
1. Update chromedriver.
2. Check your code for typos one more time.
Was really easy but took me a lot of time%

Selenium/Ruby unknown driver, firefox

I wrote a selenium test that I have working in chrome, I'm trying to get selenium to run the test in every browser. When I try and access firefox I get an error though.
Code up to the error...
require "rubygems"
require "selenium-webdriver"
driver = Selenium::WebDriver.for :Firefox
I get the following error on the line where driver is declared...
/Users/username/.rvm/gems/ruby-2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver/common/driver.rb:49:in 'for': unknown driver: :Firefox (ArgumentError)
from /Users/samuelowens/.rvm/gems/ruby-2.1.0/gems/selenium-webdriver-2.39.0/lib/selenium/webdriver.rb:67:in 'for'
from test.rb:47:in `<main>'
Any idea why that might be and how to fix it? Is there an easy way to write a selenium test and check it in multiple browsers? Thanks.
Not capital case Firefox but firefox
driver = Selenium::WebDriver.for :firefox

Resources