kinchan 0.1.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/.gitignore +9 -0
- data/.rakeTasks +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kinchan.gemspec +30 -0
- data/lib/kinchan/version.rb +5 -0
- data/lib/kinchan.rb +66 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b82350b04e5a9b22807db0d79b214df3361e9bd0dd265d8935bddf7c8d14a2fa
|
4
|
+
data.tar.gz: 861f6d1aa58b7f540973b429ab077e8e466f5240215d283dfdcb4847afb0dc96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 985cef26ece162e52e2f64ed860712b1412ab2895b11198de1755f0f03e33549f8a82c67d8da394c17d46e4443f92ced9b12675662ed5c64f0d2d988fd8fc0be
|
7
|
+
data.tar.gz: 5959195c6d85c7e9ad7d32deb56a83d56c47dcdd92e3897857cc863a63c7272d7011d364725c7e95f2ec69a34da796078e28c16337754029bc0e1db7588b7c07
|
data/.gitignore
ADDED
data/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build kinchan-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install kinchan-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install kinchan-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push kinchan-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kinchan (0.1.0)
|
5
|
+
require_all (~> 3.0.0)
|
6
|
+
selenium-webdriver (~> 3.142.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
childprocess (3.0.0)
|
12
|
+
rake (12.3.2)
|
13
|
+
require_all (3.0.0)
|
14
|
+
rubyzip (2.0.0)
|
15
|
+
selenium-webdriver (3.142.6)
|
16
|
+
childprocess (>= 0.5, < 4.0)
|
17
|
+
rubyzip (>= 1.2.2)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
kinchan!
|
24
|
+
rake (~> 12.0)
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Kyle McGough
|
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,130 @@
|
|
1
|
+
# [Kinchan](https://itazuranakiss.fandom.com/wiki/Kinnosuke_Ikezawa)
|
2
|
+
## Composable browser automation for Ruby.
|
3
|
+
|
4
|
+
### Requirements
|
5
|
+
|
6
|
+
* Ruby
|
7
|
+
* Bundler
|
8
|
+
|
9
|
+
### Getting Started
|
10
|
+
|
11
|
+
Create a new directory for your Kinchan project
|
12
|
+
|
13
|
+
`mkdir kinchan_project && cd kinchan_project`
|
14
|
+
|
15
|
+
Create the tasks directory where you'll store your Kinchan tasks
|
16
|
+
|
17
|
+
`mkdir tasks`
|
18
|
+
|
19
|
+
Initialize bundler
|
20
|
+
|
21
|
+
`bundle init`
|
22
|
+
|
23
|
+
Add the Kinchan gem to your bundle
|
24
|
+
|
25
|
+
`bundle add kinchan`
|
26
|
+
|
27
|
+
Now that we've got the structure the rest of the readme will teach you how to create, compose, and run Kinchan tasks 👽
|
28
|
+
|
29
|
+
### Creating a Task
|
30
|
+
|
31
|
+
In your tasks directory create a Ruby file with any name
|
32
|
+
|
33
|
+
e.g. `touch ruby_reddit.rb`
|
34
|
+
|
35
|
+
In your task's Ruby file you'll need to `require 'kinchan'`
|
36
|
+
|
37
|
+
and then define your task as a class that inherits from `Kinchan::Task`
|
38
|
+
|
39
|
+
so far your file should look a little something like this
|
40
|
+
```ruby
|
41
|
+
require 'kinchan'
|
42
|
+
|
43
|
+
class VisitRubysReddit < Kinchan::Task
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
All Kinchan tasks require an execute method that takes a single parameter (the selenium browser object) like so
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'kinchan'
|
51
|
+
|
52
|
+
class VisitRubyReddit < Kinchan::Task
|
53
|
+
def execute(browser)
|
54
|
+
browser.navigate.to 'https://old.reddit.com/r/ruby'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
That's all it takes to create a basic task! If we run it we'll see a browser process start and navigate to the Ruby subreddit. For a full description of the
|
60
|
+
browser API check out the [wiki page](https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings) for Ruby Selenium (they call it a "driver").
|
61
|
+
|
62
|
+
### Running a Task
|
63
|
+
|
64
|
+
Create a Ruby file in the root level of your Kinchan project and require your task
|
65
|
+
|
66
|
+
Create a new instance of the task and call `run`
|
67
|
+
|
68
|
+
e.g.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require_relative 'tasks/ruby_reddit'
|
72
|
+
|
73
|
+
VisitRubyReddit.new.run
|
74
|
+
```
|
75
|
+
|
76
|
+
That's all it takes to run a task. Kinchan handles the rest.
|
77
|
+
|
78
|
+
### Passing Data to a Task
|
79
|
+
|
80
|
+
A task's initialize function can accept options, just don't forget to call super
|
81
|
+
|
82
|
+
e.g.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
class Search < Kinchan::Task
|
86
|
+
def initialize(**options)
|
87
|
+
super
|
88
|
+
@query = options[:query]
|
89
|
+
end
|
90
|
+
|
91
|
+
def execute(browser)
|
92
|
+
browser.navigate.to 'https://www.google.com/search?q=#{CGI.escape(@query)}'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
### Composing Tasks
|
98
|
+
|
99
|
+
Tasks can call any number of other tasks either before or after they execute, and their dependencies
|
100
|
+
will have their dependencies ran and so on
|
101
|
+
|
102
|
+
This is done by specifying dependencies with a task's `@before_tasks` or `@after_tasks` in their initialize method
|
103
|
+
|
104
|
+
e.g.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
class PrintFirstResult < Kinchan::Task
|
108
|
+
def initialize(**options)
|
109
|
+
super
|
110
|
+
@before_tasks << { task: :search, options: options }
|
111
|
+
# specify that the search task should run, with the same options, before running this task
|
112
|
+
end
|
113
|
+
|
114
|
+
def execute(browser)
|
115
|
+
puts browser.execute_script "return document.querySelector('.srg a').innerText"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
Task's do not need to be in the same scope, as long as the task exists Kinchan will find and run it when appropriate
|
121
|
+
|
122
|
+
### Setting Selenium Browser Options
|
123
|
+
|
124
|
+
before running your task you can modify the selenium browser options like so
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
Kinchan::Task.browser = :chrome
|
128
|
+
Kinchan::Task.browser_options = Selenium::WebDriver::Chrome::Options.new
|
129
|
+
Kinchan::Task.browser_options.add_argument('--headless')
|
130
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kinchan"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/kinchan.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'lib/kinchan/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "kinchan"
|
5
|
+
spec.version = Kinchan::VERSION
|
6
|
+
spec.authors = ["Kyle McGough"]
|
7
|
+
spec.email = ["contact@squared.technology"]
|
8
|
+
|
9
|
+
spec.summary = %q{Composable browser automation with Ruby.}
|
10
|
+
spec.description = %q{Composable browser automation with Ruby. Create, compose, and run tasks that automate the browser with Selenium.}
|
11
|
+
spec.homepage = "https://github.com/sosodev/kinchan"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'selenium-webdriver', ['~> 3.142.6']
|
29
|
+
spec.add_runtime_dependency 'require_all', ['~> 3.0.0']
|
30
|
+
end
|
data/lib/kinchan.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'kinchan/version'
|
4
|
+
require 'selenium-webdriver'
|
5
|
+
require 'require_all'
|
6
|
+
|
7
|
+
module Kinchan
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class Task
|
11
|
+
singleton_class.send(:attr_accessor, :browser)
|
12
|
+
singleton_class.send(:attr_accessor, :browser_options)
|
13
|
+
singleton_class.send(:attr_reader, :descendants)
|
14
|
+
@descendants = []
|
15
|
+
@browser = :chrome
|
16
|
+
@browser_options = nil
|
17
|
+
@@browser_webdriver = nil
|
18
|
+
|
19
|
+
def initialize(**options)
|
20
|
+
@before_tasks = []
|
21
|
+
@after_tasks = []
|
22
|
+
@options = options
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.inherited(subclass)
|
26
|
+
Task.descendants << subclass
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.find_task(task_symbol)
|
30
|
+
Task.descendants.select { |task| task.name.split('::').last.downcase == task_symbol.to_s.downcase }[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.restart_browser
|
34
|
+
unless @@browser_webdriver.nil?
|
35
|
+
@@browser_webdriver.close
|
36
|
+
@@browser_webdriver = Selenium::WebDriver.for Task.browser
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(browser); end
|
41
|
+
|
42
|
+
def run
|
43
|
+
if @@browser_webdriver.nil?
|
44
|
+
if Task.browser_options.nil?
|
45
|
+
@@browser_webdriver = Selenium::WebDriver.for Task.browser
|
46
|
+
else
|
47
|
+
@@browser_webdriver = Selenium::WebDriver.for(Task.browser, options: Task.browser_options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@before_tasks.each do |task_hash|
|
52
|
+
task = Task.find_task(task_hash[:task])
|
53
|
+
task.new(**task_hash[:options]).public_send('run') unless task.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
execute(@@browser_webdriver)
|
57
|
+
|
58
|
+
@after_tasks.each do |task_hash|
|
59
|
+
task = Task.find_task(task_hash[:task])
|
60
|
+
task.new(**task_hash[:options]).public_send('run') unless task.nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
require_all 'tasks'
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kinchan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle McGough
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-27 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: 3.142.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.142.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: require_all
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
description: Composable browser automation with Ruby. Create, compose, and run tasks
|
42
|
+
that automate the browser with Selenium.
|
43
|
+
email:
|
44
|
+
- contact@squared.technology
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rakeTasks"
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- kinchan.gemspec
|
59
|
+
- lib/kinchan.rb
|
60
|
+
- lib/kinchan/version.rb
|
61
|
+
homepage: https://github.com/sosodev/kinchan
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata:
|
65
|
+
homepage_uri: https://github.com/sosodev/kinchan
|
66
|
+
source_code_uri: https://github.com/sosodev/kinchan
|
67
|
+
changelog_uri: https://github.com/sosodev/kinchan
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.3.0
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.1.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Composable browser automation with Ruby.
|
87
|
+
test_files: []
|