kirchhoff 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93385da45d96e5210f24498c36c53abbac104398
4
+ data.tar.gz: da60e781babe27f02338317b550bbb7fc7d2b493
5
+ SHA512:
6
+ metadata.gz: 903a4da81905ece05686438c7cbdd6e584dcd301ebc3e7488700e0500bd729623e95cf41091019f4db9cf8a291608a79c2fbe9bdf21a903e8116cd32b265fe81
7
+ data.tar.gz: 9b3ec2e8bad85de60acf365e22fcc3ca8d6ce8eadcc9ef6a104565b6270f5283eaf529cbee2d15390480a52a486d287a2549d61bb3169a64606246b3c83beeda
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gem 'pry'
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 gogotanaka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Smart Driver
2
+
3
+ Smart selenium base web driver written in Ruby.
4
+
5
+ [![Gyazo](http://i.gyazo.com/511b5265c67d41fc2cd7394c1eee3b7a.gif)](http://gyazo.com/511b5265c67d41fc2cd7394c1eee3b7a)
6
+
7
+ ## Installation
8
+
9
+ 1. Install gem as you like.
10
+
11
+ $ gem install kirchhoff
12
+
13
+ 2. Install chromedriver. (Below is the MacOS example.)
14
+
15
+ $ brew install chromedriver
16
+
17
+
18
+ ## Demo
19
+
20
+ ```rb
21
+ require 'kirchhoff'
22
+
23
+ driver = Kirchhoff::Driver.new('https://www.facebook.com/')
24
+ driver.find('input#email').fill('mail@gogotanaka.com')
25
+ driver.find('input#pass').fill('password')
26
+ driver.submit
27
+
28
+ if driver.has_text?('メールアドレスが正しくありません')
29
+ # ログインエラー後の処理
30
+ else
31
+ # ログイン成功時の処理
32
+ end
33
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smart_driver"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/kirchhoff ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "smart_driver"
data/kirchhoff.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kirchhoff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kirchhoff"
8
+ spec.version = Kirchhoff::VERSION
9
+ spec.authors = ["gogotanaka"]
10
+ spec.email = ["mail@tanakakazuki.com"]
11
+
12
+ spec.summary = %q{Smart selenium base web driver written in Ruby.}
13
+ spec.description = %q{Smart selenium base web driver written in Ruby.}
14
+ spec.homepage = "http://aisaac.in"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = "kirchhoff"
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "selenium-webdriver"
23
+ spec.add_dependency "nokogiri"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest"
28
+ end
@@ -0,0 +1,43 @@
1
+ module Kirchhoff
2
+ module CommonInterface
3
+ def find selector
4
+ e = self.find_element(css: selector).tap do
5
+ Kirchhoff::Logger.call :info, "find #{selector}..."
6
+ end
7
+
8
+ block_given? ? yield(e) : e
9
+ rescue Selenium::WebDriver::Error::NoSuchElementError
10
+ nil
11
+ end
12
+
13
+ def multi_find selector
14
+ self.find_elements(css: selector).tap do |e|
15
+ Kirchhoff::Logger.call :info, "multi find #{selector}..."
16
+ end
17
+ end
18
+
19
+ def find_text text
20
+ e = self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do
21
+ Kirchhoff::Logger.call :info, "find text '#{text}'..."
22
+ end
23
+
24
+ block_given? ? yield(e) : e
25
+ rescue Selenium::WebDriver::Error::NoSuchElementError
26
+ nil
27
+ end
28
+
29
+ def multi_find_text text
30
+ self.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |e|
31
+ Kirchhoff::Logger.call :info, "multi find text '#{text}'..."
32
+ end
33
+ end
34
+
35
+ def to_html
36
+ attribute "outerHTML"
37
+ end
38
+
39
+ def to_nokogiri
40
+ Nokogiri::HTML self.to_html
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ module Kirchhoff
2
+ module Logger
3
+ ANSI_CODES = {
4
+ :red => 31,
5
+ :green => 32,
6
+ :yellow => 33,
7
+ :blue => 34,
8
+ :gray => 90
9
+ }.freeze
10
+
11
+ class << self
12
+ def call(sym, text)
13
+ label = case sym
14
+ when :info then blue("INFO")
15
+ when :fail then red("FAIL")
16
+ end
17
+ puts "[#{label}] #{text}"
18
+ end
19
+
20
+ private
21
+ Kirchhoff::Logger::ANSI_CODES.each do |name, code|
22
+ define_method(name) do |string|
23
+ "\e[0;#{code};49m#{string}\e[0m"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Kirchhoff
2
+ VERSION = "0.0.1"
3
+ end
data/lib/kirchhoff.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'selenium-webdriver'
2
+ require 'nokogiri'
3
+
4
+ require 'kirchhoff/common_interface'
5
+ require 'kirchhoff/logger'
6
+
7
+ module Kirchhoff
8
+ class Driver
9
+ attr_accessor :__driver__
10
+ attr_reader :log_dir_path
11
+ include Kirchhoff::CommonInterface
12
+
13
+ def find_element selector
14
+ @__driver__.find_element selector
15
+ end
16
+
17
+ def find_elements selector
18
+ @__driver__.find_elements selector
19
+ end
20
+
21
+ def current_url
22
+ @__driver__.current_url
23
+ end
24
+
25
+ def initialize(url=nil, browser=:chrome)
26
+ @__driver__ = Selenium::WebDriver.for(browser)
27
+ go(url) if url
28
+ end
29
+
30
+ def go(url, &block)
31
+ @__driver__.navigate.to(url)
32
+ Kirchhoff::Logger.call :info, "visiting #{url}..."
33
+ end
34
+
35
+ def reload
36
+ @__driver__.navigate.refresh
37
+ end
38
+
39
+ def submit
40
+ $focus.submit
41
+ Kirchhoff::Logger.call :info, "submit form ..."
42
+ end
43
+
44
+ def exec_js(js_code)
45
+ @__driver__.execute_script js_code
46
+ end
47
+
48
+ def save_html(file_path)
49
+ File.open(file_path, 'w') { |f| f.write(@__driver__.page_source) }
50
+ end
51
+
52
+ def save_png(file_path)
53
+ @__driver__.save_screenshot file_path
54
+ end
55
+
56
+ def switch_window num
57
+ @__driver__.switch_to.window @__driver__.window_handles[num]
58
+ end
59
+
60
+ def wait_element selector, t=10
61
+ wait = Selenium::WebDriver::Wait.new(timeout: t)
62
+ wait.until { self.find_element(css: selector) }
63
+ end
64
+
65
+ def wait_text text, t=10
66
+ wait = Selenium::WebDriver::Wait.new(timeout: t)
67
+ wait.until { self.find_element(xpath: "//*[text()[contains(.,\"#{text}\")]]") }
68
+ end
69
+ end
70
+ end
71
+
72
+ class Selenium::WebDriver::Element
73
+ include Kirchhoff::CommonInterface
74
+ alias :origin_click :click
75
+
76
+ def click
77
+ origin_click()
78
+ end
79
+
80
+ def fill(text)
81
+ $focus = self
82
+ send_key(text)
83
+ Kirchhoff::Logger.call :info, "fill '#{text}'"
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kirchhoff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gogotanaka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: selenium-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
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Smart selenium base web driver written in Ruby.
84
+ email:
85
+ - mail@tanakakazuki.com
86
+ executables:
87
+ - kirchhoff
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - exe/kirchhoff
100
+ - kirchhoff.gemspec
101
+ - lib/kirchhoff.rb
102
+ - lib/kirchhoff/common_interface.rb
103
+ - lib/kirchhoff/logger.rb
104
+ - lib/kirchhoff/version.rb
105
+ homepage: http://aisaac.in
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Smart selenium base web driver written in Ruby.
129
+ test_files: []