selenium_standalone_dsl 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dae05766cf64fc31e2f4077e1bde3ccc939f9d86
4
+ data.tar.gz: 0d1d23106b80832857882680767afad024b70587
5
+ SHA512:
6
+ metadata.gz: f48e42c2fb25468467c6a7f694cad55a673b1b94ea643b4b105d8955c6d65ba33f660578333351ee53c564866dcbf6fb81cabb8a35a1783bc044d913d53d9a54
7
+ data.tar.gz: 42540bd565063aa36f2ec1954f940236fa9e3f818d7d642803fa22b758a0461421f24a667a8250c80d748fc234cbb3e7a7b644c89b58ad3dba93000fcd24bb75
data/.gitignore ADDED
@@ -0,0 +1,58 @@
1
+ ### https://raw.github.com/github/gitignore/3a0542080daab73605fad0a9e190794ef2fc722d/Ruby.gitignore
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /spec/examples.txt
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+
53
+
54
+ /tmp/*
55
+ !/tmp/.gitkeep
56
+
57
+ /logs/*
58
+ !/logs/.gitkeep
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ketsume0211@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'selenium-webdriver'
4
+ gem 'nokogiri'
5
+ gem 'headless'
6
+ gem 'activesupport'
7
+ gem 'rake'
8
+
9
+ group :development, :staging do
10
+ gem 'pry'
11
+ gem 'rspec'
12
+ gem 'sinatra'
13
+ end
14
+
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (5.0.0.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (~> 0.7)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ childprocess (0.5.9)
10
+ ffi (~> 1.0, >= 1.0.11)
11
+ coderay (1.1.1)
12
+ concurrent-ruby (1.0.2)
13
+ diff-lcs (1.2.5)
14
+ ffi (1.9.14)
15
+ headless (2.3.1)
16
+ i18n (0.7.0)
17
+ method_source (0.8.2)
18
+ mini_portile2 (2.1.0)
19
+ minitest (5.9.0)
20
+ nokogiri (1.6.8)
21
+ mini_portile2 (~> 2.1.0)
22
+ pkg-config (~> 1.1.7)
23
+ pkg-config (1.1.7)
24
+ pry (0.10.4)
25
+ coderay (~> 1.1.0)
26
+ method_source (~> 0.8.1)
27
+ slop (~> 3.4)
28
+ rack (1.6.4)
29
+ rack-protection (1.5.3)
30
+ rack
31
+ rake (11.2.2)
32
+ rspec (3.5.0)
33
+ rspec-core (~> 3.5.0)
34
+ rspec-expectations (~> 3.5.0)
35
+ rspec-mocks (~> 3.5.0)
36
+ rspec-core (3.5.2)
37
+ rspec-support (~> 3.5.0)
38
+ rspec-expectations (3.5.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.5.0)
41
+ rspec-mocks (3.5.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.5.0)
44
+ rspec-support (3.5.0)
45
+ rubyzip (1.2.0)
46
+ selenium-webdriver (2.53.4)
47
+ childprocess (~> 0.5)
48
+ rubyzip (~> 1.0)
49
+ websocket (~> 1.0)
50
+ sinatra (1.4.7)
51
+ rack (~> 1.5)
52
+ rack-protection (~> 1.4)
53
+ tilt (>= 1.3, < 3)
54
+ slop (3.6.0)
55
+ thread_safe (0.3.5)
56
+ tilt (2.0.5)
57
+ tzinfo (1.2.2)
58
+ thread_safe (~> 0.1)
59
+ websocket (1.2.3)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ activesupport
66
+ headless
67
+ nokogiri
68
+ pry
69
+ rake
70
+ rspec
71
+ selenium-webdriver
72
+ sinatra
73
+
74
+ BUNDLED WITH
75
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 五所和哉
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # SeleniumStandaloneDsl
2
+
3
+ Gem for using Selenium webdriver simply.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'selenium_standalone_dsl'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install selenium_standalone_dsl
20
+
21
+ ## Usage
22
+
23
+ (Coming soon)
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/acro5piano/selenium_standalone_dsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,126 @@
1
+ module SeleniumStandaloneDsl
2
+ class Base
3
+ attr_reader :driver
4
+
5
+ # @param Hash config
6
+ # config = {
7
+ # log_path: '/path/to/logs',
8
+ # user_agent: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36',
9
+ # }
10
+ def initialize(config)
11
+ # Initialize instance variables
12
+ @config = config
13
+ @logger = Logger.new(@config[:log_path])
14
+
15
+ # Extends timeout
16
+ client = Selenium::WebDriver::Remote::Http::Default.new
17
+ client.timeout = 120
18
+
19
+ # Create profile so that each driver instance has its own cookie
20
+ profile = Selenium::WebDriver::Firefox::Profile.new
21
+ profile['general.useragent.override'] = @config[:user_agent]
22
+ profile.native_events = true
23
+
24
+ if @config[:headless]
25
+ headless = Headless.new(reuse: false, destroy_at_exit: true)
26
+ headless.start
27
+ end
28
+
29
+ @driver = Selenium::WebDriver::Driver.for(:firefox, :http_client => client, :profile => profile)
30
+
31
+ @logger.info '=' * 150
32
+ @logger.info 'SeleniumStandaloneDsl started'
33
+ end
34
+
35
+ # The following methods are utility methods for SeleniumStandaloneDsl-DSL.
36
+ # You can easily handle driver with this DSL.
37
+ def click(selector, find_by: :link_text)
38
+ sleep Random.new.rand(1..2)
39
+ with_frame do
40
+ @driver.find_element(find_by, selector).click
41
+ end
42
+ sleep Random.new.rand(1..2)
43
+ end
44
+
45
+ def popup
46
+ @driver.switch_to.window @driver.window_handles.last
47
+ yield
48
+ @driver.switch_to.window @driver.window_handles.first
49
+ end
50
+
51
+ def fill_in(selector, find_by: :name, with: nil)
52
+ return if !with
53
+
54
+ element = @driver.find_element(find_by, selector)
55
+ 0.upto(100) { element.send_keys "\b" }
56
+ element.send_keys with
57
+ end
58
+
59
+ def prompt_ok
60
+ @driver.switch_to.alert.accept
61
+ end
62
+
63
+ def select(text, from: nil, find_by: :name)
64
+ return if !from
65
+
66
+ # For legacy sites using Frame
67
+ element = with_frame do
68
+ @driver.find_element(find_by, from)
69
+ end
70
+ select = Selenium::WebDriver::Support::Select.new(element)
71
+ select.select_by :text, text
72
+ end
73
+
74
+ def has_element?(method, selector)
75
+ if method == :text
76
+ @driver.page_source.match(selector) != nil
77
+ else
78
+ begin
79
+ @driver.find_element(method, selector).is_a? Selenium::WebDriver::Element
80
+ rescue Selenium::WebDriver::Error::NoSuchElementError
81
+ false
82
+ end
83
+ end
84
+ end
85
+
86
+ # Provide jQuery-like search using Nokogiri::HTML
87
+ # @return Array of [Selenium::WebDriver::Element]
88
+ def search(selector)
89
+ Nokogiri::HTML.parse(@driver.page_source).search selector
90
+ end
91
+
92
+ def iframe(method, selector)
93
+ current_frame = @driver.window_handles.first
94
+ @driver.switch_to.frame @driver.find_element(method, selector)
95
+ yield
96
+ # Frame might has gone away
97
+ @driver.switch_to.frame current_frame rescue Selenium::WebDriver::Error::NoSuchFrameError
98
+ end
99
+
100
+ def with_frame(&block)
101
+ begin
102
+ block.call
103
+ rescue Selenium::WebDriver::Error::NoSuchElementError
104
+ begin
105
+ @driver.switch_to.frame 1
106
+ rescue Selenium::WebDriver::Error::NoSuchFrameError
107
+ raise Selenium::WebDriver::Error::NoSuchElementError
108
+ end
109
+ block.call
110
+ end
111
+ end
112
+
113
+ def visit(url)
114
+ @driver.get url
115
+ end
116
+
117
+ def quit
118
+ @driver.quit
119
+ if @config[:headless]
120
+ headless = Headless.new(reuse: false, destroy_at_exit: true)
121
+ headless.start
122
+ end
123
+ end
124
+ end
125
+ end
126
+
@@ -0,0 +1,3 @@
1
+ module SeleniumStandaloneDsl
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'selenium_standalone_dsl/version'
2
+ require 'selenium_standalone_dsl/base'
3
+ require 'logger'
4
+ require 'selenium-webdriver'
5
+ require 'nokogiri'
6
+ require 'headless'
7
+
8
+
9
+ module SeleniumStandaloneDsl
10
+ ROOT_DIR = File.dirname(ENV['BUNDLE_GEMFILE']) || File.expand_path('../../', __FILE__)
11
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'selenium_standalone_dsl/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "selenium_standalone_dsl"
8
+ spec.version = SeleniumStandaloneDsl::VERSION
9
+ spec.authors = ["gosho-kazuya"]
10
+ spec.email = ["ketsume0211@gmail.com"]
11
+
12
+ spec.summary = %q{Simple gem for using Selenium webdriver simply}
13
+ spec.description = %q{Simple gem for using Selenium webdriver simply}
14
+ spec.homepage = "https://github.com/acro5piano/selenium_standalone_dsl"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing 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_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium_standalone_dsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gosho-kazuya
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Simple gem for using Selenium webdriver simply
56
+ email:
57
+ - ketsume0211@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - lib/selenium_standalone_dsl.rb
73
+ - lib/selenium_standalone_dsl/base.rb
74
+ - lib/selenium_standalone_dsl/version.rb
75
+ - selenium_standalone_dsl.gemspec
76
+ homepage: https://github.com/acro5piano/selenium_standalone_dsl
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Simple gem for using Selenium webdriver simply
100
+ test_files: []