Class: Locution::Sdk::Listener

Inherits:
Selenium::WebDriver::Support::AbstractEventListener
  • Object
show all
Defined in:
lib/locution/sdk/listener.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token, test_name = "not provided", base_url = 'http://locution.herokuapp.com') ⇒ Listener

Returns a new instance of Listener.



8
9
10
11
12
13
14
15
16
17
# File 'lib/locution/sdk/listener.rb', line 8

def initialize(access_token, test_name = "not provided", base_url = 'http://locution.herokuapp.com')
  @base_url = base_url
  @access_token = access_token
  response = ::RestClient.post "#{@base_url}/tests", {
    access_token: access_token,
    test_name: test_name,
    start_time: Time.now
  }
  @test_id = response.body
end

Instance Method Details

#after_find(by, what, driver) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/locution/sdk/listener.rb', line 24

def after_find(by, what, driver)
  ::RestClient.post "#{@base_url}/tests/#{@test_id}/locators", {
    access_token: @access_token,
    locator_value: "#{by}, #{what}",
    locator_count: @number_of_elements_found,
    start_time: @locator_start_time,
    end_time: Time.now
  }
end

#after_quit(driver) ⇒ Object



34
35
36
37
38
39
# File 'lib/locution/sdk/listener.rb', line 34

def after_quit(driver)
  ::RestClient.put "#{@base_url}/tests/#{@test_id}", {
    access_token: @access_token,
    end_time: Time.now
  }
end

#before_find(by, what, driver) ⇒ Object



19
20
21
22
# File 'lib/locution/sdk/listener.rb', line 19

def before_find(by, what, driver)
  @number_of_elements_found = driver.execute_script("return #{get_javascript(by, what)}")
  @locator_start_time = Time.now
end