watir-customize_elements 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c983aeb021cf78608707cf4dda2908a783646d8
4
+ data.tar.gz: 28f31d487bd25e37c10fc2cf41ae3ddb6449f308
5
+ SHA512:
6
+ metadata.gz: 345f1f7bd82a8728ebd08131020ca831e735f86e2dc98ac45923fab25c248a3029d9491120c0e2a98ab3a7e9202cfd11bf5e005e5a6c87d5f0b798e8046b7477
7
+ data.tar.gz: 8aaabd4cd1793763c84bcd1075d5461b296c5c54f732b3f893ce4dc2bea7c1f47c5e277b22d5d7325f41ef0d28864739f50db7efde1d6a9c0006b2016bafaf4d
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2016 MyHeritage, Ltd.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # watir-customize_elements
2
+ The purpose of this gem is to enable Watir-Webdriver and page-object gem to work with custom, non-standard HTML element tag names.
3
+
4
+ While Watir-Webdriver and the page-object gem do not support non-standard HTML tags, we encountered many cases in our testing when we needed to use such elements.
5
+ Although it's possible to register custom elements with PageObject via [widgets](https://github.com/cheezy/page-object/wiki/Widgets-%28registering-custom-elements-with-PageObject%29), and to add support for it in Watir, the process of doing so for each custom element got tedious.
6
+ That's why we created this gem. It automatically instantiates custom HTML tag names into watir-webdriver and/or page-object gem from a few lines in a simple yml file.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'watir-customize_elements'
13
+ ```
14
+
15
+ And then execute:
16
+ ```shell
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+
22
+ ```shell
23
+ $ gem install watir-customize_elements
24
+ ```
25
+
26
+ ## Usage
27
+ - Create a yml file (call it whatever you like), and include the name and path as an env argument named `CUSTOM_ELEMENTS_CONFIG_PATH`. See explanation at the end of this section
28
+ - Require watir-customize_elements **after** requiring watir-webdriver and/or page-object.
29
+ - If you don't want to pass `ENV[CUSTOM_ELEMENTS_CONFIG_PATH]` from the command line, set it **before** requiring watir-customize_elements
30
+ ```ruby
31
+ require 'watir-webdriver'
32
+ require 'page-object'
33
+ ENV['CUSTOM_ELEMENTS_CONFIG_PATH'] = 'path\to\custom_elements_file.yml'
34
+ require 'watir-customize_elements'
35
+ ```
36
+ ## yml file
37
+ The yml file should include two parts: modules and elements
38
+
39
+ ```
40
+ modules:
41
+ watir: true
42
+ page_object: true
43
+ elements:
44
+ element_name:
45
+ element_collection: element_names
46
+ element_class: ElementName
47
+ element_type: CheckBox
48
+ mh_button:
49
+ element_collection: mh_buttons
50
+ element_class: MHButton
51
+ element_type: Button
52
+ ```
53
+ ##### Modules
54
+ Determines which gem to interact with. Configure according to your setup.
55
+ ##### Elements section explained:
56
+ - element_name - This is the exact name of the tag type, with underscores instead of dashes
57
+ - element_collection - This is the name of the element name, but pluralized. element-name would be element_name
58
+ - element_class - This is the element name in class form. mh-checkbox would be MHCheckBox.
59
+ - element_type- This is the PageObject element type (found here: http://bit.ly/1TNEtal). This will give your custom
60
+ element the same type of attribute as its native HTML element type (ex: mh-checkbox with a type of CheckBox is
61
+ treated by PageObject as a true HTML checkbox). If there isn't a matching type, choose Element.
62
+
63
+ You can find an example of a complete yml file [here](http://github.com/myheritage/watir-customize_elements/blob/master/example_custom_elements.yml)
@@ -0,0 +1,16 @@
1
+ modules:
2
+ watir: true
3
+ page_object: true
4
+ elements:
5
+ mh_checkbox:
6
+ element_collection: mh_checkboxes
7
+ element_class: MHCheckBox
8
+ element_type: CheckBox
9
+ mh_button:
10
+ element_collection: mh_buttons
11
+ element_class: MHButton
12
+ element_type: Button
13
+ source_with_matches:
14
+ element_collection: sources_with_matches
15
+ element_class: SourceWithMatches
16
+ element_type: Element
@@ -0,0 +1,92 @@
1
+ require 'watir-webdriver'
2
+ require 'page-object'
3
+ require 'yaml'
4
+
5
+ =begin
6
+ Copyright 2016 MyHeritage, Ltd.
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and limitations under the License.
18
+ =end
19
+
20
+ module WatirCustomizeElements
21
+
22
+ config_file = ENV['CUSTOM_ELEMENTS_CONFIG_PATH']
23
+ @config = YAML::load_file(config_file) unless config_file.nil?
24
+
25
+ def self.custom_elements
26
+ custom_elements = @config['elements'] unless @config.nil?
27
+ end
28
+
29
+ def self.modules
30
+ modules = @config['modules'] unless @config.nil?
31
+ end
32
+
33
+ end
34
+
35
+
36
+ unless WatirCustomizeElements.custom_elements.nil?
37
+ if WatirCustomizeElements.modules['watir']
38
+ # Extending Watir module
39
+ module Watir
40
+ # Extending Container module
41
+ module Container
42
+ # Do the following for each custom element to add
43
+ WatirCustomizeElements.custom_elements.each do |key, values|
44
+ # Defines the element in Watir as a method
45
+ define_method(key.to_sym) { |*args| eval(values['element_class']).new(self, extract_selector(args).merge(:tag_name => key.gsub('_', '-'))) }
46
+
47
+ # Defines a collection of elements in Watir as a method
48
+ define_method(values['element_collection']) { |*args| eval("#{values['element_class']}Collection").new(self, extract_selector(args).merge(:tag_name => key.gsub('_', '-'))) }
49
+
50
+ # Instantiate the classes for a single element and the collection of elements
51
+ Container.const_set(values['element_class'], Class.new(Element))
52
+ Container.const_set("#{values['element_class']}Collection", Class.new(ElementCollection) do
53
+ define_method('element_class') { eval(values['element_class']) }
54
+ end)
55
+ end
56
+ end
57
+ end
58
+
59
+ module Watir
60
+ # Expanding the case statement in the normalize_selector method to include custom attributes,
61
+ # since the custom element does not recognize all attributes by default.
62
+ class ElementLocator
63
+ alias :old_normalize_selector :normalize_selector
64
+
65
+ def normalize_selector(how, what)
66
+ case how
67
+ # supporting "name" attribute
68
+ when :name
69
+ [how, what]
70
+ else
71
+ old_normalize_selector(how, what)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ if WatirCustomizeElements.modules['page_object']
80
+ # Adding each custom element to PageObject gem
81
+ WatirCustomizeElements.custom_elements.each do |key, values|
82
+ # Interacting with the element
83
+ Object.const_set(values['element_class'], Class.new(eval("PageObject::Elements::#{values['element_type']}")))
84
+
85
+ # Registering the class with the PageObject gem.
86
+ # register_widget accepts a tag which is used as the accessor (ex: mh_button), the class which is added to
87
+ # the Elements module (ex: MHButton), and a html element tag which is used as the html element (ex: mh_button).
88
+ PageObject.register_widget key.to_sym, eval(values['element_class']), key.to_sym
89
+ end
90
+ end
91
+
92
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir-customize_elements
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yehuda Miller, Shani Raby, Matan Goren, Ronnie Harpaz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: watir-webdriver
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.11
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.11
27
+ - !ruby/object:Gem::Dependency
28
+ name: page-object
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Automatically instantiates custom HTML tag names into watir-webdriver
42
+ and\or page-object gem.
43
+ email:
44
+ - matan.goren@myheritage.com
45
+ - yehuda.miller@myheritage.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE.txt
51
+ - README.md
52
+ - example_custom_elements.yml
53
+ - lib/watir-customize_elements.rb
54
+ homepage: https://github.com/myheritage/watir-customize_elements
55
+ licenses:
56
+ - Apache-2.0
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.4.5.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Gem for adding custom elements to Watir-webdriver and page-object gem
78
+ test_files: []