crabfarm 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9c3775845087acaaa1cc6a8ba773a034d52e8ed
4
- data.tar.gz: 78156359fc8d036ad54a591be1923ac96eb5aa72
3
+ metadata.gz: 01f53897c32d27e6253c74660a0842b9cb7c3c97
4
+ data.tar.gz: 7993ac4152d6128ce8b69950458e48dfe042089a
5
5
  SHA512:
6
- metadata.gz: f4aa1971119f25c19a1bae8f606464cc20e0025a02b02ea960749b22ed3602acb6d69b4a58dfa4af18851ecfacba528646b2fc0c6bb4cd8b0c8a8239bd6f9f07
7
- data.tar.gz: d7ecd4359f474d94b109a62b48f35e2af394d3aa0aad62e27d8ef6ac3f00f99037897c56f68fc285470dfa72c14246f3d6e1219d9be71efd05a470bb54950c4f
6
+ metadata.gz: af73913311cb5404d95724470ce07bb37e3ed686abb02a39e20b6a85b0ad028a31ef4524c8ffd09381ce20157e107da7cbe20ddea22c08f3908997d81c1e37b1
7
+ data.tar.gz: 3345f29499e15089b3fd6feccf984f9121187500e9859a2016ccfaf14947d363ca335b0212025722b9eac273996171a6f133e2c37f9d0fa5f2bd649952333742
data/lib/crabfarm.rb CHANGED
@@ -7,6 +7,7 @@ require "crabfarm/version"
7
7
  require "crabfarm/errors"
8
8
  require "crabfarm/configuration"
9
9
  require "crabfarm/loader_service"
10
+ require "crabfarm/parser_service"
10
11
  require "crabfarm/driver_bucket"
11
12
  require "crabfarm/driver_bucket_pool"
12
13
  require "crabfarm/default_driver_factory"
@@ -45,6 +46,9 @@ module Crabfarm
45
46
  register :browser_dsl, :watir, 'Crabfarm::WatirBrowserDsl', 'crabfarm/adapters/browser/watir'
46
47
  register :browser_dsl, :capybara, 'Crabfarm::CapybaraBrowserDsl', 'crabfarm/adapters/browser/capybara'
47
48
 
49
+ # bundled parsers dsl adapters
50
+ register :parser_dsl, :nokogiri, 'Crabfarm::NokogiriDsl', 'crabfarm/adapters/parser/nokogiri'
51
+
48
52
  # bundled state output builders
49
53
  register :output_builder, :hash, 'Crabfarm::HashOutputBuilder', 'crabfarm/adapters/output/hash'
50
54
  register :output_builder, :ostruct, 'Crabfarm::OStructOutputBuilder', 'crabfarm/adapters/output/ostruct'
@@ -1,5 +1,24 @@
1
1
  require 'watir-webdriver'
2
2
 
3
+ class Watir::Browser
4
+ def parse(_parser_class, _options={})
5
+ Crabfarm::ParserService.parse _parser_class, html, _options
6
+ end
7
+ end
8
+
9
+ class Watir::Element
10
+ def parse(_parser_class, _options={})
11
+ Crabfarm::ParserService.parse _parser_class, html, _options
12
+ end
13
+ end
14
+
15
+ class Watir::ElementCollection
16
+ def parse(_parser_class, _options={})
17
+ full_html = self.map(&:html).join
18
+ Crabfarm::ParserService.parse _parser_class, full_html, _options
19
+ end
20
+ end
21
+
3
22
  module Crabfarm
4
23
  class WatirBrowserDsl
5
24
  def self.wrap(_bucket)
@@ -0,0 +1,9 @@
1
+ require 'nokogiri'
2
+
3
+ module Crabfarm
4
+ class NokogiriDsl
5
+ def self.parse(_html)
6
+ Nokogiri::HTML _html
7
+ end
8
+ end
9
+ end
@@ -1,18 +1,18 @@
1
1
  module Crabfarm
2
2
  class BaseParser < Delegator
3
3
 
4
- attr_reader :browser, :params
4
+ attr_reader :params, :root
5
5
 
6
- def self.browser_dsl(_dsl)
7
- @browser_dsl = _dsl
6
+ def self.parser_dsl(_dsl)
7
+ @parser_dsl = _dsl
8
8
  end
9
9
 
10
- def initialize(_driver, _params)
11
- dsl_class = Strategies.load(:browser_dsl, class_browser_dsl || Crabfarm.config.browser_dsl)
12
- @browser = dsl_class.wrap _driver
10
+ def initialize(_html, _params)
11
+ dsl_class = Strategies.load(:parser_dsl, class_parser_dsl || Crabfarm.config.parser_dsl)
12
+ @root = dsl_class.parse _html
13
13
  @params = _params
14
14
 
15
- super @browser
15
+ super @root
16
16
  end
17
17
 
18
18
  def parse
@@ -20,17 +20,17 @@ module Crabfarm
20
20
  end
21
21
 
22
22
  def __getobj__
23
- @browser
23
+ @root
24
24
  end
25
25
 
26
26
  def __setobj__(obj)
27
- @browser = obj
27
+ @root = obj
28
28
  end
29
29
 
30
30
  private
31
31
 
32
- def class_browser_dsl
33
- self.class.instance_variable_get :@browser_dsl
32
+ def class_parser_dsl
33
+ self.class.instance_variable_get :@parser_dsl
34
34
  end
35
35
  end
36
36
  end
@@ -5,7 +5,8 @@ module Crabfarm
5
5
  class Option < Struct.new(:name, :type, :text); end
6
6
 
7
7
  OPTIONS = [
8
- [:browser_dsl, :string, 'Default browser dsl used by parsers and states'],
8
+ [:browser_dsl, :string, 'Default browser dsl used by states'],
9
+ [:parser_dsl, :string, 'Default parser dsl used by parsers'],
9
10
  [:output_builder, :string, 'Default json output builder used by states'],
10
11
  [:driver_factory, :mixed, 'Driver factory, disabled if phantom_mode is used'],
11
12
  [:log_path, :string, 'Path where logs should be stored'],
@@ -50,6 +51,7 @@ module Crabfarm
50
51
  def reset
51
52
  @values = {
52
53
  browser_dsl: :surfer,
54
+ parser_dsl: :nokogiri,
53
55
  output_builder: :hash,
54
56
  driver_factory: nil,
55
57
  log_path: nil,
@@ -14,13 +14,6 @@ module Crabfarm
14
14
  @factory = _factory
15
15
  end
16
16
 
17
- def parse(_parser_class, _options={})
18
- _parser_class = LoaderService.load_parser(_parser_class) if _parser_class.is_a? String or _parser_class.is_a? Symbol
19
- parser = _parser_class.new self, _options
20
- parser.parse
21
- return parser
22
- end
23
-
24
17
  def original
25
18
  @driver ||= @factory.build_driver(@session_id)
26
19
  end
@@ -49,7 +49,6 @@ module Crabfarm
49
49
  wrap_errors { (element!['class'] || '').split(' ') }
50
50
  end
51
51
 
52
- # searches for elements that match a given selector
53
52
  def search(_selector=nil, _options={})
54
53
  _options[:css] = _selector if _selector
55
54
 
@@ -85,7 +84,6 @@ module Crabfarm
85
84
  end
86
85
  end
87
86
 
88
- # clears and sends_keys to this context main element
89
87
  def fill(_value)
90
88
  wrap_errors do
91
89
  element!.clear
@@ -93,6 +91,14 @@ module Crabfarm
93
91
  end
94
92
  end
95
93
 
94
+ def parse(_parser_class, _params={})
95
+ ParserService.parse _parser_class, to_html, _params
96
+ end
97
+
98
+ def to_html
99
+ elements.map { |e| e['outerHTML'] }.join
100
+ end
101
+
96
102
  # Any methods missing are forwarded to the main element (first).
97
103
  def method_missing(_method, *_args, &_block)
98
104
  wrap_errors do
@@ -3,7 +3,7 @@ module Crabfarm
3
3
  module Surfer
4
4
  class SurfContext < SearchContext
5
5
 
6
- def_delegators :@bucket, :parse, :setup
6
+ def_delegators :@bucket, :setup
7
7
  def_delegators 'driver.navigate', :back, :forward, :refresh
8
8
 
9
9
  def initialize(_bucket)
@@ -19,6 +19,10 @@ module Crabfarm
19
19
  [driver]
20
20
  end
21
21
 
22
+ def to_html
23
+ driver.page_source
24
+ end
25
+
22
26
  def driver
23
27
  @bucket.original
24
28
  end
@@ -0,0 +1,12 @@
1
+ module Crabfarm
2
+ class ParserService
3
+
4
+ def self.parse(_parser_class, _html, _options={})
5
+ _parser_class = LoaderService.load_parser(_parser_class) if _parser_class.is_a? String or _parser_class.is_a? Symbol
6
+ parser = _parser_class.new _html, _options
7
+ parser.parse
8
+ parser
9
+ end
10
+
11
+ end
12
+ end
@@ -1,4 +1,5 @@
1
1
  require 'crabfarm/crabtrap_context'
2
+ require 'net/http'
2
3
 
3
4
  CF_TEST_CONTEXT = Crabfarm::CrabtrapContext::new
4
5
  CF_TEST_CONTEXT.load
@@ -9,13 +10,13 @@ module Crabfarm
9
10
 
10
11
  def parse(_snap_or_url, _options={})
11
12
  fixture = Pathname.new(File.join(ENV['SNAPSHOT_DIR'], _snap_or_url))
12
- if fixture.exist?
13
- CF_TEST_BUCKET.get("file://#{fixture.realpath}")
13
+ html = if fixture.exist?
14
+ File.read fixture.realpath
14
15
  else
15
- CF_TEST_BUCKET.get(_snap_or_url)
16
+ Net::HTTP.get(URI.parse _snap_or_url)
16
17
  end
17
18
 
18
- CF_TEST_BUCKET.parse(described_class, _options)
19
+ ParserService.parse described_class, html, _options
19
20
  end
20
21
 
21
22
  def crawl(_state=nil, _params={})
@@ -1,3 +1,3 @@
1
1
  module Crabfarm
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crabfarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.6
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activesupport
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -324,6 +338,7 @@ files:
324
338
  - lib/crabfarm/adapters/output/hash.rb
325
339
  - lib/crabfarm/adapters/output/jbuilder.rb
326
340
  - lib/crabfarm/adapters/output/ostruct.rb
341
+ - lib/crabfarm/adapters/parser/nokogiri.rb
327
342
  - lib/crabfarm/base_parser.rb
328
343
  - lib/crabfarm/base_state.rb
329
344
  - lib/crabfarm/cli.rb
@@ -347,6 +362,7 @@ files:
347
362
  - lib/crabfarm/modes/publisher.rb
348
363
  - lib/crabfarm/modes/recorder.rb
349
364
  - lib/crabfarm/modes/server.rb
365
+ - lib/crabfarm/parser_service.rb
350
366
  - lib/crabfarm/phantom_driver_factory.rb
351
367
  - lib/crabfarm/phantom_runner.rb
352
368
  - lib/crabfarm/rspec.rb