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

  • SEARCH
  • Home
  • 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 7026469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:18+00:00 2026-05-28T00:07:18+00:00

I am working on a program in Ruby with Watir that has a series

  • 0

I am working on a program in Ruby with Watir that has a series of modules.

An example module would look like:

demoMod1.rb

DEMOMOD1 = true #this module has been loaded
module demoMod1
  def reload(browser)
    browser.goto("demo1.html")
  end
end

There are several files with very similarly named functions (example: reload() ), so demoMod2 and demoMod3 both have the same reload function (except pointing to different pages).

The modules are commented out of the require list when that area is not expected to be tested. (as per design specs)

The program then dynamically loads test case files (code to do that is below in main.rb). Each test case file contains a runTest() function, which calls the appropriate sections from the modules. Each test checks if the module is loaded, and if it has, the test executes.

A sample test case file would look like:

test1.rb

def runTest(browser)  # test case 1
  if(defined?(DEMOMOD1)).nil?
    return nil  #if the module is not there, dont run this test
  end
  demoMod1::reload(browser)
end

As per specs, a single file lists all of the modules to be required, so that a user can just comment out the sections to not be tested without having to look at the main file. The main file is below.

main.rb

require 'Watir'
SITE = #internal site - address removed =/ sorry
FOLDER = File.dirname(__FILE__) + '/lib'
SHORTNAME = 'Test'  #for reporting
LONGNAME = 'In Development'  #for reporting
  #I know - globals.. yuck... avoid... 
require FOLDER + '/lib/requires'
  #includes the function to require each module from the module folder
require FOLDER + '/www/include/report.module'
  #creates an html report to view the test results

# Get list of tests
def getTests()
  Dir.chdir(FOLDER + '/Tests')
  files = Dir.glob("*.rb")
  return files
end #eofunc

# Run each test
def runTests(files, browser, report)
  testSuite = String.new
  files.each do |test|
    suite = test.split(" - ") # name convention:  suite - testname.rb
    if !(suite[0]==testSuite)
      testSuite = suite[0]
      report.newTestSuiteName(testSuite)
    end #eoif
    load FOLDER + '/Tests/' + test #load the test case file
    runTest(browser) #run the test case
  end #eoeach
end #eofunc

begin
  browser = Watir::Browser.new
  browser.goto(SITE)
  report = Report.new()
  reportname = report.createReport(SHORTNAME, LONGNAME) #vars in Vars.rb
  files = getTests()
  runTests(files, browser, report)
  report.finishReport(reportname, SITE)
  browser.close
  report.openReport(reportname) #launch report in a new browser
end #eofunc

I would expect in each of the runTest() to be able to access the demoMod1::reload() and demoMod2::reload(), but this is not the case. I get an error for undefined method 'reload' for demoMod1:Module. I can resolve the error by using include demoMod1 but then (if I have this correctly), the scope is not needed, and using just reload() would work. However this would require each module have entirely unique names, and that is not a great solution.

What am I missing?

  • 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-28T00:07:18+00:00Added an answer on May 28, 2026 at 12:07 am

    By changing the function names in the modules I can get it to work.

    example module:

    DEMOMOD1 = true
    module DemoMod1
      def DemoMod1.reload(browser) #<---------
        browser.goto('demo1.htm')
      end
    end
    

    Line with the <— arrow is the main change (also had to change the module name, did not have a capital first letter…oops)

    example test case:

    def runTest(browser)  # test case 1
      if(defined?(DEMOMOD1)).nil?
        return nil  #if the module is not there, dont run this test
      end
      DemoMod1::reload(browser)
      ### OR ###   Both work
      DemoMod1.reload(browser)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a small Ruby program that will connect to a remote MySQL
I have a working program in C++ that generates data for a Mandelbrot Set.
I am working on a program that needs to create a multiple temporary folders
I'm working on a program that processes many requests, none of them reaching more
I'm working on a program that searches entire drives for a given file. At
Has anyone used Watir with IronRuby successfully? I am getting an error that the
I'm learning Ruby and working on my first real project. The program will receive
I'm a scientist working mostly with C++, but I would like to find a
I am working on a ruby program and have run into the following problem.
I have a working program written in Java with the Java Sound API that

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.