Class: Ehbrs::Google::Translate::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs/google/translate/session.rb

Constant Summary collapse

START_URL =
'https://translate.google.com.br/#view=home&op=docs&sl=en&tl=pt'
CLOSE_POPUP_CSS =
'.dismiss-button'
FILE_INPUT_XPATH =
'//*[@id = "tlid-file-input"]'
SUBMIT_XPATH =
'//form[@action="//translate.googleusercontent.com/translate_f"]' \
'//input[@type="submit"]'
RESULT_XPATHS =
[
  '//script[contains(@src, "https://translate.google.com/translate_a")]',
  '/html/body/pre'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



21
22
23
# File 'lib/ehbrs/google/translate/session.rb', line 21

def initialize
  @sub = ::Aranha::Selenium::Session.new
end

Instance Attribute Details

#subObject (readonly)

Returns the value of attribute sub.



19
20
21
# File 'lib/ehbrs/google/translate/session.rb', line 19

def sub
  @sub
end

Instance Method Details

#translate(source_document_path) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/ehbrs/google/translate/session.rb', line 25

def translate(source_document_path)
  go_to_upload_form
  input_file(source_document_path)
  close_changes_alert_popup
  click_on_translate_button
  wait_for_load_translation
  sub.current_source
end