Module: Sapphire::DSL::Browser

Included in:
Sapphire
Defined in:
lib/sapphire/DSL/Browser/To.rb,
lib/sapphire/DSL/Browser/For.rb,
lib/sapphire/DSL/Browser/Not.rb,
lib/sapphire/DSL/Browser/Set.rb,
lib/sapphire/DSL/Browser/Hide.rb,
lib/sapphire/DSL/Browser/Show.rb,
lib/sapphire/DSL/Browser/With.rb,
lib/sapphire/DSL/Browser/Check.rb,
lib/sapphire/DSL/Browser/Clear.rb,
lib/sapphire/DSL/Browser/Click.rb,
lib/sapphire/DSL/Browser/Close.rb,
lib/sapphire/DSL/Browser/Error.rb,
lib/sapphire/DSL/Browser/Popup.rb,
lib/sapphire/DSL/Browser/Start.rb,
lib/sapphire/DSL/Browser/Exists.rb,
lib/sapphire/DSL/Browser/Reload.rb,
lib/sapphire/DSL/Browser/Should.rb,
lib/sapphire/DSL/Browser/Switch.rb,
lib/sapphire/DSL/Browser/Browser.rb,
lib/sapphire/DSL/Browser/Disable.rb,
lib/sapphire/DSL/Browser/Tracker.rb,
lib/sapphire/DSL/Browser/Uncheck.rb,
lib/sapphire/DSL/Browser/Complete.rb,
lib/sapphire/DSL/Browser/IsHidden.rb,
lib/sapphire/DSL/Browser/Navigate.rb,
lib/sapphire/DSL/Browser/IsVisible.rb,
lib/sapphire/DSL/Browser/MouseOver.rb,
lib/sapphire/DSL/Browser/CurrentUrl.rb,
lib/sapphire/DSL/Browser/Transition.rb,
lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb

Defined Under Namespace

Classes: Browser, Popup

Instance Method Summary collapse

Instance Method Details

#Check(*args) ⇒ Object



4
5
6
7
8
# File 'lib/sapphire/DSL/Browser/Check.rb', line 4

def Check(*args)
  ExecuteAgainstControl(args) do |control, arg|
    control.Check true
  end
end

#Clear(item) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/sapphire/DSL/Browser/Clear.rb', line 4

def Clear(item)
  if(item.is_a? Class)
    x = item.new $browser
    x.Clear
    return
  end
end

#Click(*args) ⇒ Object



4
5
6
7
8
# File 'lib/sapphire/DSL/Browser/Click.rb', line 4

def Click(*args)
  ExecuteAgainstControl(args) do |control, arg|
    control.Click
  end
end

#Complete(page) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/sapphire/DSL/Browser/Complete.rb', line 4

def Complete(page)
  if(page.is_a? Class)
    x = page.new(@browser)
  else
    x = page
  end
  @page = x.Complete
end

#CurrentUrl(value) ⇒ Object



4
5
6
7
# File 'lib/sapphire/DSL/Browser/CurrentUrl.rb', line 4

def CurrentUrl(value)
  url = @browser.CurrentUrl
  url == value
end

#Disable(args) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/Disable.rb', line 4

def Disable(args)
  return Hide(args)
end

#Error(hash) ⇒ Object



4
5
6
7
8
# File 'lib/sapphire/DSL/Browser/Error.rb', line 4

def Error(hash)
 ExecuteHashAgainstControl(hash) do |control, arg|
    return control.Equals(arg)
  end
end

#ExecuteAgainstControl(*args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb', line 19

def ExecuteAgainstControl(*args, &block)
  @page.fields.each do |field|
    field.keys.each do |field_key|
      args.each do |arg_array|
        arg_array.each do |arg|
          if(field_key == arg)
            block.call(field[field_key], arg)
            return
          end
        end
      end
    end
  end

  arglist = ""
  args.each do |arg_array|
    arg_array.each do |arg|
      arglist += arg.to_s + ", "
    end
  end

  raise "Cannot find controls matching: " + arglist + "for page " + @page.to_s
end

#ExecuteHashAgainstControl(hash, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb', line 4

def ExecuteHashAgainstControl(hash, &block)
  hash.keys.each do |key|
    @page.fields.each do |field|
      field.keys.each do |field_key|
        if(field_key == key)
          block.call(field[key], hash[key])
          return
        end
      end
    end
  end

  raise "cannot find control matching " + hash.to_s + " for page " + @page.to_s
end

#Exists(symbol) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sapphire/DSL/Browser/Exists.rb', line 4

def Exists(symbol)
  @page.fields.each do |field|
    field.keys.each do |field_key|
      if(field_key == symbol)
        begin
          x = field[field_key].FindWithoutWait
          return x.displayed?
        rescue
          return false
        end
      end
    end
  end
  false
end

#Exit(item) ⇒ Object



4
5
6
7
# File 'lib/sapphire/DSL/Browser/Close.rb', line 4

def Exit(item)
  x = item.new
  x.Close
end

#For(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/For.rb', line 4

def For(item)
  {item => GetPageField(item).Text}
end

#Hide(args) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/Hide.rb', line 4

def Hide(args)
  IsHidden(args) == true
end

#IsHidden(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sapphire/DSL/Browser/IsHidden.rb', line 4

def IsHidden(args)
  @page.fields.each do |field|
    field.keys.each do |field_key|
      if(field_key == args)
        begin
          wait = Selenium::WebDriver::Wait.new(:timeout => 10)
          element = wait.until { x = field[field_key].Find
              x and !x.displayed?
          }
          if(element)
            return element.displayed?
          end
        rescue
         return true
        end
      end
    end
  end

  raise "cannot find control matching " + args.to_s + " for page " + @page.to_s
end

#IsVisible(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sapphire/DSL/Browser/IsVisible.rb', line 4

def IsVisible(args)
  @page.fields.each do |field|
    field.keys.each do |field_key|
      if(field_key == args)
        begin
          x = field[field_key].Find
          if(x)
            begin
              wait = Selenium::WebDriver::Wait.new(:timeout => 10)
              result = wait.until { y = x.displayed?
                y unless y == false
              }
              return result
            rescue
              return false
            end
          end
        rescue
         return false
        end
      end
    end
  end

  raise "cannot find control matching " + args.to_s + " for page " + @page.to_s
end

#MouseOver(*args) ⇒ Object



4
5
6
7
8
# File 'lib/sapphire/DSL/Browser/MouseOver.rb', line 4

def MouseOver(*args)
  ExecuteAgainstControl(args) do |control, arg|
    control.MouseOver
  end
end


4
5
6
7
# File 'lib/sapphire/DSL/Browser/Navigate.rb', line 4

def Navigate(page)
  @page = @browser.NavigateTo(page)
  @page.Init
end

#Not(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/Not.rb', line 4

def Not(item)
  !item
end

#Reload(item) ⇒ Object



4
5
6
7
# File 'lib/sapphire/DSL/Browser/Reload.rb', line 4

def Reload(item)
  @browser.Reload
  Should Show item
end

#Set(hash) ⇒ Object



4
5
6
7
8
# File 'lib/sapphire/DSL/Browser/Set.rb', line 4

def Set(hash)
  ExecuteHashAgainstControl(hash) do |control, arg|
    control.Set arg
  end
end

#Should(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/Should.rb', line 4

def Should(item)
  item.should == true
end

#Show(item) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sapphire/DSL/Browser/Show.rb', line 4

def Show(item)
  if(item.is_a? Hash)
    ExecuteHashAgainstControl(item) do |control, arg|
      wait = Selenium::WebDriver::Wait.new(:timeout => 10)
      text = wait.until { x = control
        x unless (!x.Equals(arg) && x.Equals(""))
      }

      return text.Equals(arg)
    end
  elsif(item.is_a? Symbol)
    return IsVisible(item) == true
  elsif(item.is_a? Class)
    temp, @page = @browser.ShouldNavigateTo item
    @page.Init
    return temp
  else
    @page = item
    @page.Init
    return true
  end
end

#Start(browser) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/sapphire/DSL/Browser/Start.rb', line 4

def Start(browser)
  if(browser == ConfigurationBrowser)
    @browser = AppConfig.Current.Browser
  else
    @browser = browser
  end

  @browser.SetRootUrl(@rootUrl)
end

#Switch(browser) ⇒ Object



4
5
6
7
# File 'lib/sapphire/DSL/Browser/Switch.rb', line 4

def Switch(browser)
  x = browser.new
  x.Switch
end

#To(url) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/To.rb', line 4

def To(url)
  url
end

#Track(hash) ⇒ Object



4
5
6
7
# File 'lib/sapphire/DSL/Browser/Tracker.rb', line 4

def Track(hash)
  $tracker ||= {}
  $tracker.merge! hash
end

#Tracker(item) ⇒ Object



9
10
11
# File 'lib/sapphire/DSL/Browser/Tracker.rb', line 9

def Tracker(item)
  $tracker[item]
end

#Transition(url) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/Transition.rb', line 4

def Transition(url)
  @browser.ShouldTransitionTo url
end

#Uncheck(*args) ⇒ Object



4
5
6
7
8
# File 'lib/sapphire/DSL/Browser/Uncheck.rb', line 4

def Uncheck(*args)
  ExecuteAgainstControl(args) do |control, arg|
    control.Check false
  end
end

#With(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Browser/With.rb', line 4

def With(item)
  item
end