简体   繁体   中英

How to get local variable between ruby script

Unable to get local variable value of module in one .rb into another .rb file. Am trying to get driverDetailsMap variable value from setup.rb into Scriptrunner.rb file. But i always got the issue as undefined method `driverDetailsMap' for Setup:Module (NoMethodError).

Setup.rb

require "selenium-webdriver"
require "rspec"
require 'spreadsheet'

  module Setup

    if ENV["RAKE_CALL"] == "true"   
        $driverDetailsMap = Hash.new
        inputMap = Hash.new
        workbook = Spreadsheet.open 'src/config/Config.xls'

        deviceConfigSheet = workbook.worksheet 'DeviceConfig'
        totalColumnCount = deviceConfigSheet.column_count
        startingColumn = 1  

        while startingColumn <= totalColumnCount-1

          deviceConfigSheet.each do |row|
            inputMap[row[0]] = row[startingColumn]
          end

          if inputMap.[]('PLATFORM_NAME') == 'Web-Firefox'
            driver = Selenium::WebDriver.for :firefox
            base_url = inputMap.[]('DRIVER_URL')
            accept_next_alert = true
            driver.manage.timeouts.implicit_wait = 30
            driver.manage.window.maximize
            driver.get(base_url + "/")
          end

             driverDetailsMap[inputMap.[]('DEVICE_IDENTIFIER')] = driver
            startingColumn += 1
        end
      end
end

ScriptRunner.rb

require "rspec"
require 'spreadsheet'
#require 'setup'
require File.dirname(__FILE__) + '/setup.rb'
#include Setup

 puts Setup::driverDetailsMap
 puts "TESTING <<<<<<<<<<<<<<<<<<<<<<<<<<"

..................

Please Help In Advance..

$driverDetailsMap is the global variable .

To have an instance variable on Setup class, one might do:

class Setup
  @driver_details_map = Hash.new
  class << self
    attr_reader :driver_details_map
  end

  ...
end

And later access it with

Setup.driver_details_map

Please note, that I corrected the name of the variable to snake case to conform ruby style guidelines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM