smart_driver 1.0.0

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: e073d66d4fa0efa5bc1c717a2279859e3a3c62c1
4
+ data.tar.gz: 392215ac3bf4fe649ada1044102dec286bb1376a
5
+ SHA512:
6
+ metadata.gz: 8dd1103f8d0f2e945243dd843ad3e0cc407be15c6ab0594d243eaa7f3d1e10d2e9da820674f566ed5e5f65170c7a189276124b9f62374aaa6eaa696e0e00cc3c
7
+ data.tar.gz: 4c22b5bf8ff9aa7123ec0153b9538e91dd7df8ce9793637aeaf1737ab668b9f7a43fc51bfc2d113673d8a03fb2793cef6bb154d382f51158bada8bafb18de3a7
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 smart_driver
12
+
13
+ 2. Install chromedriver. (Below is the MacOS example.)
14
+
15
+ $ brew install chromedriver
16
+
17
+
18
+ ## Demo
19
+
20
+ ```rb
21
+ require 'smart_driver'
22
+
23
+ driver = SmartDriver.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/smart_driver ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "smart_driver"
@@ -0,0 +1,113 @@
1
+ require 'selenium-webdriver'
2
+
3
+ class SmartDriver
4
+ attr_accessor :__driver__
5
+
6
+ def initialize(url=nil, browser=:chrome)
7
+ @__driver__ = Selenium::WebDriver.for(browser)
8
+ go(url) if url
9
+ end
10
+
11
+ def go(url)
12
+ logging :info, "visiting #{url}..."
13
+ @__driver__.navigate.to(url)
14
+ end
15
+
16
+ def reload
17
+ @__driver__.navigate.refresh
18
+ end
19
+
20
+ def find(selector)
21
+ logging :info, "find #{selector}..."
22
+ @__driver__.find_element(css: selector)
23
+ rescue Selenium::WebDriver::Error::NoSuchElementError
24
+ logging :fail, "#{selector} cannot be found"
25
+ end
26
+
27
+ def finds(selector)
28
+ logging :info, "finds #{selector}..."
29
+ @__driver__.find_elements(css: selector)
30
+ rescue Selenium::WebDriver::Error::NoSuchElementError
31
+ logging :fail, "#{selector} cannot be found"
32
+ end
33
+
34
+ # http://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error
35
+ def scroll(selector)
36
+ logging :info, "scroll to #{selector}..."
37
+ element = find(selector)
38
+ exec_js "window.scrollTo(#{element.location.x},#{element.location.y})"
39
+ element
40
+ end
41
+
42
+ def has?(selector)
43
+ !!find(selector)
44
+ rescue Selenium::WebDriver::Error::NoSuchElementError
45
+ false
46
+ end
47
+
48
+ def has_text?(text)
49
+ !!@__driver__.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
50
+ rescue Selenium::WebDriver::Error::NoSuchElementError
51
+ false
52
+ end
53
+
54
+ def click(selector)
55
+ logging :info, "click #{selector}..."
56
+ has?(selector) ? find(selector).click : false
57
+ end
58
+
59
+ def submit
60
+ logging :info, "submit form ..."
61
+ $focus.submit if $focus
62
+ end
63
+
64
+ def exec_js(js_code)
65
+ @__driver__.execute_script js_code
66
+ end
67
+
68
+ def save_html(file_path)
69
+ File.open(file_path, 'w') { |f| f.write(@__driver__.page_source) }
70
+ end
71
+
72
+ def method_missing(method, *args, &block)
73
+ @__driver__.respond_to?(method) ? @__driver__.send(method, *args, &block) : super
74
+ end
75
+
76
+ private
77
+ def logging(sym, text)
78
+ label = case sym
79
+ when :info then "INFO"
80
+ when :fail then "FAIL"
81
+ end
82
+ puts "[#{label}] #{text}"
83
+ end
84
+ end
85
+
86
+ class Selenium::WebDriver::Element
87
+ def fill(text)
88
+ $focus = self
89
+ logging :info, "fill #{text}..."
90
+ send_key(text)
91
+ end
92
+
93
+ def find(selector)
94
+ find_element(css: selector)
95
+ end
96
+
97
+ def finds(selector)
98
+ find_elements(css: selector)
99
+ end
100
+
101
+ def to_html
102
+ attribute("outerHTML")
103
+ end
104
+
105
+ private
106
+ def logging(sym, text)
107
+ label = case sym
108
+ when :info then "INFO"
109
+ when :fail then "FAIL"
110
+ end
111
+ puts "[#{label}] #{text}"
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ class SmartDriver
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smart_driver/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smart_driver"
8
+ spec.version = SmartDriver::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
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "selenium-webdriver"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest"
35
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_driver
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - gogotanaka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-02 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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Smart selenium base web driver written in Ruby.
70
+ email:
71
+ - mail@tanakakazuki.com
72
+ executables:
73
+ - smart_driver
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - exe/smart_driver
86
+ - lib/smart_driver.rb
87
+ - lib/smart_driver/version.rb
88
+ - smart_driver.gemspec
89
+ homepage: http://aisaac.in
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Smart selenium base web driver written in Ruby.
113
+ test_files: []