symbiote 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/symbiote.rb CHANGED
@@ -1,65 +1,40 @@
1
- require 'symbiote/version'
2
- require 'symbiote/logger'
3
- require 'symbiote/errors'
4
- require 'symbiote/platforms'
5
- require 'symbiote/generators'
1
+ require "symbiote/version"
6
2
 
7
- require 'watir-webdriver'
8
- require 'selenium-webdriver'
3
+ require "symbiote/data_setter"
4
+ require "symbiote/situation"
5
+ require "symbiote/elements"
6
+ require "symbiote/factory"
7
+ require "symbiote/pages"
9
8
 
10
9
  module Symbiote
11
- include Platforms
10
+ module_function
12
11
 
13
- # @return [Object] platform reference
14
- # [Symbiont::Platforms::WatirWebDriver::PlatformObject]
15
- # [Symbiont::Platforms::SeleniumWebDriver::PlatformObject]
16
- attr_reader :platform
17
-
18
- # @return [Object] browser reference
19
- # [Watir::Browser]
20
- # [Selenium::WebDriver::Driver]
21
12
  attr_reader :browser
22
-
23
- def self.version
24
- "Symbiote v#{Symbiote::VERSION}"
13
+
14
+ def included(caller)
15
+ caller.extend Symbiote::Elements
16
+ caller.extend Symbiote::Pages::Assertion
17
+ caller.__send__ :include, Symbiote::Elements::Accessor
18
+ caller.__send__ :include, Symbiote::Pages
19
+ caller.__send__ :include, Symbiote::DataSetter
20
+ end
21
+
22
+ def initialize(browser = nil, &block)
23
+ @browser = Symbiote.browser unless Symbiote.browser.nil?
24
+ @browser = browser if Symbiote.browser.nil?
25
+ instance_eval(&block) if block
25
26
  end
26
27
 
27
- # The included callback is used to provide the core functionality of the
28
- # library to any class or module that includes the Symbiote library. The
29
- # calling class or module is extended with logic that the library makes
30
- # available as class methods. Those methods will be available only in
31
- # the context of the class (definition) that included Symbiote.
32
- def self.included(caller)
33
- Symbiote.trace("#{caller.class} #{caller} attached the Symbiote")
34
- caller.extend Symbiote::Generators
28
+ def set_browser(app = :chrome, *args)
29
+ @browser = Watir::Browser.new(app, *args)
30
+ Symbiote.browser = @browser
35
31
  end
36
32
 
37
- # The initialize method will be invoked when a page definition includes
38
- # Symbiote. A few key things are happening here that are critical to
39
- # everything working properly:
40
- # (1) A browser instance is being created.
41
- # (2) A platform object is created for that browser.
42
- #
43
- # @param [Object] browser a browser instance with a tool driver
44
- def initialize(browser=nil)
33
+ def browser=(browser)
45
34
  @browser = browser
46
- @browser = Watir::Browser.new if browser.nil? or browser == :watir
47
- @browser = Selenium::WebDriver.for :firefox if browser == :selenium
48
-
49
- Symbiote::trace("Symbiote attached to browser: #{@browser}")
50
-
51
- establish_platform_object_for(@browser)
52
35
  end
53
-
54
- private
55
36
 
56
- # This method is crucial in that it sets up the platform instance that
57
- # will be used by just about every module that makes calls to any
58
- # platform-specific functionality.
59
- #
60
- # @param [Object] browser a browser instance with a tool driver
61
- def establish_platform_object_for(browser)
62
- @platform = get_platform_for(browser)
37
+ def browser
38
+ @browser
63
39
  end
64
-
65
40
  end
@@ -0,0 +1,51 @@
1
+ class Object
2
+ def chain(method_chain, arg = nil)
3
+ return self if method_chain.empty?
4
+ method_chain.split('.').inject(self) do |o, m|
5
+ if arg.nil?
6
+ o.send(m.intern)
7
+ else
8
+ o.send(m.intern, arg)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ module Symbiote
15
+ module DataSetter
16
+ def using(data)
17
+ data.each do |key, value|
18
+ use_data_with(key, value) if object_enabled_for(key)
19
+ end
20
+ end
21
+
22
+ alias using_data using
23
+ alias use_data using
24
+ alias using_values using
25
+ alias use_values using
26
+
27
+ private
28
+
29
+ def use_data_with(key, value)
30
+ element = send(key.to_s)
31
+ set_and_select(key, element, value)
32
+ check_and_uncheck(key, element, value)
33
+ end
34
+
35
+ def set_and_select(key, element, value)
36
+ chain("#{key}.set", value) if element.class == Watir::TextField
37
+ chain("#{key}.set") if element.class == Watir::Radio
38
+ chain("#{key}.select", value) if element.class == Watir::Select
39
+ end
40
+
41
+ def check_and_uncheck(key, element, value)
42
+ return chain("#{key}.check") if element.class == Watir::CheckBox && value
43
+ chain("#{key}.uncheck") if element.class == Watir::CheckBox
44
+ end
45
+
46
+ def object_enabled_for(key)
47
+ web_element = send(key.to_s)
48
+ web_element.enabled? && web_element.visible?
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,60 @@
1
+ require "watir"
2
+ require "watir-webdriver"
3
+
4
+ module Symbiote
5
+ include Situation
6
+
7
+ module_function
8
+
9
+ def elements
10
+ @elements = Watir::Container.instance_methods unless @elements
11
+ end
12
+
13
+ def hosts?(method)
14
+ Symbiote.elements.include? method.to_sym
15
+ end
16
+
17
+ module Elements
18
+ module Accessor
19
+ def reference_element(element, locator)
20
+ browser.send(element, *locator).to_subtype
21
+ rescue NoMethodError
22
+ browser.send(element, *locator)
23
+ end
24
+ end
25
+
26
+ def method_missing(method, *args)
27
+ abort("The method '#{method}' is not a recognized element method.")
28
+ super
29
+ end
30
+
31
+ def respond_to_missing?(method)
32
+ super
33
+ end
34
+
35
+ Symbiote.elements.each do |element|
36
+ define_method(element) do |*signature, &block|
37
+ identifier, locator = parse_signature(signature)
38
+ define_element_accessor(identifier, locator, element, &block)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def define_element_accessor(identifier, *locator, element, &block)
45
+ define_method(identifier.to_s.to_sym) do |*values|
46
+ if block_given?
47
+ instance_exec(*values, &block)
48
+ else
49
+ no_locator(self.class, identifier) if empty_locator(locator, values)
50
+ locator = values if locator[0].nil?
51
+ reference_element(element, locator)
52
+ end
53
+ end
54
+ end
55
+
56
+ def parse_signature(signature)
57
+ [signature.shift, signature.shift]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module Symbiote
2
+ module Factory
3
+ # Creates a definition context for actions. If an existing context
4
+ # exists, that context will be re-used.
5
+ def on(definition, visit = false, &block)
6
+ unless @context.is_a?(definition)
7
+ @context = definition.new(@browser) if @browser
8
+ @context = definition.new unless @browser
9
+ @context.visit if visit
10
+ end
11
+
12
+ yield @context if block
13
+ @context
14
+ end
15
+
16
+ # Creates a definition context for actions and establishes the
17
+ # context for execution.
18
+ def on_view(definition, &block)
19
+ on(definition, true, &block)
20
+ end
21
+
22
+ alias on_visit on_view
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ module Symbiote
2
+ include Situation
3
+
4
+ module_function
5
+
6
+ module Pages
7
+ module Assertion
8
+ include Situation
9
+
10
+ def url_is(url)
11
+ url_is_empty if url.nil? || url.empty?
12
+ @url = url
13
+ end
14
+
15
+ def asserted_url
16
+ @url
17
+ end
18
+
19
+ def title_is(title)
20
+ title_is_empty if title.nil? || title.empty?
21
+ @title = title
22
+ end
23
+
24
+ def asserted_title
25
+ @title
26
+ end
27
+ end
28
+
29
+ def visit(url = nil)
30
+ no_url_provided if url.nil? && asserted_url.nil?
31
+ browser.goto(url) unless url.nil?
32
+ browser.goto(asserted_url) if url.nil?
33
+ self
34
+ end
35
+
36
+ alias perform visit
37
+ alias view visit
38
+ alias navigate_to visit
39
+ alias goto visit
40
+
41
+ def asserted_url
42
+ self.class.asserted_url
43
+ end
44
+
45
+ def asserted_title
46
+ self.class.asserted_title
47
+ end
48
+
49
+ def resize(width, height)
50
+ browser.window.resize_to(width, height)
51
+ end
52
+
53
+ def position(x, y)
54
+ browser.window.move_to(x, y)
55
+ end
56
+
57
+ def url
58
+ browser.url
59
+ end
60
+
61
+ def title
62
+ browser.title
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ module Symbiote
2
+ module Situation
3
+ private
4
+
5
+ def url_is_empty
6
+ puts "PROBLEM: url_is assertion empty."
7
+ puts "The url_is assertion is empty on"
8
+ puts "the definition #{retrieve_class(caller)}."
9
+ abort
10
+ end
11
+
12
+ def no_url_provided
13
+ puts "PROBLEM: No url provided."
14
+ puts "You called a '#{retrieve_method(caller)}' action but the "
15
+ puts "definition #{self.class} does not have a url_is assertion."
16
+ puts "Either provide the url_is assertion or pass the url as an"
17
+ puts "argument to the visit call."
18
+ abort
19
+ end
20
+
21
+ def title_is_empty
22
+ puts "PROBLEM: title_is assertion empty."
23
+ puts "The title_is assertion is empty on"
24
+ puts "the definition #{retrieve_class(caller)}."
25
+ abort
26
+ end
27
+
28
+ def no_title_is_provided
29
+ puts "PROBLEM: No title provided."
30
+ puts "You called a '#{retrieve_method(caller)}' action but the"
31
+ puts "definition #{self.class} does not have a title_is assertion."
32
+ end
33
+
34
+ def no_locator(definition, identifier)
35
+ puts "PROBLEM: No locator provided."
36
+ puts "You are using '#{identifier}' on '#{definition}'."
37
+ puts "But there is no locator provided with it."
38
+ abort
39
+ end
40
+
41
+ def empty_locator(locator, values)
42
+ locator[0].nil? && values.empty? && !values[0].is_a?(Hash)
43
+ end
44
+
45
+ def retrieve_class(caller)
46
+ caller[1][/`.*'/][8..-3]
47
+ end
48
+
49
+ def retrieve_method(caller)
50
+ caller[0][/`.*'/][1..-2]
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,14 @@
1
1
  module Symbiote
2
- VERSION = '0.1.0'
2
+ module_function
3
+
4
+ VERSION = "0.2.0".freeze
5
+
6
+ def version
7
+ """
8
+ Symbiote v#{Symbiote::VERSION}
9
+ watir: #{Gem.loaded_specs['watir'].version}
10
+ watir-webdriver: #{Gem.loaded_specs['watir-webdriver'].version}
11
+ selenium-webdriver: #{Gem.loaded_specs['selenium-webdriver'].version}
12
+ """
13
+ end
3
14
  end
data/symbiote.gemspec CHANGED
@@ -4,28 +4,34 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'symbiote/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'symbiote'
7
+ spec.name = "symbiote"
8
8
  spec.version = Symbiote::VERSION
9
- spec.platform = Gem::Platform::RUBY
10
- spec.author = 'Jeff Nyman'
11
- spec.email = 'jeffnyman@gmail.com'
12
- spec.description = 'Provides a DSL to construct a fluent interface for test execution libraries.'
13
- spec.summary = 'An endosymbiotic facultative library for web application testing.'
14
- spec.homepage = 'https://github.com/jnyman/symbiote'
15
- spec.license = 'MIT'
9
+ spec.authors = ["Jeff Nyman"]
10
+ spec.email = ["jeffnyman@gmail.com"]
16
11
 
17
- spec.files = `git ls-files`.split($/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = %w(lib)
21
-
22
- spec.required_ruby_version = '>= 1.9.3'
23
-
24
- spec.add_development_dependency 'bundler', '~> 1.3'
25
- spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'rspec', '~> 2.14.1'
27
- spec.add_development_dependency 'simplecov', '~> 0.7'
12
+ spec.summary = %q{Provides a semantic DSL to construct fluent interfaces for test execution logic.}
13
+ spec.description = %q{Provides a semantic DSL to construct fluent interfaces for test execution logic.}
14
+ spec.homepage = "https://github.com/jnyman/symbiote"
15
+ spec.license = "MIT"
28
16
 
29
- spec.add_runtime_dependency 'watir-webdriver', '0.6.4'
30
- spec.add_runtime_dependency 'selenium-webdriver', '2.35.1'
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rubocop"
28
+ spec.add_development_dependency "pry"
29
+
30
+ spec.add_runtime_dependency "watir"
31
+
32
+ spec.post_install_message = %{
33
+ (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
34
+ Symbiote #{Symbiote::VERSION} has been installed.
35
+ (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
36
+ }
31
37
  end
metadata CHANGED
@@ -1,154 +1,152 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbiote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Nyman
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2013-10-06 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '1.13'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '1.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.1
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.1
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simplecov
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.7'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0.7'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: watir-webdriver
70
+ name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.6.4
76
- type: :runtime
75
+ version: '0'
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.6.4
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: selenium-webdriver
84
+ name: watir
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 2.35.1
89
+ version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 2.35.1
97
- description: Provides a DSL to construct a fluent interface for test execution libraries.
98
- email: jeffnyman@gmail.com
96
+ version: '0'
97
+ description: Provides a semantic DSL to construct fluent interfaces for test execution
98
+ logic.
99
+ email:
100
+ - jeffnyman@gmail.com
99
101
  executables: []
100
102
  extensions: []
101
103
  extra_rdoc_files: []
102
104
  files:
103
- - .gitignore
104
- - .travis.yml
105
+ - ".gitignore"
106
+ - ".hound.yml"
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
105
111
  - Gemfile
106
- - HISTORY.md
107
112
  - LICENSE.txt
108
113
  - README.md
109
114
  - Rakefile
115
+ - bin/console
116
+ - bin/setup
110
117
  - lib/symbiote.rb
111
- - lib/symbiote/errors.rb
112
- - lib/symbiote/generators.rb
113
- - lib/symbiote/logger.rb
114
- - lib/symbiote/platform_selenium.rb
115
- - lib/symbiote/platform_selenium/platform_object.rb
116
- - lib/symbiote/platform_watir.rb
117
- - lib/symbiote/platform_watir/platform_object.rb
118
- - lib/symbiote/platforms.rb
118
+ - lib/symbiote/data_setter.rb
119
+ - lib/symbiote/elements.rb
120
+ - lib/symbiote/factory.rb
121
+ - lib/symbiote/pages.rb
122
+ - lib/symbiote/situation.rb
119
123
  - lib/symbiote/version.rb
120
- - spec/spec_helper.rb
121
- - spec/symbiote/generators_spec.rb
122
- - spec/symbiote/platform_object_spec.rb
123
- - spec/symbiote/symbiote_spec.rb
124
124
  - symbiote.gemspec
125
125
  homepage: https://github.com/jnyman/symbiote
126
126
  licenses:
127
127
  - MIT
128
128
  metadata: {}
129
- post_install_message:
129
+ post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
130
+ \ Symbiote 0.2.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::) (::)
131
+ (::) (::) (::)\n "
130
132
  rdoc_options: []
131
133
  require_paths:
132
134
  - lib
133
135
  required_ruby_version: !ruby/object:Gem::Requirement
134
136
  requirements:
135
- - - '>='
137
+ - - ">="
136
138
  - !ruby/object:Gem::Version
137
- version: 1.9.3
139
+ version: '0'
138
140
  required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  requirements:
140
- - - '>='
142
+ - - ">="
141
143
  - !ruby/object:Gem::Version
142
144
  version: '0'
143
145
  requirements: []
144
146
  rubyforge_project:
145
- rubygems_version: 2.0.2
147
+ rubygems_version: 2.5.1
146
148
  signing_key:
147
149
  specification_version: 4
148
- summary: An endosymbiotic facultative library for web application testing.
149
- test_files:
150
- - spec/spec_helper.rb
151
- - spec/symbiote/generators_spec.rb
152
- - spec/symbiote/platform_object_spec.rb
153
- - spec/symbiote/symbiote_spec.rb
154
- has_rdoc:
150
+ summary: Provides a semantic DSL to construct fluent interfaces for test execution
151
+ logic.
152
+ test_files: []