selenium_standalone_dsl 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3693c0d5500983b794af7fdf98364312dad7641
4
- data.tar.gz: f2c0ededad165e7f43ab72be4fe8f0503d7c2c45
3
+ metadata.gz: e5ca3a0d39428672502c8d0731e8732b129489bc
4
+ data.tar.gz: 6d0dbb1640ca9c44e908d576d19c4333c186157c
5
5
  SHA512:
6
- metadata.gz: 0f62c910a6fc5d0ce9c95729b34bb512dfe79952f04493100354a825fd136d2655d197ca349313e6f2e3d66154298ef96523fec4c71ade5961953b37c5bd1738
7
- data.tar.gz: f48cc8dd3eb385b692b0f99b0cce5a617830f379ece17b1c441a6f0e75c984cb7d2813ae748b4573930c7c36d475f5a7acab72049373cd23266a11aacb98a6a5
6
+ metadata.gz: a61ddd3963efa378873a5251bdaf75020ef3c3e5e3dd95963a947df25c6acdab595cdc903f57e1a87ccc84ab7ce6878eac7841cdc674eb2b723f4429b6c46379
7
+ data.tar.gz: 2128b1811e1e2bf2fd1dff2f257bc7618756259a15072ff82e50d4582376d870c09dd847e3e424207e9538bad26afd4b7d4d3960a4fff81f235b786ff2fb561a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- selenium_standalone_dsl (0.1.2)
4
+ selenium_standalone_dsl (0.1.3)
5
5
  headless
6
6
  nokogiri
7
7
  selenium-webdriver
data/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/selenium_standalone_dsl.svg)](https://badge.fury.io/rb/selenium_standalone_dsl)
2
+ [![Build Status](https://travis-ci.org/acro5piano/selenium_standalone_dsl.svg?branch=master)](https://travis-ci.org/acro5piano/selenium_standalone_dsl)
2
3
 
3
4
  # Selenium Standalone DSL
4
5
 
5
6
  Gem for using Selenium webdriver simply.
6
7
 
8
+ Let's scrape sites using JavaScript and iframe!
9
+
10
+ This project aims to expanding Selenium and Nokogiri.
11
+
7
12
  ## Installation
8
13
 
9
14
  Ensure you have already installed Firefox:
@@ -39,7 +44,9 @@ gem install selenium_standalone_dsl
39
44
  ## Usage
40
45
 
41
46
  ```rb
42
- class YahooSearcher < SeleniumStandaloneDsl::Base
47
+ require 'selenium_standalone_dsl'
48
+
49
+ class YahooSearcher < SeleniumStandaloneDSL::Base
43
50
  def search_for_wikipedia
44
51
  visit 'https://www.yahoo.com/'
45
52
  fill_in 'p', with: 'wikipedia'
@@ -70,6 +77,23 @@ driver.search_for_wikipedia
70
77
 
71
78
  ```
72
79
 
80
+
81
+ ## Supported API
82
+
83
+ | Method | Summary | Arguments | Remarks |
84
+ |----------|-----------------------------------|--------------------------|--------------------------------|
85
+ | click | Click a button or link | text of link, name, etc. | |
86
+ | select | Choose an option in select box | option text | |
87
+ | visit | Navigate firefox to a link | link url | |
88
+ | fill\_in | Fill in a input box | element name | |
89
+ | search | Search page source using Nokogiri | | Returns Nokogiri::XML::Element |
90
+
91
+ ### Options
92
+
93
+ | Name | Arguments | Defalut |
94
+ |-----------|-----------------------------------------------|-------------|
95
+ | :find\_by | :link\_text, :name, :id, :class, :css, :xpath | :link\_text |
96
+
73
97
  ## Development
74
98
 
75
99
  ```sh
@@ -79,7 +103,7 @@ bundle install --path vendor/bundle
79
103
  bundle exec rake install
80
104
  bundle exec rake spec
81
105
  ```
82
-
106
+
83
107
  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).
84
108
 
85
109
  ## Roadmap
@@ -94,7 +118,7 @@ In my heart, `Selenium Spider` will have these features:
94
118
 
95
119
  ### Full JavaScript support
96
120
 
97
- Based on Selenium Standalone DSL, it comprehences JavaScript.
121
+ Based on Selenium Standalone DSL which run Firefox headlessly, it comprehences JavaScript completely.
98
122
 
99
123
  ### PMC architecture
100
124
 
@@ -106,19 +130,21 @@ In PMC architecture, Page is for listing items and pagenation.
106
130
 
107
131
  Model is for extracting information from detail page and store data to database.
108
132
 
109
- Controller is for handle the above two.
133
+ Controller is for handling the above two.
110
134
 
111
135
  ### Web-based task execution
112
136
 
113
137
  Scraping tasks are often multiply and difficult to arrange.
114
138
 
115
- Imagine Web-based task execution, definition, and scheduling like Jenkins.
139
+ Imagine Web-based task execution, definition, csv-export and scheduling like Jenkins.
116
140
 
117
141
  ## TODO
118
142
 
119
- - [ ] Fix class name. Dsl => DSL
120
- - [ ] Log and config
121
- - [ ] TravisCI
143
+ - [x] Fix module name. Dsl => DSL
144
+ - [x] Defalut config
145
+ - [x] Add API document
146
+ - [x] TravisCI
147
+ - [ ] Log
122
148
 
123
149
  ## Contributing
124
150
 
@@ -1,7 +1,7 @@
1
1
  require 'bundler/setup'
2
2
  require 'selenium_standalone_dsl'
3
3
 
4
- class YahooSearcher < SeleniumStandaloneDsl::Base
4
+ class YahooSearcher < SeleniumStandaloneDSL::Base
5
5
  def search_for_wikipedia
6
6
  visit 'https://www.yahoo.com/'
7
7
  fill_in 'p', with: 'wikipedia'
@@ -1,16 +1,13 @@
1
- module SeleniumStandaloneDsl
1
+ module SeleniumStandaloneDSL
2
2
  class Base
3
3
  attr_reader :driver
4
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])
5
+ def initialize(log_path: '/tmp/selenium_standalone_dsl',
6
+ user_agent: 'Selenium Standalone DSL', headless: false)
7
+
8
+ if headless
9
+ Headless.new(reuse: false, destroy_at_exit: true).start
10
+ end
14
11
 
15
12
  # Extends timeout
16
13
  client = Selenium::WebDriver::Remote::Http::Default.new
@@ -18,17 +15,13 @@ module SeleniumStandaloneDsl
18
15
 
19
16
  # Create profile so that each driver instance has its own cookie
20
17
  profile = Selenium::WebDriver::Firefox::Profile.new
21
- profile['general.useragent.override'] = @config[:user_agent]
18
+ profile['general.useragent.override'] = user_agent
22
19
  profile.native_events = true
23
20
 
24
- if @config[:headless]
25
- headless = Headless.new(reuse: false, destroy_at_exit: true)
26
- headless.start
27
- end
28
-
29
21
  @driver = Selenium::WebDriver::Driver.for(:firefox, :http_client => client, :profile => profile)
30
22
 
31
- @logger.info '=' * 150
23
+ @logger = Logger.new(log_path)
24
+ @logger.info '=' * 100
32
25
  @logger.info 'SeleniumStandaloneDsl started'
33
26
  end
34
27
 
@@ -116,10 +109,6 @@ module SeleniumStandaloneDsl
116
109
 
117
110
  def quit
118
111
  @driver.quit
119
- if @config[:headless]
120
- headless = Headless.new(reuse: false, destroy_at_exit: true)
121
- headless.start
122
- end
123
112
  end
124
113
  end
125
114
  end
@@ -1,3 +1,3 @@
1
- module SeleniumStandaloneDsl
2
- VERSION = "0.1.2"
1
+ module SeleniumStandaloneDSL
2
+ VERSION = "0.1.3"
3
3
  end
@@ -6,6 +6,6 @@ require 'nokogiri'
6
6
  require 'headless'
7
7
 
8
8
 
9
- module SeleniumStandaloneDsl
9
+ module SeleniumStandaloneDSL
10
10
  ROOT_DIR = File.dirname(ENV['BUNDLE_GEMFILE']) || File.expand_path('../../', __FILE__)
11
11
  end
@@ -5,7 +5,7 @@ require 'selenium_standalone_dsl/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "selenium_standalone_dsl"
8
- spec.version = SeleniumStandaloneDsl::VERSION
8
+ spec.version = SeleniumStandaloneDSL::VERSION
9
9
  spec.authors = ["gosho-kazuya"]
10
10
  spec.email = ["ketsume0211@gmail.com"]
11
11
 
@@ -27,9 +27,9 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency 'selenium-webdriver'
31
- spec.add_dependency 'nokogiri'
32
- spec.add_dependency 'headless'
30
+ spec.add_runtime_dependency 'selenium-webdriver'
31
+ spec.add_runtime_dependency 'nokogiri'
32
+ spec.add_runtime_dependency 'headless'
33
33
 
34
34
  spec.add_development_dependency "bundler", "~> 1.12"
35
35
  spec.add_development_dependency "rake", "~> 10.0"
data/spec/base_spec.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe SeleniumStandaloneDSL::Base do
4
+ before :all do
5
+ @pid = Process.spawn('bundle e ruby spec/fixtures/app.rb')
6
+
7
+ config = {
8
+ log_path: '/tmp/selenium_standalone_dsl.log',
9
+ user_agent: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 ' +
10
+ '(KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36',
11
+ headless: true,
12
+ }
13
+ @driver = SeleniumStandaloneDSL::Base.new(config)
14
+ end
15
+
16
+ after :all do
17
+ @driver.quit
18
+ Process.kill 9, @pid
19
+ end
20
+
21
+ it 'visit a site' do
22
+ expect { @driver.visit('http://localhost:4567') }.not_to raise_error
23
+ end
24
+
25
+ it 'click a link and follow href' do
26
+ @driver.visit 'http://localhost:4567/click'
27
+ expect { @driver.click('ClickMe') }.not_to raise_error
28
+ expect(@driver.driver.current_url).to eq 'http://localhost:4567/'
29
+ end
30
+
31
+ it 'fill_in a input box' do
32
+ @driver.visit 'http://localhost:4567/fill_in'
33
+ expect { @driver.fill_in('input_box', with: 'hoge') }.not_to raise_error
34
+ end
35
+
36
+ it 'close alert' do
37
+ @driver.visit 'http://localhost:4567/alert'
38
+ expect { @driver.prompt_ok }.not_to raise_error
39
+ end
40
+
41
+ it 'select a value in a select box' do
42
+ @driver.visit 'http://localhost:4567/select'
43
+ expect { @driver.select('an option', from: 'select_box') }.not_to raise_error
44
+ expect { @driver.select('an option', from: 'select_box', find_by: :name) }.not_to raise_error
45
+ end
46
+
47
+ it 'determine if the page has the text' do
48
+ @driver.visit 'http://localhost:4567/'
49
+ expect(@driver.has_element?(:text, 'Hello')).to be true
50
+ expect(@driver.has_element?(:text, 'Hogehogehoge')).to be false
51
+ expect(@driver.has_element?(:class, 'title')).to be true
52
+ expect(@driver.has_element?(:class, 'titleIsNotBlank')).to be false
53
+ end
54
+
55
+ it 'search with Nokogiri' do
56
+ @driver.visit 'http://localhost:4567/search'
57
+ expect(@driver.search('th:contains("title") + td').inner_html).to eq 'Hello'
58
+ end
59
+ end
60
+
@@ -1,64 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SeleniumStandaloneDsl do
3
+ describe SeleniumStandaloneDSL do
4
4
  it 'has a version number' do
5
- expect(SeleniumStandaloneDsl::VERSION).not_to be nil
6
- end
7
-
8
- describe SeleniumStandaloneDsl::Base do
9
- before :all do
10
- @pid = Process.spawn('bundle e ruby spec/fixtures/app.rb')
11
-
12
- config = {
13
- log_path: '/tmp/selenium_standalone_dsl_spec.log',
14
- user_agent: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36',
15
- headless: true,
16
- }
17
- @driver = SeleniumStandaloneDsl::Base.new(config)
18
- end
19
-
20
- after :all do
21
- @driver.quit
22
- Process.kill 9, @pid
23
- end
24
-
25
- it 'visit a site' do
26
- expect { @driver.visit('http://localhost:4567') }.not_to raise_error
27
- end
28
-
29
- it 'click a link and follow href' do
30
- @driver.visit 'http://localhost:4567/click'
31
- expect { @driver.click('ClickMe') }.not_to raise_error
32
- expect(@driver.driver.current_url).to eq 'http://localhost:4567/'
33
- end
34
-
35
- it 'fill_in a input box' do
36
- @driver.visit 'http://localhost:4567/fill_in'
37
- expect { @driver.fill_in('input_box', with: 'hoge') }.not_to raise_error
38
- end
39
-
40
- it 'close alert' do
41
- @driver.visit 'http://localhost:4567/alert'
42
- expect { @driver.prompt_ok }.not_to raise_error
43
- end
44
-
45
- it 'select a value in a select box' do
46
- @driver.visit 'http://localhost:4567/select'
47
- expect { @driver.select('an option', from: 'select_box') }.not_to raise_error
48
- expect { @driver.select('an option', from: 'select_box', find_by: :name) }.not_to raise_error
49
- end
50
-
51
- it 'determine if the page has the text' do
52
- @driver.visit 'http://localhost:4567/'
53
- expect(@driver.has_element?(:text, 'Hello')).to be true
54
- expect(@driver.has_element?(:text, 'Hogehogehoge')).to be false
55
- expect(@driver.has_element?(:class, 'title')).to be true
56
- expect(@driver.has_element?(:class, 'titleIsNotBlank')).to be false
57
- end
58
-
59
- it 'search with Nokogiri' do
60
- @driver.visit 'http://localhost:4567/search'
61
- expect(@driver.search('th:contains("title") + td').inner_html).to eq 'Hello'
62
- end
5
+ expect(SeleniumStandaloneDSL::VERSION).not_to be nil
63
6
  end
64
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium_standalone_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - gosho-kazuya
@@ -137,11 +137,12 @@ files:
137
137
  - LICENSE
138
138
  - README.md
139
139
  - Rakefile
140
- - demo.rb
140
+ - examples/yahoo_searcher.rb
141
141
  - lib/selenium_standalone_dsl.rb
142
142
  - lib/selenium_standalone_dsl/base.rb
143
143
  - lib/selenium_standalone_dsl/version.rb
144
144
  - selenium_standalone_dsl.gemspec
145
+ - spec/base_spec.rb
145
146
  - spec/selenium_standalone_dsl_spec.rb
146
147
  homepage: https://github.com/acro5piano/selenium_standalone_dsl
147
148
  licenses:
@@ -168,4 +169,5 @@ signing_key:
168
169
  specification_version: 4
169
170
  summary: Gem for using Selenium webdriver simply
170
171
  test_files:
172
+ - spec/base_spec.rb
171
173
  - spec/selenium_standalone_dsl_spec.rb