omnibrowser 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/omni_browser.rb +66 -0
- data/lib/omni_browser/watir.rb +57 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fad2bdcd7f187721946fd98e8ff813d0ff5d89a2
|
4
|
+
data.tar.gz: 2d6e1ebb28117ddaa4adb76f59f281915d882f59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7afac90decb2b5cbe0434f6f80f35312af14dc7ad2dcebc3c7f9e1e1fda875931a8013c58a7bc13d0c260efd91a77eb0cf1d5c7eb7badb110504722bf1c9cf7e
|
7
|
+
data.tar.gz: 222d7576d9a1ec56b3e76e05e49dcfd13b3feb125ea5c3ed3f34b4dd390bd577611d2a9fcffff985197ff01fd6460c34931c1f73da02138c52c4f3abb7c348eb
|
data/lib/omni_browser.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'omni_browser/watir'
|
2
|
+
require 'watir-webdriver'
|
3
|
+
require 'watir-webdriver/alerts'
|
4
|
+
|
5
|
+
class OmniBrowser
|
6
|
+
|
7
|
+
FIREFOX_41 = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'
|
8
|
+
|
9
|
+
CHROME = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
|
10
|
+
|
11
|
+
def initialize (*config)
|
12
|
+
profile = Selenium::Webdriver::Firefox::Profile.new
|
13
|
+
|
14
|
+
profile['javascript.enabled'] = false if config.include?(:no_java)
|
15
|
+
profile['general.useragent.override'] =
|
16
|
+
case
|
17
|
+
when config.include?(:firefox_41)
|
18
|
+
FIREFOX_41
|
19
|
+
else
|
20
|
+
CHROME
|
21
|
+
end
|
22
|
+
|
23
|
+
@browser = Watir::Browser.new(:firefox, profile: profile)
|
24
|
+
end
|
25
|
+
|
26
|
+
def resize (width, height = nil)
|
27
|
+
height = width if height.nil?
|
28
|
+
@browser.window.resize_to(width, height)
|
29
|
+
end
|
30
|
+
|
31
|
+
def move (x, y)
|
32
|
+
@browser.window.move_to(x, y)
|
33
|
+
end
|
34
|
+
|
35
|
+
def zoom_out (times)
|
36
|
+
times.times do
|
37
|
+
@browser.send_keys([:command, :subtract])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def position
|
42
|
+
@browser.windows.first.position.to_a
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
@browser.windows.first.size.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing (method, *args, &block)
|
50
|
+
@browser.send(method, *args, block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def domain
|
54
|
+
@browser.url.scan(/[^\/]+/)[1]
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_html (path)
|
58
|
+
path = path
|
59
|
+
path << '.html' unless path =~ /.+\.html\z/
|
60
|
+
|
61
|
+
file = File.open(path, 'w')
|
62
|
+
file.puts @browser.html
|
63
|
+
file.close
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
PRINT_LINE = '------------------'
|
2
|
+
|
3
|
+
module Watir
|
4
|
+
|
5
|
+
class Element
|
6
|
+
|
7
|
+
def child_print (*tag_names)
|
8
|
+
tags = tag_names.flatten
|
9
|
+
tally = {}
|
10
|
+
|
11
|
+
print_line = ->(element) {
|
12
|
+
tally.find_add(element.tag_name)
|
13
|
+
puts "<#{element.tag_name}> #{tally[element.tag_name] - 1} | #{element.text.inspect} | #{element.elements.size}"
|
14
|
+
}
|
15
|
+
|
16
|
+
if tags.size == 0
|
17
|
+
work = ->(element) {
|
18
|
+
print_line.call(element)
|
19
|
+
}
|
20
|
+
else
|
21
|
+
work = ->(element) {
|
22
|
+
print_line.call(element) if tags.include?(element.tag_name)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
self.elements.each { |element|
|
27
|
+
work.call(element)
|
28
|
+
}
|
29
|
+
|
30
|
+
puts tally.to_yaml
|
31
|
+
puts self.elements.size
|
32
|
+
puts PRINT_LINE
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class ElementCollection
|
38
|
+
|
39
|
+
def each_print
|
40
|
+
self.each { |element|
|
41
|
+
output = [element.text.inspect]
|
42
|
+
output << element.class_name.inspect
|
43
|
+
output << element.id.inspect
|
44
|
+
puts output.join(', ')
|
45
|
+
}
|
46
|
+
puts PRINT_LINE
|
47
|
+
end
|
48
|
+
|
49
|
+
def text
|
50
|
+
self.inject([]) { |acc, element|
|
51
|
+
acc << element.text
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omnibrowser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Lai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: watir-webdriver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: To do
|
28
|
+
email: ejt.lai@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/omni_browser.rb
|
34
|
+
- lib/omni_browser/watir.rb
|
35
|
+
homepage:
|
36
|
+
licenses: []
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.5.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A powerful automated browser
|
58
|
+
test_files: []
|