browsery 0.4.1 → 0.5.0

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: 3ac1c58c9cfcb420e0bbc5d9a92bc7d88e261797
4
- data.tar.gz: 5c445aa7260ad4ae6f72b617e925c06288e2662f
3
+ metadata.gz: c490410ea3724362cb077735140c55c5e2c8ca7d
4
+ data.tar.gz: 86a6871d43bdf0ce986bb4f487debb9aac4a3b3c
5
5
  SHA512:
6
- metadata.gz: b747e0927e0824b085bfb455c38d7c48bc8fd7bedcb7ae73ed636d5503d9281df6e29133f44ad004daafceb38215e12fa304ec43b5b6319c7b6123dc53198e7e
7
- data.tar.gz: 7c18c7cd76b7dfdcb029d684bc2726fbd139fca7333dd9b6698528ac8b9dc963b8dd473aeb47609c8da8a8f1c3974e0865b22e7f359a2ec46404fe0642feb8d3
6
+ metadata.gz: 8203050abd7d2b1f6c3359fc6fe25bfb70337d73b00bad91b9fda6e3057fb2d886bc5a5d432ebbbdf5fab4ba2e5deb6d02615e8afb607f291d063bc4eafce317
7
+ data.tar.gz: 446f91dbe5b5d064836343afcbf650d3514c581914a5624084be21c4f7cf5c92c99c0f4bb408a6a8c67d329fda44187709b116deded67227b3d014dcfe0e564d
@@ -19,5 +19,6 @@ end
19
19
  # Major classes and modules
20
20
  require_relative 'page_objects/element_container'
21
21
  require_relative 'page_objects/base'
22
+ require_relative 'page_objects/section'
22
23
  require_relative 'page_objects/overlay/base'
23
24
  require_relative 'page_objects/widgets/base'
@@ -19,6 +19,27 @@ module Browsery
19
19
  end
20
20
  alias_method :collection, :elements
21
21
 
22
+ def section(section_name, *args)
23
+ section_class, find_args = extract_section_options args
24
+ build section_name, *find_args do |how, what|
25
+ define_method section_name do
26
+ section_class.new self, find_first(how, what)
27
+ end
28
+ end
29
+ end
30
+
31
+ def sections(section_collection_name, *args)
32
+ section_class, find_args = extract_section_options args
33
+ build section_collection_name, *find_args do
34
+ define_method section_collection_name do
35
+ self.class.raise_if_block(self, section_collection_name.to_s, !element_block.nil?)
36
+ find_all(how, what).map do |element|
37
+ section_class.new self, element
38
+ end
39
+ end
40
+ end
41
+ end
42
+
22
43
  def add_to_mapped_items(item)
23
44
  @mapped_items ||= []
24
45
  @mapped_items << item.to_s
@@ -45,6 +66,18 @@ module Browsery
45
66
  end
46
67
  end
47
68
 
69
+ def extract_section_options(args, &block)
70
+ case
71
+ when args.first.is_a?(Class)
72
+ section_class = args.shift
73
+ when block_given?
74
+ section_class = Class.new Browsery::PageObjects::Section, &block
75
+ else
76
+ raise ArgumentError, 'You should provide section class either as a block, or as the second argument'
77
+ end
78
+ return section_class, args
79
+ end
80
+
48
81
  end
49
82
  end
50
- end
83
+ end
@@ -0,0 +1,32 @@
1
+ module Browsery
2
+ module PageObjects
3
+ class Section
4
+ extend ElementContainer
5
+
6
+ attr_reader :root_element, :parent
7
+
8
+ def initialize(parent, root_element)
9
+ @parent = parent
10
+ @root_element = root_element
11
+ # Browsery.within(@root_element) { yield(self) } if block_given?
12
+ end
13
+
14
+ def parent_page
15
+ candidate_page = parent
16
+ until candidate_page.is_a?(Browsery::PageObjects::Base)
17
+ candidate_page = candidate_page.parent
18
+ end
19
+ candidate_page
20
+ end
21
+
22
+ def find_first(how, what)
23
+ root_element.find_element(how, what)
24
+ end
25
+
26
+ def find_all(how, what)
27
+ root_element.all(how, what)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Browsery
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peijie Hu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2016-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -174,6 +174,7 @@ files:
174
174
  - lib/browsery/page_objects/base.rb
175
175
  - lib/browsery/page_objects/element_container.rb
176
176
  - lib/browsery/page_objects/overlay/base.rb
177
+ - lib/browsery/page_objects/section.rb
177
178
  - lib/browsery/page_objects/widgets/base.rb
178
179
  - lib/browsery/parallel.rb
179
180
  - lib/browsery/runner.rb