Class: Browserbeam::Session
- Inherits:
-
Object
- Object
- Browserbeam::Session
- Defined in:
- lib/browserbeam/session.rb
Instance Attribute Summary collapse
-
#blockers_dismissed ⇒ Object
readonly
Returns the value of attribute blockers_dismissed.
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#extraction ⇒ Object
readonly
Returns the value of attribute extraction.
-
#media ⇒ Object
readonly
Returns the value of attribute media.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #act(steps) ⇒ Object
- #check(ref: nil, text: nil, label: nil, checked: nil) ⇒ Object
- #click(ref: nil, text: nil, label: nil) ⇒ Object
- #close ⇒ Object
- #execute_js(code, result_key: nil, timeout: nil) ⇒ Object
- #extract(**schema) ⇒ Object
- #fill(value, ref: nil, text: nil, label: nil) ⇒ Object
- #fill_form(fields, submit: false) ⇒ Object
- #goto(url, wait_for: nil, wait_until: nil, wait_timeout: nil) ⇒ Object
-
#initialize(envelope, http) ⇒ Session
constructor
A new instance of Session.
- #last_response ⇒ Object
- #observe(scope: nil, format: nil, mode: nil, include_page_map: nil, include_links: nil, max_text_length: nil) ⇒ Object
- #pdf(format: nil, landscape: nil, print_background: nil, scale: nil, margin: nil) ⇒ Object
- #screenshot(full_page: nil, format: nil, quality: nil, selector: nil) ⇒ Object
- #scroll(to: nil, direction: nil, amount: nil, times: nil, ref: nil, text: nil, label: nil) ⇒ Object
- #scroll_collect(max_scrolls: nil, wait_ms: nil, timeout_ms: nil, max_text_length: nil) ⇒ Object
- #select(value, ref: nil, text: nil, label: nil) ⇒ Object
- #type(value, ref: nil, text: nil, label: nil, delay: nil) ⇒ Object
- #upload(files, ref: nil, text: nil, label: nil) ⇒ Object
- #wait(ms: nil, selector: nil, text: nil, timeout: nil, **opts) ⇒ Object
Constructor Details
#initialize(envelope, http) ⇒ Session
Returns a new instance of Session.
6 7 8 9 |
# File 'lib/browserbeam/session.rb', line 6 def initialize(envelope, http) @http = http update(envelope) end |
Instance Attribute Details
#blockers_dismissed ⇒ Object (readonly)
Returns the value of attribute blockers_dismissed.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def blockers_dismissed @blockers_dismissed end |
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def completed @completed end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def error @error end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def expires_at @expires_at end |
#extraction ⇒ Object (readonly)
Returns the value of attribute extraction.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def extraction @extraction end |
#media ⇒ Object (readonly)
Returns the value of attribute media.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def media @media end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def page @page end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def request_id @request_id end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
3 4 5 |
# File 'lib/browserbeam/session.rb', line 3 def session_id @session_id end |
Instance Method Details
#act(steps) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/browserbeam/session.rb', line 15 def act(steps) data = @http.post("/v1/sessions/#{session_id}/act", { steps: steps }) envelope = SessionEnvelope.from_hash(data) update(envelope) envelope end |
#check(ref: nil, text: nil, label: nil, checked: nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/browserbeam/session.rb', line 74 def check(ref: nil, text: nil, label: nil, checked: nil) params = {} params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label params[:checked] = checked unless checked.nil? act([{ check: params }]) end |
#click(ref: nil, text: nil, label: nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/browserbeam/session.rb', line 41 def click(ref: nil, text: nil, label: nil) params = {} params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label act([{ click: params }]) end |
#close ⇒ Object
158 159 160 |
# File 'lib/browserbeam/session.rb', line 158 def close act([{ close: {} }]) end |
#execute_js(code, result_key: nil, timeout: nil) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/browserbeam/session.rb', line 151 def execute_js(code, result_key: nil, timeout: nil) params = { code: code } params[:result_key] = result_key if result_key params[:timeout] = timeout if timeout act([{ execute_js: params }]) end |
#extract(**schema) ⇒ Object
123 124 125 |
# File 'lib/browserbeam/session.rb', line 123 def extract(**schema) act([{ extract: schema }]) end |
#fill(value, ref: nil, text: nil, label: nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/browserbeam/session.rb', line 49 def fill(value, ref: nil, text: nil, label: nil) params = { value: value } params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label act([{ fill: params }]) end |
#fill_form(fields, submit: false) ⇒ Object
127 128 129 130 131 |
# File 'lib/browserbeam/session.rb', line 127 def fill_form(fields, submit: false) params = { fields: fields } params[:submit] = true if submit act([{ fill_form: params }]) end |
#goto(url, wait_for: nil, wait_until: nil, wait_timeout: nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/browserbeam/session.rb', line 22 def goto(url, wait_for: nil, wait_until: nil, wait_timeout: nil) params = { url: url } params[:wait_for] = wait_for if wait_for params[:wait_until] = wait_until if wait_until params[:wait_timeout] = wait_timeout if wait_timeout act([{ goto: params }]) end |
#last_response ⇒ Object
11 12 13 |
# File 'lib/browserbeam/session.rb', line 11 def last_response @last end |
#observe(scope: nil, format: nil, mode: nil, include_page_map: nil, include_links: nil, max_text_length: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/browserbeam/session.rb', line 30 def observe(scope: nil, format: nil, mode: nil, include_page_map: nil, include_links: nil, max_text_length: nil) params = {} params[:scope] = scope if scope params[:format] = format if format params[:mode] = mode if mode params[:include_page_map] = include_page_map unless include_page_map.nil? params[:include_links] = include_links unless include_links.nil? params[:max_text_length] = max_text_length if max_text_length act([{ observe: params }]) end |
#pdf(format: nil, landscape: nil, print_background: nil, scale: nil, margin: nil) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/browserbeam/session.rb', line 141 def pdf(format: nil, landscape: nil, print_background: nil, scale: nil, margin: nil) params = {} params[:format] = format if format params[:landscape] = landscape unless landscape.nil? params[:print_background] = print_background unless print_background.nil? params[:scale] = scale if scale params[:margin] = margin if margin act([{ pdf: params }]) end |
#screenshot(full_page: nil, format: nil, quality: nil, selector: nil) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/browserbeam/session.rb', line 104 def screenshot(full_page: nil, format: nil, quality: nil, selector: nil) params = {} params[:full_page] = full_page unless full_page.nil? params[:format] = format if format params[:quality] = quality if quality params[:selector] = selector if selector act([{ screenshot: params }]) end |
#scroll(to: nil, direction: nil, amount: nil, times: nil, ref: nil, text: nil, label: nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/browserbeam/session.rb', line 83 def scroll(to: nil, direction: nil, amount: nil, times: nil, ref: nil, text: nil, label: nil) params = {} params[:to] = to if to params[:direction] = direction if direction params[:amount] = amount if amount params[:times] = times if times params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label act([{ scroll: params }]) end |
#scroll_collect(max_scrolls: nil, wait_ms: nil, timeout_ms: nil, max_text_length: nil) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/browserbeam/session.rb', line 95 def scroll_collect(max_scrolls: nil, wait_ms: nil, timeout_ms: nil, max_text_length: nil) params = {} params[:max_scrolls] = max_scrolls if max_scrolls params[:wait_ms] = wait_ms if wait_ms params[:timeout_ms] = timeout_ms if timeout_ms params[:max_text_length] = max_text_length if max_text_length act([{ scroll_collect: params }]) end |
#select(value, ref: nil, text: nil, label: nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/browserbeam/session.rb', line 66 def select(value, ref: nil, text: nil, label: nil) params = { value: value } params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label act([{ select: params }]) end |
#type(value, ref: nil, text: nil, label: nil, delay: nil) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/browserbeam/session.rb', line 57 def type(value, ref: nil, text: nil, label: nil, delay: nil) params = { value: value } params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label params[:delay] = delay if delay act([{ type: params }]) end |
#upload(files, ref: nil, text: nil, label: nil) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/browserbeam/session.rb', line 133 def upload(files, ref: nil, text: nil, label: nil) params = { files: files } params[:ref] = ref if ref params[:text] = text if text params[:label] = label if label act([{ upload: params }]) end |
#wait(ms: nil, selector: nil, text: nil, timeout: nil, **opts) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/browserbeam/session.rb', line 113 def wait(ms: nil, selector: nil, text: nil, timeout: nil, **opts) params = {} params[:ms] = ms if ms params[:selector] = selector if selector params[:text] = text if text params[:until] = opts[:until] if opts[:until] params[:timeout] = timeout if timeout act([{ wait: params }]) end |