Coder Social home page Coder Social logo

watir-rspec'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-rspec's People

Contributors

jarmo avatar jkotests avatar p0deje avatar sblond 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

watir-rspec's Issues

uninitialized constant Watir::RSpec (NameError)

C:\Ruby193\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby193\bin/rspec "C:/Users/Admin/RubymineProjects/Selenium_Ruby/Google Test/spec/login_spec.rb" --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter --example "Gmail Login"
Testing started at 12:54 AM ...
C:/Users/Admin/RubymineProjects/Selenium_Ruby/Google Test/spec/spec_helper.rb:19:in block in <top (required)>': uninitialized constant Watir::RSpec (NameError) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core.rb:107:inconfigure'
from C:/Users/Admin/RubymineProjects/Selenium_Ruby/Google Test/spec/spec_helper.rb:16:in <top (required)>' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require' from C:/Users/Admin/RubymineProjects/Selenium_Ruby/Google Test/spec/login_spec.rb:1:in<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in load' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:inblock in load_spec_files'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in each' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:inload_spec_files'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:inrun'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

Process finished with exit code 1
Empty test suite.

require 'watir-rspec' cause circular reference on driver init

In my project which already running with selenium-webdriver I decide to try watir w/ watir-rspec gems.
I create driver instance via: @driver = Watir::Browser.new :firefox and if watir-spec is required - I got 'SystemStackError: stack level too deep' error

I've tried to debug it w/ and w/out requiring gem:

  • when it required - Watir::Browser.new cause to run ../watir-5.0.0/.../watir/loader.rb
  • when it's not - ../watir-webdriver-0.7.0/.../browser.rb

in first case it cause circular reference in initialize method which cause such exception.

Ask me for any additional info - would be happy to share.

undefined method `synchronize' for nil:NilClass (NoMethodError)

Hi,
I was using v0.0.3, and then had issues after updating to v1.1.0.
When I create a new ActiveRecord instance in a spec, I get the following error:

NoMethodError:
       undefined method `synchronize' for nil:NilClass

After investigating a bit, I wonder if changes in file lib/watir/rspec/active_record_shared_connection.rb from commit c1ed876 could be responsible (@shared_connection_semaphore and @shared_connection are not visible in subclasses of ActiveRecord::Base).

In ruby 3.2.2 version, Watir::RSpec::HtmlFormatter will delete current project files

In ruby 3.2.2 version.

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

I don't set ENV["WATIR_RESULTS_PATH"] as before versions.
Running " bundle exec rspec " twice, It will delete all files from current project.
Because in ruby 3.2.2 version, the default output_wrapper will response to method :path , it returns "<STDOUT>".

 @output_path = File.expand_path(ENV["WATIR_RESULTS_PATH"] || (output.respond_to?(:path) ? output.path : "tmp/spec-results/index.html"))
FileUtils.rm_rf File.dirname(@output_path), :verbose => true if File.exist?(@output_path)

@output_path is assigned "<CURRENT_DIRECTORY>/<STDOUT>".
Run rspec first time, it will output "<STDOUT>" file in the current directory.
Run rspec second time, it will remove all files in the project directory.

It's very bad to delete all files in the current directory.

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.

undefined method 'file_field' for main:Object (NoMethodError)

Hello,

I would like to setup the HTMLFormatter into my project, when I run the automated tests.
After successfully installing watir-rspec into rspec_helper.rb, I also wanted to setup the screenshots to be attached to the html report. I was unsuccessful.
The watir-rspec readme states:

You can use Watir::RSpec.file_path to have links automatically in the html report to the files created during tests.
uploaded_file_path = Watir::RSpec.file_path("uploaded.txt")
File.open(uploaded_file_path, "w") {|file| file.write "Generated File Input"}
file_field(:name => "upload-file").set uploaded_file_path

Where do I put this code? When I put it in my spec_helper.rb, I get this error: undefined method 'file_field' for main:Object (NoMethodError)

Can anyone please help me and tell me what I'm doing wrong? I did not find any other documentation to help me resolve this. Maybe this will help a lot of beginners understand.
Thanks in advance !

is watir-rspec2.3.0 gem can be used along with Rspec 3.2 or later versions?

Hi,

I am using rspec3.2 along with watir-rspec2.3.0 to generate rspec html report along with attached screenshot link for failed test cases. Getting an error msg while spec execution. please find the attached error msg screenshot.

errormsg

is watir-rspec2.3.0 gem can be used along with Rspec 3.2 ? could somebody help me in generating watir-rspec html report.

Thanks,
Chandana

Instantiate browser in before :suite?

In my program I am using Watir to spool up web browsers and test various pages for a website. The easiest way to do this (which I have been using) is to go with watir-rspec's default behavior of opening a new browser instance for every test package, then close it afterwards.

I really want to make my program more efficient, so that instead of opening and closing windows for every unit test, it will 'borrow' a browser that was already open from the previous test, redirect it to the page it tests on, and test.
The problem with this is that although when I instantiate my browser object in before :all it works just fine, in before :suite it can't be accessed. If I puts the object name from before :all it comes back nil, and likewise within each spec file it comes back nil.

Basically, I'm instantiating the object in before :suite and destroying it in after :suite so that it can persist through all specs, then only close at the end. Is there anything I am missing about scope here? Is there a better way to do this altogether?
Furthermore, is there a way to do this while still maintaining the command shortening functionality

(I.E. button(id: "foo") or send_keys :return)?

My spec_helper.rb

require_relative '../login'
require_relative '../logInObject'

require 'watir'




# Configuration for watir-rspec
require "watir/rspec"

RSpec.configure do |config|
  # Use Watir::RSpec::HtmlFormatter to get links to the screenshots, html and
  # all other files created during the failing examples.
  config.add_formatter(:progress) if config.formatters.empty?
  config.add_formatter(Watir::RSpec::HtmlFormatter)

  # Open up the browser for each example.
#=begin
  config.before :all do

#  puts "----------before all!"
#    @browser = LoginDrone.new :internet_explorer if !@browser
#   @browser.doLogin
#   puts "Before all browser: #{@browser}"
#   sleep(3)
  end

  config.before :suite do
#  puts "----------before suite!"
#  puts "Before suite browser: #{@browser}"
    $user = Credentials.new #if !$user
    @browser = LoginDrone.new :internet_explorer if !@browser
    @browser.doLogin
    puts @browser
  end

#  config.before :all do
#   goto "office.rcsdev.com/dasqa"
#  end
#=end
=begin
  #This bit is of my own making, it chooses not to open a new browser if one exists.
  config.before :all do
    if @browser.nil?
        @browser = LoginDrone.new :internet_explorer
        doLogin
    end
  end
=end
#=begin
  # Close that browser after each example.
  config.after :suite do
  puts "----------after suite!" if @browser
  puts "after suite browser: #{@browser}"
    @browser.close if @browser
  end
#=end





  # Include RSpec::Helper into each of your example group for making it possible to
  # write in your examples instead of:
  #   @browser.goto "localhost"
  #   @browser.text_field(name: "first_name").set "Bob"
  #
  # like this:
  #   goto "localhost"
  #   text_field(name: "first_name").set "Bob"
  #
  # This needs that you've used @browser as an instance variable name in
  # before :all block.
  config.include Watir::RSpec::Helper

  # Include RSpec::Matchers into each of your example group for making it possible to
  # use #within with some of RSpec matchers for easier asynchronous testing:
  #   expect(@browser.text_field(name: "first_name")).to exist.within(2)
  #   expect(@browser.text_field(name: "first_name")).to be_present.within(2)
  #   expect(@browser.text_field(name: "first_name")).to be_visible.within(2)
  #
  # You can also use #during to test if something stays the same during the specified period:
  #   expect(@browser.text_field(name: "first_name")).to exist.during(2)
  config.include Watir::RSpec::Matchers
end

LoginDrone is an object that inherits from Watir::Browser with some added goodies, like the doLogin method which goes to my test site and gets a credential input.

P.S. I -DON'T- want to use global variables if at all possible, because A: they are inefficient and B: I want to eventually add multi-threading support.

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.