I am working on Automation using watir-webdriver. There are 3 ruby files, lets name is as File1.rb, File2.rb and Commnn_file.rb
The scenario is as follows: I compute the count value in File1.rb, say count=10 and pass it on to Commnn_file.rb. I have written a class within a module which will hold the value computed in File1.rb.
Now, I want to retrieve the count value in File2.rb file. How can I do this?
Below is the code snippet:
Commnn_file.rb
module Count
class Row_count
# constructor method
def initialize(cnt)
@count = cnt
end
# instance method
def printCount
@row_value = @count
puts "#{@count}"
puts "#{@row_value}"
return @count
end
end
end
File1.rb
And(/^I print the row count$/) do
include Web_url
@obj = Web_url::Row_count
puts "Step 2 count"
# puts @obj
obj.printCount()
end
File2.rb
And(/^I print the row count$/) do
include Count #Count is the module name
@obj = Web_url::Row_count
puts "Step 2 count"
# puts @obj
obj.printCount()
end
In the above code, the value that is set in File1.rb is not available in File2.rb, which is because every time the object gets instantiated, re-initializes the value.
Can anyone suggest any alternative way of resolving this issue?
As you said, it doesn't work because
@obj
are 2 different Ruby objects in two different files.You could set a
default_count
forCount::RowCount
. (Note that I changed the case to the standard Ruby one).