Module: RWebSpec::WebDriver::UsingPages

Defined in:
lib/rwebspec-webdriver/using_pages.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(kclass) ⇒ Object

support Ruby 1.9



6
7
8
9
10
11
12
13
# File 'lib/rwebspec-webdriver/using_pages.rb', line 6

def self.extended(kclass)
  caller_file = caller[1]
  if caller_file && caller_file =~ /^(.*):\d+.*$/
    file = $1
    dir = File.expand_path(File.dirname(file))
    kclass.const_set "TestFileDir", dir
  end
end

Instance Method Details

#pages(*args) ⇒ Object

Example

pages :all
pages :login_page, :payment_page
pages :login_page, :payment_page, :page_dir => "c:/tmp"


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rwebspec-webdriver/using_pages.rb', line 19

def pages(*args)
  return if args.nil? or args.empty?

  test_file_dir = class_eval{  self::TestFileDir }
  default_page_dir = File.join(test_file_dir, "pages")
  #puts "debug: default_page_dir :#{default_page_dir}}"
  page_dir = default_page_dir

  page_files = []
  args.each do |x|
    if x.class == Hash && x[:page_dir]
      page_dir = x[:page_dir]
    else
      page_files << x
    end
  end

  if page_files.size == 1 && page_files[0] == :all
    Dir[File.expand_path(page_dir)+ "/*_page.rb"].each { |page_file|
      load page_file
    }
    return
  end

  page_files.each do |page|
    page_file = File.join(page_dir, page.to_s)
    load page_file
  end
end