Class: Flunky::Actions

Inherits:
Object
  • Object
show all
Defined in:
lib/flunky/actions.rb

Overview

The human-readable action DSL over a driver. Each mutating action returns a small result hash so the tool layer can report outcomes uniformly.

Actions also holds a reference to its session because field resolution (fill_in by label) reads the session’s current snapshot, the same way a person finds a field by the label printed next to it.

Constant Summary collapse

SCROLL_STEP =
600

Instance Method Summary collapse

Constructor Details

#initialize(driver, session) ⇒ Actions

Returns a new instance of Actions.



13
14
15
16
# File 'lib/flunky/actions.rb', line 13

def initialize(driver, session)
  @driver = driver
  @session = session
end

Instance Method Details

#check(ref) ⇒ Object



45
46
47
48
# File 'lib/flunky/actions.rb', line 45

def check(ref)
  @driver.click(ref)
  ok("checked [#{ref}]")
end

#click(ref) ⇒ Object



23
24
25
26
# File 'lib/flunky/actions.rb', line 23

def click(ref)
  @driver.click(ref)
  ok("clicked [#{ref}]")
end

#current_urlObject



61
62
63
# File 'lib/flunky/actions.rb', line 61

def current_url
  @driver.current_url
end

#fill_in(label, with:) ⇒ Object

Resolve a field by its label or placeholder, then type into it.



34
35
36
37
38
# File 'lib/flunky/actions.rb', line 34

def fill_in(label, with:)
  ref = field_ref(label)
  @driver.type_text(ref, with, clear: true)
  ok(%(filled "#{label}" with "#{with}"))
end


18
19
20
21
# File 'lib/flunky/actions.rb', line 18

def navigate(url)
  @driver.go_to(url)
  ok("navigated to #{url}")
end

#press(key) ⇒ Object



50
51
52
53
# File 'lib/flunky/actions.rb', line 50

def press(key)
  @driver.press_key(key)
  ok("pressed #{key}")
end

#screenshotObject



65
66
67
# File 'lib/flunky/actions.rb', line 65

def screenshot
  @driver.screenshot_base64
end

#scroll(direction) ⇒ Object



55
56
57
58
59
# File 'lib/flunky/actions.rb', line 55

def scroll(direction)
  dx, dy = scroll_delta(direction)
  @driver.scroll_by(dx, dy)
  ok("scrolled #{direction}")
end

#select(value, ref:) ⇒ Object



40
41
42
43
# File 'lib/flunky/actions.rb', line 40

def select(value, ref:)
  @driver.select_option(ref, value)
  ok(%(selected "#{value}" in [#{ref}]))
end

#type(ref, text) ⇒ Object



28
29
30
31
# File 'lib/flunky/actions.rb', line 28

def type(ref, text)
  @driver.type_text(ref, text, clear: true)
  ok(%(typed "#{text}" into [#{ref}]))
end