views:

36

answers:

1

hello sir,

i am autpmating a web site that have different function page. i am making differnt modules for each function. the problem is that i have a login page Login.rb that has the below code :-

$IE = Watir::IE.new_process

module Login

  def Login.login(url)
    $IE.goto("url")
    sleep (4)
    $IE.maximize
    #$IE.span(:class =>'menuLink', :text =>'Image').click
  end
end

i need to access $IE variable to my other modules methods. the problem is that the other modules that are in different .rb file are not taking this variable. help me how sholud i declare this so that i can use it in all my modules throughout different files.

+1  A: 

Global variables should be available in all modules and in all files. You could put this global variable in a file named (for example) common.rb and require or load that file in all of your scripts.

But you don't need to use a global variable. You could just as easily do something like this and load it in every script file that you need.

module Browser
  def self.ie
    @ie ||= Watir::IE.new_process
  end
end
AboutRuby