Module: Sapphire::DSL::Browser

Included in:
Sapphire
Defined in:
lib/sapphire/DSL/Browser/For.rb,
lib/sapphire/DSL/Browser/Make.rb,
lib/sapphire/DSL/Evaluators/In.rb,
lib/sapphire/DSL/Browser/Create.rb,
lib/sapphire/DSL/Browser/Should.rb,
lib/sapphire/DSL/Browser/Tracker.rb,
lib/sapphire/DSL/Evaluators/Show.rb,
lib/sapphire/DSL/Browser/Fluff/Be.rb,
lib/sapphire/DSL/Browser/Fluff/By.rb,
lib/sapphire/DSL/Browser/Fluff/To.rb,
lib/sapphire/DSL/Browser/Verbs/On.rb,
lib/sapphire/DSL/Evaluators/Count.rb,
lib/sapphire/DSL/Browser/Nouns/Day.rb,
lib/sapphire/DSL/Browser/Verbs/Has.rb,
lib/sapphire/DSL/Browser/Verbs/Set.rb,
lib/sapphire/DSL/Evaluators/Differ.rb,
lib/sapphire/DSL/Evaluators/Source.rb,
lib/sapphire/DSL/Browser/Fluff/Have.rb,
lib/sapphire/DSL/Browser/Fluff/With.rb,
lib/sapphire/DSL/Browser/Verbs/Exit.rb,
lib/sapphire/DSL/Browser/Verbs/Wait.rb,
lib/sapphire/DSL/Evaluators/AltText.rb,
lib/sapphire/DSL/Evaluators/Checked.rb,
lib/sapphire/DSL/Evaluators/Contain.rb,
lib/sapphire/DSL/Browser/Nouns/Enter.rb,
lib/sapphire/DSL/Browser/Nouns/Month.rb,
lib/sapphire/DSL/Browser/Nouns/Popup.rb,
lib/sapphire/DSL/Browser/Verbs/Check.rb,
lib/sapphire/DSL/Browser/Verbs/Clear.rb,
lib/sapphire/DSL/Browser/Verbs/Click.rb,
lib/sapphire/DSL/Browser/Verbs/Press.rb,
lib/sapphire/DSL/Browser/Verbs/Start.rb,
lib/sapphire/DSL/Browser/Verbs/Using.rb,
lib/sapphire/DSL/Evaluators/Selected.rb,
lib/sapphire/DSL/Browser/Nouns/Second.rb,
lib/sapphire/DSL/Browser/Verbs/Accept.rb,
lib/sapphire/DSL/Browser/Verbs/Exists.rb,
lib/sapphire/DSL/Browser/Verbs/Matrix.rb,
lib/sapphire/DSL/Browser/Verbs/Reload.rb,
lib/sapphire/DSL/Browser/Verbs/Remove.rb,
lib/sapphire/DSL/Browser/Verbs/Switch.rb,
lib/sapphire/DSL/Browser/Nouns/Browser.rb,
lib/sapphire/DSL/Browser/Verbs/Compare.rb,
lib/sapphire/DSL/Browser/Verbs/Disable.rb,
lib/sapphire/DSL/Browser/Verbs/Uncheck.rb,
lib/sapphire/DSL/Evaluators/Transition.rb,
lib/sapphire/DSL/Browser/Verbs/Complete.rb,
lib/sapphire/DSL/Browser/Verbs/Navigate.rb,
lib/sapphire/DSL/Browser/Verbs/MouseOver.rb,
lib/sapphire/DSL/Browser/Verbs/Virtually.rb,
lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb

Defined Under Namespace

Classes: AltText, Browser, Checked, Day, Enter, Matrix, Month, Popup, Second, Source

Instance Method Summary collapse

Instance Method Details

#Accept(item) ⇒ Object



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

def Accept(item)
  item.Accept
end

#AltText(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/AltText.rb', line 4

def AltText(item)
  AltText.new(item)
end

#Be(item) ⇒ Object



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

def Be(item)
  item
end

#By(value) ⇒ Object



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

def By(value)
  value
end

#Check(item) ⇒ Object



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

def Check(item)
  item.Check
end

#Checked(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Checked.rb', line 4

def Checked(item)
  Checked.new(item)
end

#Clear(item) ⇒ Object



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

def Clear(item)
  item.Clear(item)
end

#Click(item) ⇒ Object



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

def Click(item)
  item.Click
end

#Compare(control1, control2, &block) ⇒ Object



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

def Compare(control1, control2, &block)
  if(control1.is_a? Symbol)
    $compare1 = GetPageField(control1).Text
  else
    $compare1 = control1
  end
  if(control2.is_a? Symbol)
    $compare2 = GetPageField(control2).Text
  else
    $compare2 = control2
  end
  block.call()
end

#Complete(page) ⇒ Object



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

def Complete(page)
  if(page.is_a? Class)
    temp = page.new
    temp.Complete
  else
    page.Complete
  end
end

#Contain(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Contain.rb', line 4

def Contain(item)
  Evaluator.new(item) do |item, comparator| item.Contain(item, comparator) end
end

#Count(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Count.rb', line 4

def Count(item)
  Evaluator.new(item) do |item, comparator| item.Count(item, comparator) end
end

#Create(item, &block) ⇒ Object



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

def Create(item, &block)
  item.Create(item) do block.call end
end

#Day(value) ⇒ Object



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

def Day(value)
  day = Day.new(value, $compare1, $compare2)
  $compare1 = nil
  $compare2 = nil
  return day
end

#Differ(value) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Differ.rb', line 4

def Differ(value)
  Evaluator.new(value) do |value, comparator| value.Differ(comparator) end
end

#Disable(args) ⇒ Object



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

def Disable(args)
  return Not Show(args)
end

#ExecuteAgainstControl(item, &block) ⇒ Object



12
13
14
15
16
# File 'lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb', line 12

def ExecuteAgainstControl(item, &block)
  return block.call($page.Get(item), item) if($page.Contains item)

  raise "Cannot find controls matching: " + item.to_s + "for page " + $page.to_s
end

#ExecuteHashAgainstControl(hash, &block) ⇒ Object



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

def ExecuteHashAgainstControl(hash, &block)
  hash.keys.each do |key|
    return block.call($page.Get(key), hash[key]) if($page.Contains key)
  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
# File 'lib/sapphire/DSL/Browser/Verbs/Exists.rb', line 4

def Exists(symbol)
  if($page.Contains symbol)
    begin
      return $page.Get(symbol).Visible(false).Evaluate()
    rescue
      return false
    end
  end
end

#Exit(item) ⇒ Object



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

def Exit(item)
  item.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

#Has(page) ⇒ Object



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

def Has(page)
  return !page.nil? && !page.empty?
end

#Have(item) ⇒ Object



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

def Have(item)
  item
end

#In(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/In.rb', line 4

def In(item)
  Evaluator.new(item) do |item, comparator| item.In(item, comparator) end
end

#Make(item) ⇒ Object



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

def Make(item)
  item.Make
end

#Matrix(symbol) ⇒ Object



5
6
7
# File 'lib/sapphire/DSL/Browser/Verbs/Matrix.rb', line 5

def Matrix(symbol)
  return Matrix.new(symbol)
end

#Month(value) ⇒ Object



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

def Month(value)
  month = Month.new(value, $compare1, $compare2)
  $compare1 = nil
  $compare2 = nil
  return month
end

#MouseOver(item) ⇒ Object



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

def MouseOver(item)
  item.MouseOver
end


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

def Navigate(page)
  $driver.NavigateTo(page)
end

#On(page) ⇒ Object



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

def On(page)
  page = page.new if page.is_a? Class
  found = $driver.CurrentUrl.upcase.start_with?(page.Url.upcase)
  if(found == false)
    page.AlternateUrls.each do |url|
      if( found == false)
        found = $driver.CurrentUrl.upcase.start_with?(url.upcase)
      end
    end
  end

  return found
end

#Press(item) ⇒ Object



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

def Press(item)
  item.Press(item)
end

#Reload(item) ⇒ Object



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

def Reload(item)
  $driver.Reload
  Should Show item
end

#Remove(item) ⇒ Object



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

def Remove(item)
  ExecuteHashAgainstControl(item) do |control, arg|
      wait = Selenium::WebDriver::Wait.new(:timeout => 20)
      begin
        evaluation = wait.until { x = control
          val = x.Text
          arr = item[item.keys.first]
          arr.delete(val)
          return nil
        }
      rescue
        return nil
      end
   end
end

#Second(value) ⇒ Object



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

def Second(value)
  second = Second.new(value, $compare1, $compare2)
  $compare1 = nil
  $compare2 = nil
  return second
end

#Selected(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Selected.rb', line 4

def Selected(item)
  Evaluator.new(item) do |item, comparator| item.Selected(item, comparator) end
end

#Set(hash) ⇒ Object



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

def Set(hash)
  hash.Set hash
end

#Should(item) ⇒ Object



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

def Should(item)
  results = item.execute()
  results.Output()
end

#Show(*item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Show.rb', line 4

def Show(*item)
  Evaluator.new(item) do |item, comparator| item.first.Show(item, comparator) end
end

#Source(item) ⇒ Object



4
5
6
# File 'lib/sapphire/DSL/Evaluators/Source.rb', line 4

def Source(item)
  Source.new(item)
end

#Start(browser) ⇒ Object



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

def Start(browser)
  if(browser == ConfigurationBrowser)
    return AppConfig.Current.Browser if AppConfig.Current
    raise "No App Config defined!"
  end
  $driver.SetRootUrl(@rootUrl)
end

#Switch(browser) ⇒ Object



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

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

#To(item) ⇒ Object



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

def To(item)
  item
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/Evaluators/Transition.rb', line 4

def Transition(url)
  Evaluator.new(url) do |item, comparator| comparator.Create($driver.ShouldTransitionTo(item, comparator)) end
end

#Uncheck(item) ⇒ Object



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

def Uncheck(item)
  item.Uncheck
end

#Using(item, &block) ⇒ Object



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

def Using(item, &block)
  item.Using(item) do block.call end
end

#Virtually(&block) ⇒ Object



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

def Virtually(&block)
  ui = VirtualUI.new
  begin
    ui.Create()
    block.call
  ensure
    ui.Close()
  end
end

#Wait(item) ⇒ Object



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

def Wait(item)
  item.Wait
end

#With(item) ⇒ Object



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

def With(item)
  item
end