Giter VIP home page Giter VIP logo

watir-rails's Introduction

watir

Watir Powered By Selenium!

Gem Version Chrome Tests Edge Tests Firefox Tests IE Tests Safari Tests Unit Tests

Using Watir

This README is for people interested in writing code for Watir or gems in the Watir ecosystem that leverage private-api Watir code.

For our users, everything you'll need is on the Watir website: examples, news, guides, additional resources, support information and more.

Procedure for Patches/Pull Requests

  • Fork the project.
  • Clone onto your local machine.
  • Create a new feature branch (bonus points for good names).
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so we don't unintentionally break it in a future version.
  • Commit, do not change Rakefile, gemspec, or CHANGES files, we'll take care of that on release.
  • Make sure it is passing doctests.
  • Make sure it is passing rubocop.
  • Push to your forked repository.
  • Send a pull request.

Developing Extensions

When developing a gem intended to be used with Watir, you can run your code with WatirSpec to make sure that requiring your code does not break something else in Watir.

First, add WatirSpec Rake tasks to your gem:

# Rakefile
require 'watirspec/rake_tasks'
WatirSpec::RakeTasks.new

Second, initialize WatirSpec for your gem:

$ bundle exec rake watirspec:init

This command will walk you through how to customize your code.

Automatic Element Generation

The majority of element methods Watir provides is autogenerated from specifications. This is done by extracting the IDL parts from the spec and processing them with the WebIDL gem.

Generated elements are currently based on the following specifications:

  • HTML (lib/watir/elements/html_elements.rb)
  • SVG (lib/watir/elements/svg_elements.rb)

To run:

$ bundle exec rake html:update
$ bundle exec rake svg:update

Specs

Github Actions

Watir specs are run with Github Actions.

Watir code is tested on Linux with latest versions of supported browsers and all active Ruby versions.

Doctests

Watir uses yard-doctest to directly test our documentation examples.

mkdir ~/.yard
bundle exec yard config -a autoload_plugins yard-doctest
rake yard:doctest

Coveralls

Watir code is run through Coveralls to encourage PRs to ensure all paths in their code have tests associated with them.

Rubocop

Watir is using Rubocop to ensure a consistent style across the code base. It is run with our minimum supported Ruby version (2.3) We have some established exceptions at .rubocop.yml that might need to be tweaked for new code submissions. This can be addressed in the PR as necessary.

Statistics

Element specs are run with Selenium Statistics gem to verify that changes to the code do not dramatically decrease the performance based on wire calls.

Copyright

See LICENSE for details

watir-rails's People

Contributors

barthez avatar bwilczek avatar cbliard avatar jarmo avatar jasnow avatar ka8725 avatar ojab avatar p0deje avatar stfcodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

watir-rails's Issues

Using with phantomjs

I am trying to get this working with phantomjs, I am using:

browser = Watir::Browser.new :phantomjs

when I run a single test file, this starts up phantomjs, but I get a timeout error for every test:

Timeout::Error: execution expired

When I try accessing a site via phantomjs in the rails console it works fine and is very fast. Any idea what this could be?

mime-types dependency

Can we have mime-types dependency not as strict?

Now it's gem.add_dependency "mime-types", "~> 1.16"

But modern mail gem has the dependency as >= 1.16, < 3, can we have the same here?

NameError VERSION

require 'watir'
require 'webdrivers'
browser = Watir::Browser.new :firefox

Results in:

Traceback (most recent call last):
        2: from (irb):4
        1: from (irb):4:in `new'
NameError (uninitialized constant Watir::VERSION)

I'm not sure what I'm doing wrong, but it all seems to work when I use gem watir rather than this rails integration.

Timeout error?

I would try your gem to test Watir lib, I add "gem 'watir-rails'" to my gem file, do bundle install
and start app on route with this action controller ๐Ÿ‘

def index
browser = Watir::Browser.new
browser.goto 'http://www.googe.com'
end

but it send timeout error : "Rails Rack application timed out during boot"

what's wrong?

Supported rails versions

I d tried to debug something and tried to rewrite some stuff in Watir::Rails and found out that rails-2.x still supported, so I tried to actually check if it works.

Long story short: Rails-2.3.18 cannot run on ruby >= 2.2 since it uses Config::CONFIG which is

irb(main):001:0> Config
(irb):1:in `irb_binding': Use RbConfig instead of obsolete and deprecated Config.
=> RbConfig::Obsolete

on ruby-2.1.10 and dropped in ruby-2.2.

On ruby-2.1.10 we have another issue: rubygems doesn't work:

gem install bundler
ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=error: certificate verify failed (https://api.rubygems.org/latest_specs.4.8.gz)

It was compiled with openssl-1.0.2u and ruby-2.2 with the same version works fine, I assume that ruby-2.1 openssl module lacks current ciphers.

So the question is: can Rails-2.x be dropped in order to simplify some stuff? Same question goes for rails-3, but I haven't tried to boot it yet.

Booting Rails server times out

Hi, I'm trying to use watir-rails with Rails 7.0.6, watir 7.2.2, watir-rails 2.3.0, and watir-rspec 5.0.0.

I was getting this error every time:

Rails Rack application timed out during boot

I did some troubleshooting and found that the application was booting, but the __identify__ middleware was returning a different object_id for @app.object_id. It was not getting called twice, so I'm guessing this is a thread-safety issue. I'm not entirely sure why, but while debugging I found that the problem went away if @app.object_id was accessed after creating the app. My initial changes were printing the object id, but the following change caused it to all work again.

I apologize for the issue without a full reproduction, but I thought I would report this in case anyone else is running in to it.

This is the change that works for me:

--- a/lib/watir/rails.rb
+++ b/lib/watir/rails.rb
@@ -112,6 +112,11 @@ module Watir
             run ::Rails.application
           end
         end.to_app
+
+        # Somehow this fixes everything?
+        @app.object_id
+
+        @app
       end
 
       private

Rails not booting

I am using rails (6.1.3.1), watir (7.0.0.beta2), watir-rspec (3.0.0), and watir-rails (2.2.2). My rails server is not starting with my test. Here's my watir specific configuration that I require in rails_helper:

require 'watir'
require 'watir/rspec'
require 'webdrivers'

Webdrivers::Chromedriver.required_version = Settings.functional_tests.webdrivers.chrome_version
Webdrivers::Geckodriver.required_version  = Settings.functional_tests.webdrivers.gecko_version
Webdrivers::Edgedriver.required_version   = Settings.functional_tests.webdrivers.edge_version

RSpec.configure do |config|
  config.add_formatter(Watir::RSpec::HtmlFormatter)

  [:acceptance, :functional].each do |type|
    config.include Watir::RSpec::Helper, type: type
    config.include Watir::RSpec::Matchers, type: type

    config.include Devise::Test::IntegrationHelpers, type: type

    config.before(:each, type: type) do
      Watir::Rails.host = 'http://localhost'

      @browser = Watir::Browser.new Settings.functional_tests.browser.to_sym
      @base_url = "#{Watir::Rails.host}:#{Watir::Rails.port}"
    end

    config.after(:each, type: type) do
      @browser.close if @browser
    end
  end
end

In my test @base_url is set and the url and the proper driver is initialized so this file is being executed.

Get cookies via middleware

After I started using Warden to perform sign in operations, I've faced a problem that since request is stubbed, browser cookies are no valid (i.e. if I want to grab signed in user cookies and use them in external request like curl, it won't work).

So, I think one of the approaches is to be able to get session/cookies from Rack request using already implemented middleware and use them as browser cookies (or set browser cookies to them).

I'm working on draft solution, however, not sure what approach is the best here. @jarmo What do you think would be the best way to workaround this problem?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Timeout::Error when booting up

So for some reason, on my machine on MacOS Mojave 10.14.6 (18G5033) line lib/watir/rails.rb:110 throws a timeout error when ran for the first time.

def running?
return false if @server_thread && @server_thread.join(0)
res = Net::HTTP.start(local_host, @port) { |http| http.get('/__identify__') }
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
return res.body == @app.object_id.to_s
end
rescue Errno::ECONNREFUSED, Errno::EBADF, EOFError
return false
end

It seems that when checking if a server is actually running, the port number is discarded on the initial call.

Doing Net::HTTP.start('127.0.0.1', nil) { block } without a port number, picks port number 80 by default. But for some weird reason OSX already has something running on this port and then the whole call hangs with a timeout error.

Problem to update watir-rails from version 0.1.2 to 1.x

Hello, I have problem when I try to update watir-rails from version 0.1.2 to 1.1.0. This problem is the same for the version 1.0.0.

When I update my gemfile

group :test do
  [...]
  gem 'watir', '~> 5.0'
  gem 'watir-rails', '1.1.0'
  gem 'watir-rspec'
  gem 'watir-webdriver'
  [...]
end

bundle command gives:

[...]
Using watir-webdriver 0.9.1
Using watir 5.0.0
Using watir-rails 1.1.0
Using watir-rspec 2.0.3
[...]

But when I run my tests, the url in the browser is wrong because it misses the rails host and the rails port. To understand why, I debugged and saw that when the test runs the goto "/app" line the method Watir::Browser::goto of watir-rails gem is not called. In fact, the method Watir::Browser::goto of watir-webdriver is called:

From: /home/darlot/.rvm/gems/ruby-2.2.2/gems/watir-webdriver-0.9.1/lib/watir-webdriver/browser.rb @ line 75 Watir::Browser#goto:

    74: def goto(uri)
 => 75:   uri = "http://#{uri}" unless uri =~ URI.regexp
    76: 
    77:   @driver.navigate.to uri
    78:   @after_hooks.run
    79: 
    80:   uri
    81: end

[1] pry(#<Watir::Browser>):1> 

So I guess I have a gem loading order problem. So I tried to change the order of the gem in the gemfile:

group :test do
 [...]
  gem 'watir-webdriver'
  gem 'watir', '~> 5.0'
  gem 'watir-rails', '1.1.0'
  gem 'watir-rspec'
 [...]
end

But this time, I obtained a infinite recursion when I run my test. Here is the console log:

# /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:53:in `initialize_rails_with_watir'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:10:in `initialize'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-5.0.0/lib/watir/loader.rb:9:in `initialize'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:53:in `block in initialize_rails_with_watir'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:36:in `call'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:36:in `override_and_preserve_original_methods'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:53:in `initialize_rails_with_watir'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:10:in `initialize'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-5.0.0/lib/watir/loader.rb:9:in `initialize'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:53:in `block in initialize_rails_with_watir'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:36:in `call'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:36:in `override_and_preserve_original_methods'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:53:in `initialize_rails_with_watir'
     # /home/sdarlot/.rvm/gems/ruby-2.2.2/gems/watir-rails-1.1.0/lib/watir/browser.rb:10:in `initialize'
     # ./spec/spec_helper.rb:85:in `new'
     # ./spec/spec_helper.rb:85:in `create_browser'
     # ./spec/spec_helper.rb:177:in `block (2 levels) in <top (required)>'

Do you have a clue to help me solving the watir-rails update ?
Thanks

Rails 4.x exceptions won't be re-raised

watir-rails will not re-raise exceptions thrown by Rails Rack::App when using Rails 4.x.

Code responsible for this behavior is in Watir::Rails::Middleware#call.

Exceptions won't be even raised when Rails has action_dispatch.show_exceptions set to false and Watir::Rails.ignore_exceptions? is false.

The problem seems to be in Rails and/or Rack because enabling Thin or WEBrick logging will make everything work.

The following monkey-patch is a temporary solution until newer version of gem has been released.

Add it into your spec_helper.rb or similar file:

require "watir/rails"

class Watir::Rails
  def self.run_default_server(app, port)
    require 'rack/handler/thin'
    Rack::Handler::Thin.run(app, :Port => port)
  rescue LoadError
    require 'rack/handler/webrick'
    Rack::Handler::WEBrick.run(app, :Port => port)
  end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.