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_execute_script(script, driver) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/locution/sdk/listener.rb', line 42

def after_execute_script(script, driver)
  unless @ignore_javascript_inspection
    ::RestClient.post "#{@base_url}/tests/#{@test_id}/locators", {
      access_token: @access_token,
      locator_value: "execute script, #{script}",
      start_time: @locator_start_time,
      end_time: Time.now
    }
  end
end

#after_find(by, what, driver) ⇒ Object



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

def after_find(by, what, driver)
  @ignore_javascript_inspection = false
  ::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



53
54
55
56
57
58
# File 'lib/locution/sdk/listener.rb', line 53

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

#before_execute_script(script, driver) ⇒ Object



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

def before_execute_script(script, driver)
  unless @ignore_javascript_inspection
    @locator_start_time = Time.now
  end
end

#before_find(by, what, driver) ⇒ Object



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

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