How to access the another Ruby script value inside my Main Ruby Script

Below is my Main Ruby Script(Main.rb) which Loads my another ruby code
as Property as specified in require section of Main.rb

#Include The Library
require 'rubygems'
require 'win32ole'
require 'watir'
require 'watir/ie'
require 'watir/collections'
require 'watir/element_collections'
require 'watir/screen_capture'
require 'watir/browser'
require 'C:\Ruby193\lib\ruby\gems\1.9.1\gems\watir-2.0.4\lib\watir
\Property.rb'

Watir.options_file = 'C:\Users\amanpreet.oberoi\Desktop\options.yml'

Watir.options[:zero_based_indexing] = false

begin

#Open Excel File
excel = WIN32OLE::new('excel.Application')
excel.DisplayAlerts = false
workbook = excel.Workbooks.Open(File.expand_path(excel_file_path))
#Loop through the worksheets
for i in 1 .. workbook.Worksheets.Count

puts "Inside Worksheet Loop"
  worksheet = workbook.Worksheets(excel_file_sheet_number)
  rowcount = worksheet.UsedRange.Rows.Count

  for j in 2..rowcount
    keyword =worksheet.Cells(j, 4).value
    puts "Fetching Row/Column Value 4" +keyword

    object_Prop_Name = worksheet.Cells(j, 5).value
    #puts "Fetching Row/Column Value 5" +object_Prop_Name

    object_Prop_Value = worksheet.Cells(j, 6).value
    #puts "Fetching Row/Column Value 6" +object_Prop_Value

    expected_Output = worksheet.Cells(j, 7).value
    #puts "Fetching Row/Column Value 7" +expected_Output

    actual_Output = worksheet.Cells(j, 8).value
    #puts "Fetching Row/Column Value 8" +actual_Output

    parm_01 = worksheet.Cells(j, 9).value
    #   puts "Fetching Row/Column Value 9" +parm_01


But when I run Main.rb it gives me below error.

amanpreet.oberoi@AMANPREETT410 ~
$ ruby -KU -- 'C:\Ruby193\lib\ruby\gems\1.9.1\gems\watir-2.0.4\lib
\watir\DataDriven.rb'
Excel File Path Extracted'C:\Users\amanpreet.oberoi\Desktop
\Google.xls'
Excel File Sheet Number Extracted  1
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-2.0.4/lib/watir/
DataDriven.rb:21:in `<main>': undefined local variable or method
`excel_file_path' for main
:Object (NameError)

Property.rb file contains below variables being defined:

#Include watir library
require 'rubygems'
require 'watir'

#Begin read the contents of the configuration file for data mapping
file_contents = File.open('C:\Users\amanpreet.oberoi\Desktop
\config.txt').readlines
#Create a name/value hash for the properties
data_inputs = Hash.new()
file_contents.each { |property|
        foo = property.split('=')
        data_inputs[foo[0]] = foo[1]}
#Data mapping for column heading names for config variables
excel_file_path = data_inputs["excel_file_location_path"].chomp
puts "Excel File Path Extracted" +excel_file_path
excel_file_sheet_number = data_inputs["excel_file_sheet_number"].chomp
puts "Excel File Sheet Number Extracted  " +excel_file_sheet_number
#End read

with Output as

amanpreet.oberoi@AMANPREETT410 ~
$ ruby -KU -- 'C:\Ruby193\lib\ruby\gems\1.9.1\gems\watir-2.0.4\lib
\watir\Property.rb'
Excel File Path Extracted'C:\Users\amanpreet.oberoi\Desktop
\Google.xls'
Excel File Sheet Number Extracted  1


How can I access the Property.rb variables values in inside Main.rb

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to