Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:25:26+00:00 2026-05-19T01:25:26+00:00

In my ruby Selenium Tests there is a lot of the same code in

  • 0

In my ruby Selenium Tests there is a lot of the same code in every test. How can I best share code between tests? For example my setup and teardown methods are the same in every file, how can I remove them from every file into one shared file or is that even possible?

def setup
    @verification_errors = []
    @selenium = Selenium::Client::Driver.new \
    :host => "#$sell_server",
    :port => 4444,
    :browser => "#$browser",
    :url => "http://#$network.#$host:2086/",
    :timeout_in_second => 60

    @selenium.start_new_browser_session
end

def teardown
    @selenium.close_current_browser_session
    assert_equal [], @verification_errors
end

I’ve tried putting setup in a shared module and a required file but both present different problems with inheritance of the other methods that need access to the @selenium object that is started. What would be a good design if there is one for sharing the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:25:27+00:00Added an answer on May 19, 2026 at 1:25 am

    For test unit framework – it seems to work to create a SharedTest class to inherit from Test::Unit::Testcase with setup and teadown methods. Then just subclass the test files SharedTest. The only negative consequence I’ve found is I had to add a test_default method that does nothing in SharedTest to get it to work. If I name my test method test_default that overides it and seems ok, but not very descriptive…

    sharedtest.rb

    class SharedTest < Test::Unit::Testcase
      def setup
        @verification_errors = []
        @selenium = Selenium::Client::Driver.new \
        :host => "#$sell_server",
        :port => 4444,
        :browser => "#$browser",
        :url => "http://#$network.#$host:2086/",
        :timeout_in_second => 60
    
        @selenium.start_new_browser_session
     end
    
     def teardown
        @selenium.close_current_browser_session
        assert_equal [], @verification_errors
     end
    
     def test_default
       #puts self
     end
    end
    

    T01_testcasename.rb

     class Test_01_whatever < SharedTest
       def test_default
          #test code
       end
    

    I’m still open to better solutions but this seems to be working for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I've started to create some Ruby unit tests that use Selenium RC to
I am am running some selenium tests(ruby) on my web page and as i
I am trying to get Hudson to run my ruby based selenium tests. I
Ruby's standard popen3 module does not work on Windows. Is there a maintained replacement
Ruby can add methods to the Number class and other core types to get
Ruby on Rails has a lot of ways to generate JavaScript. Particularly when it
Ruby is truly memory-hungry - but also worth every single bit. What do you
I'm pretty new to both Ruby and Selenium and I'm just trying to figure
I'm in the middle of picking tools to load test my Ruby on Rails
I use selenium, usually with firefox, to test my rails apps and it's all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.