smart_driver 1.1.2 → 1.2.0

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: 5398ad2839372564d16484012594e95755586130
4
- data.tar.gz: 91b1529e80bc77fd0fa247634f86c044c1beec92
3
+ metadata.gz: d8950af3cf27acea7863e03e51e09e5aaecd19d7
4
+ data.tar.gz: 564b0a0a7c9d3d5ddd108177a6217a2dd39ae710
5
5
  SHA512:
6
- metadata.gz: 0c0b93b55e343c5675d0054a640f09fe8d377129e57abad21908e23eb9734db145044940c7249d0bcd3ab031457a0e2312e22c3ffecf945e2c9eb5bd9b2fc128
7
- data.tar.gz: 909bfd55ca17f66f0c07afda69b0ad9011e9662c9a5e6e27c9646c555c4ddb5067b4869f521d79359dee5a0e5de2240bb16225e1dc333123935c3946917d0af8
6
+ metadata.gz: ef36a8861e420531bea3befb707c06589bfcd70f3e2bbc97ac2dae8cafc6dadb5a9f660e601c7396cdc4e112b8b375fbaa75e3e0a125640e8137a44382c317e1
7
+ data.tar.gz: c315138636715579852bcb920e33a8ee23e3bf1a03c57c36cd698cbdb036e837a3372b71bfc088efea22c8391813bae43e37758bd3a630804c33fdf0cd7a37b6
@@ -1,5 +1,45 @@
1
1
  class SmartDriver
2
2
  module CommonInterface
3
+ def find(selector)
4
+ self.find_element(css: selector).tap do |e|
5
+ logging :info, "find #{selector}..."
6
+ yield(e) if block_given?
7
+ end
8
+ end
9
+
10
+ def finds(selector)
11
+ self.find_elements(css: selector).tap do |es|
12
+ logging :info, "finds #{selector}..."
13
+ end
14
+ end
15
+
16
+ def find_text(text)
17
+ self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |e|
18
+ logging :info, "find text '#{text}'..."
19
+ yield(e) if block_given?
20
+ end
21
+ end
22
+
23
+ def finds_text(text)
24
+ self.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |es|
25
+ logging :info, "finds text '#{text}'..."
26
+ end
27
+ end
28
+
29
+ def has?(selector)
30
+ self.find_element(css: selector)
31
+ true
32
+ rescue Selenium::WebDriver::Error::NoSuchElementError
33
+ false
34
+ end
35
+
36
+ def has_text?(text)
37
+ self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
38
+ true
39
+ rescue Selenium::WebDriver::Error::NoSuchElementError
40
+ false
41
+ end
42
+
3
43
  def to_html
4
44
  attribute("outerHTML")
5
45
  end
@@ -1,3 +1,3 @@
1
1
  class SmartDriver
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/smart_driver.rb CHANGED
@@ -12,38 +12,6 @@ class SmartDriver
12
12
  go(url) if url
13
13
  end
14
14
 
15
- def find(selector)
16
- logging :info, "find #{selector}..."
17
- @__driver__.find_element(css: selector)
18
- rescue Selenium::WebDriver::Error::NoSuchElementError
19
- logging :fail, "#{selector} cannot be found"
20
- nil
21
- end
22
-
23
- def finds(selector)
24
- logging :info, "finds #{selector}..."
25
- @__driver__.find_elements(css: selector)
26
- rescue Selenium::WebDriver::Error::NoSuchElementError
27
- logging :fail, "#{selector} cannot be found"
28
- nil
29
- end
30
-
31
- def find_text(text)
32
- logging :info, "find text '#{text}'..."
33
- @__driver__.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
34
- rescue Selenium::WebDriver::Error::NoSuchElementError
35
- logging :fail, "text '#{text}' cannot be found"
36
- nil
37
- end
38
-
39
- def finds_text(text)
40
- logging :info, "finds text '#{text}'..."
41
- @__driver__.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
42
- rescue Selenium::WebDriver::Error::NoSuchElementError
43
- logging :fail, "text #{text} cannot be found"
44
- nil
45
- end
46
-
47
15
  def go(url)
48
16
  logging :info, "visiting #{url}..."
49
17
  @__driver__.navigate.to(url)
@@ -53,9 +21,15 @@ class SmartDriver
53
21
  @__driver__.navigate.refresh
54
22
  end
55
23
 
56
- def submit
24
+ def submit(n=20)
57
25
  logging :info, "submit form ..."
58
- $focus.submit if $focus
26
+ $focus.submit
27
+ if block_given?
28
+ n.times do
29
+ break if yield()
30
+ sleep 0.5
31
+ end
32
+ end
59
33
  end
60
34
 
61
35
  def exec_js(js_code)
@@ -77,41 +51,26 @@ class SmartDriver
77
51
  def switch_window(num)
78
52
  @__driver__.switch_to.window @__driver__.window_handles[num]
79
53
  end
80
- end
81
54
 
82
- class Selenium::WebDriver::Element
83
- include SmartDriver::CommonInterface
84
-
85
- def find(selector)
86
- logging :info, "find #{selector} in element..."
87
- self.find_element(css: selector)
88
- rescue Selenium::WebDriver::Error::NoSuchElementError
89
- logging :fail, "#{selector} cannot be found in element..."
90
- nil
91
- end
92
-
93
- def finds(selector)
94
- logging :info, "finds #{selector} in element..."
95
- self.find_elements(css: selector)
96
- rescue Selenium::WebDriver::Error::NoSuchElementError
97
- logging :fail, "#{selector} cannot be found in element..."
98
- nil
99
- end
100
-
101
- def find_text(text)
102
- logging :info, "find text '#{text}'..."
103
- self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
55
+ def maybe(&block)
56
+ block.call()
104
57
  rescue Selenium::WebDriver::Error::NoSuchElementError
105
- logging :fail, "text '#{text}' cannot be found"
106
58
  nil
107
59
  end
60
+ end
108
61
 
109
- def finds_text(text)
110
- logging :info, "finds text '#{text}'..."
111
- self.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
112
- rescue Selenium::WebDriver::Error::NoSuchElementError
113
- logging :fail, "text #{text} cannot be found"
114
- nil
62
+ class Selenium::WebDriver::Element
63
+ include SmartDriver::CommonInterface
64
+ alias :origin_click :click
65
+
66
+ def click(n=20)
67
+ origin_click()
68
+ if block_given?
69
+ n.times do
70
+ break if yield()
71
+ sleep 0.5
72
+ end
73
+ end
115
74
  end
116
75
 
117
76
  def fill(text)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-03 00:00:00.000000000 Z
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver