kirchhoff 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93385da45d96e5210f24498c36c53abbac104398
4
- data.tar.gz: da60e781babe27f02338317b550bbb7fc7d2b493
3
+ metadata.gz: 4b4685b6ac03e6611ca24f2337f79d12078ea07a
4
+ data.tar.gz: 87cc14431e9556168881c17e0d2ddd08255dcab4
5
5
  SHA512:
6
- metadata.gz: 903a4da81905ece05686438c7cbdd6e584dcd301ebc3e7488700e0500bd729623e95cf41091019f4db9cf8a291608a79c2fbe9bdf21a903e8116cd32b265fe81
7
- data.tar.gz: 9b3ec2e8bad85de60acf365e22fcc3ca8d6ce8eadcc9ef6a104565b6270f5283eaf529cbee2d15390480a52a486d287a2549d61bb3169a64606246b3c83beeda
6
+ metadata.gz: 2b7fe60b4f1676c657dac0c62f67cb75c2e0a16370732a5029a0ec462ad6a260d6af6b485dc7c5b6cc63f117f23a01f07bb7c91cfbcc5351fd85b12b312fb4e9
7
+ data.tar.gz: 962ae7e2550548e7bb6992ff575c9b0d04802daae0beafe32316e63dc098c66a65f1279907ab601de49f714571f2a51f53d9f82a7642d75094472a6c94ea5a90
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "smart_driver"
4
+ require "kirchhoff"
5
+
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
data/exe/kirchhoff CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "smart_driver"
3
+ require "kirchhoff"
@@ -1,3 +1,3 @@
1
1
  module Kirchhoff
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/kirchhoff.rb CHANGED
@@ -6,7 +6,7 @@ require 'kirchhoff/logger'
6
6
 
7
7
  module Kirchhoff
8
8
  class Driver
9
- attr_accessor :__driver__
9
+ attr_accessor :__driver__, :default_timeout
10
10
  attr_reader :log_dir_path
11
11
  include Kirchhoff::CommonInterface
12
12
 
@@ -22,12 +22,16 @@ module Kirchhoff
22
22
  @__driver__.current_url
23
23
  end
24
24
 
25
- def initialize(url=nil, browser=:chrome)
26
- @__driver__ = Selenium::WebDriver.for(browser)
27
- go(url) if url
25
+ def quit
26
+ @__driver__.quit
28
27
  end
29
28
 
30
- def go(url, &block)
29
+ def initialize(browser: :chrome, default_timeout: 6)
30
+ @__driver__ = Selenium::WebDriver.for(browser)
31
+ @default_timeout = default_timeout
32
+ end
33
+
34
+ def go url
31
35
  @__driver__.navigate.to(url)
32
36
  Kirchhoff::Logger.call :info, "visiting #{url}..."
33
37
  end
@@ -57,14 +61,26 @@ module Kirchhoff
57
61
  @__driver__.switch_to.window @__driver__.window_handles[num]
58
62
  end
59
63
 
60
- def wait_element selector, t=10
61
- wait = Selenium::WebDriver::Wait.new(timeout: t)
64
+ def wait_element(selector, maybe: true, t: nil)
65
+ wait = Selenium::WebDriver::Wait.new(timeout: (t || @default_timeout))
62
66
  wait.until { self.find_element(css: selector) }
67
+ rescue Selenium::WebDriver::Error::TimeOutError
68
+ unless maybe
69
+ raise Selenium::WebDriver::Error::TimeOutError, "selector: #{selector}"
70
+ end
63
71
  end
64
72
 
65
- def wait_text text, t=10
66
- wait = Selenium::WebDriver::Wait.new(timeout: t)
73
+ def wait_text(text, maybe: true, t: nil)
74
+ wait = Selenium::WebDriver::Wait.new(timeout: (t || @default_timeout))
67
75
  wait.until { self.find_element(xpath: "//*[text()[contains(.,\"#{text}\")]]") }
76
+ rescue Selenium::WebDriver::Error::TimeOutError
77
+ unless maybe
78
+ raise Selenium::WebDriver::Error::TimeOutError, "text: #{text}"
79
+ end
80
+ end
81
+
82
+ def to_html
83
+ self.__driver__.page_source
68
84
  end
69
85
  end
70
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kirchhoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver