sapphire 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sapphire.rb CHANGED
@@ -8,11 +8,13 @@ require 'Forwardable'
8
8
  require 'win32ole'
9
9
  require 'json'
10
10
 
11
+ require File.expand_path(File.dirname(__FILE__) +'/sapphire/Strategies/Strategy.rb', __FILE__)
11
12
  Dir[File.dirname(__FILE__) + '/sapphire/Testing/*.rb'].each {|file| require file }
12
13
  Dir[File.dirname(__FILE__) + '/sapphire/Configuration/*.rb'].each {|file| require file }
13
14
  Dir[File.dirname(__FILE__) + '/sapphire/WebAbstractions/Controls/Base/*.rb'].each {|file| require file }
14
15
  Dir[File.dirname(__FILE__) + '/sapphire/WebAbstractions/Controls/*.rb'].each {|file| require file }
15
16
  Dir[File.dirname(__FILE__) + '/sapphire/DataAbstractions/*.rb'].each {|file| require file }
17
+ Dir[File.dirname(__FILE__) + '/sapphire/Strategies/*.rb'].each {|file| require file }
16
18
  Dir[File.dirname(__FILE__) + '/sapphire/DSL/Browser/*.rb'].each {|file| require file }
17
19
  Dir[File.dirname(__FILE__) + '/sapphire/DSL/Configuration/*.rb'].each {|file| require file }
18
20
  Dir[File.dirname(__FILE__) + '/sapphire/DSL/Data/*.rb'].each {|file| require file }
@@ -21,6 +23,7 @@ Dir[File.dirname(__FILE__) + '/sapphire/DSL/TestPlans/*.rb'].each {|file| requir
21
23
 
22
24
  module Sapphire
23
25
  module Sapphire
26
+ include DSL::Strategies
24
27
  include DSL::Scenarios
25
28
  include DSL::Browser
26
29
  include DSL::Configuration
@@ -0,0 +1,30 @@
1
+ module Sapphire
2
+ module Configuration
3
+ class SapphireConfig
4
+
5
+ def initialize
6
+ @@config = {}
7
+
8
+ Add Symbol => SymbolStrategy
9
+ Add Class => ClassStrategy
10
+ Add Hash => HashStrategy
11
+ end
12
+
13
+ def self.Current
14
+ @@instance ||= SapphireConfig.new
15
+ end
16
+
17
+ def Add(hash)
18
+ @@config = @@config.merge(hash)
19
+ end
20
+
21
+ def GetBy(symbol)
22
+ if(@@config.has_key? symbol)
23
+ return @@config[symbol]
24
+ end
25
+
26
+ return DefaultStrategy
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,8 +2,22 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Error(hash)
5
- ExecuteHashAgainstControl(hash) do |control, arg|
6
- return control.Equals(arg)
5
+ NullModifier.new(Error.new(hash, @page, @browser))
6
+ end
7
+
8
+ class Error
9
+ def initialize(item, page, browser)
10
+ @item = item
11
+ @page = page
12
+ @browser = browser
13
+ end
14
+
15
+ def ModifyWith(item)
16
+ @modifier = item
17
+ end
18
+
19
+ def execute
20
+ return { :value => SapphireConfig.Current.GetBy(@item.class).new(@page, @browser).Error(@item), :modifier => @modifier }
7
21
  end
8
22
  end
9
23
  end
@@ -1,12 +1,12 @@
1
1
  module Sapphire
2
2
  module DSL
3
3
  module Browser
4
- def ExecuteHashAgainstControl(hash, &block)
4
+ def ExecuteHashAgainstControl(hash, page, &block)
5
5
  hash.keys.each do |key|
6
- @page.fields.each do |field|
6
+ page.fields.each do |field|
7
7
  field.keys.each do |field_key|
8
8
  if(field_key == key)
9
- block.call(field[key], hash[key])
9
+ block.call(field[field_key], hash[key])
10
10
  return
11
11
  end
12
12
  end
@@ -5,9 +5,11 @@ module Sapphire
5
5
  def Equals(value)
6
6
  x = self.FindAll
7
7
  x.each do |item|
8
- return true if item.text == value
8
+ if item.text == value
9
+ return Evaluation.new(item.text, value)
10
+ end
9
11
  end
10
- return false
12
+ return Evaluation.new("Value not found in list", value)
11
13
  end
12
14
  end
13
15
  end
@@ -2,7 +2,28 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Not(item)
5
- !item
5
+ Not.new(item)
6
+ end
7
+
8
+ class Not
9
+
10
+ def initialize(item)
11
+ @item = item
12
+ @item.ModifyWith self
13
+ end
14
+
15
+ def Modify(item)
16
+ return @modifier.Modify(!item) if @modifier != nil
17
+ !item
18
+ end
19
+
20
+ def Evaluate(evaluation)
21
+ evaluation.left.should_not == evaluation.right
22
+ end
23
+
24
+ def execute
25
+ @item.execute
26
+ end
6
27
  end
7
28
  end
8
29
  end
@@ -2,7 +2,7 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Set(hash)
5
- ExecuteHashAgainstControl(hash) do |control, arg|
5
+ ExecuteHashAgainstControl(hash, @page) do |control, arg|
6
6
  control.Set arg
7
7
  end
8
8
  end
@@ -2,7 +2,30 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Should(item)
5
- item.should == true
5
+ results = item.execute()
6
+
7
+ if results.is_a? Hash
8
+ @page = results[:page] if results[:page] != nil
9
+ value = results[:value]
10
+ modifier = results[:modifier]
11
+
12
+ if value.is_a? Hash
13
+ @page = value[:page] if value[:page] != nil
14
+ sub_value = value[:value]
15
+ modifier.Evaluate(sub_value)
16
+ return
17
+ end
18
+ modifier.Evaluate(value)
19
+
20
+ return
21
+ end
22
+
23
+ if(results.is_a? Evaluation)
24
+ results.left.should == results.right
25
+ return
26
+ end
27
+
28
+ raise "Cannot act upon result " + results.to_s + " for page " + @page.to_s
6
29
  end
7
30
  end
8
31
  end
@@ -2,25 +2,22 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Show(item)
5
- if(item.is_a? Hash)
6
- ExecuteHashAgainstControl(item) do |control, arg|
7
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
8
- text = wait.until { x = control
9
- x unless (!x.Equals(arg) && x.Equals(""))
10
- }
5
+ NullModifier.new(Show.new(item, @page, @browser))
6
+ end
7
+
8
+ class Show
9
+ def initialize(item, page, browser)
10
+ @item = item
11
+ @page = page
12
+ @browser = browser
13
+ end
14
+
15
+ def ModifyWith(item)
16
+ @modifier = item
17
+ end
11
18
 
12
- return text.Equals(arg)
13
- end
14
- elsif(item.is_a? Symbol)
15
- return IsVisible(item) == true
16
- elsif(item.is_a? Class)
17
- temp, @page = @browser.ShouldNavigateTo item
18
- @page.Init
19
- return temp
20
- else
21
- @page = item
22
- @page.Init
23
- return true
19
+ def execute
20
+ return { :value => SapphireConfig.Current.GetBy(@item.class).new(@page, @browser).Show(@item, @modifier), :modifier => @modifier }
24
21
  end
25
22
  end
26
23
  end
@@ -1,8 +1,24 @@
1
1
  module Sapphire
2
2
  module DSL
3
3
  module Browser
4
+
4
5
  def Transition(url)
5
- @browser.ShouldTransitionTo url
6
+ NullModifier.new(Transition.new(url, @browser))
7
+ end
8
+
9
+ class Transition
10
+ def initialize(item, browser)
11
+ @item = item
12
+ @browser = browser
13
+ end
14
+
15
+ def ModifyWith(item)
16
+ @modifier = item
17
+ end
18
+
19
+ def execute
20
+ @modifier.Modify(@browser.ShouldTransitionTo(@item))
21
+ end
6
22
  end
7
23
  end
8
24
  end
@@ -2,7 +2,23 @@ module Sapphire
2
2
  module DSL
3
3
  module Data
4
4
  def Exist(value)
5
- value != nil
5
+ Not(Exist.new(value, @page, @browser))
6
+ end
7
+
8
+ class Exist
9
+ def initialize(item, page, browser)
10
+ @item = item
11
+ @page = page
12
+ @browser = browser
13
+ end
14
+
15
+ def ModifyWith(item)
16
+ @modifier = item
17
+ end
18
+
19
+ def execute
20
+ return { :value => SapphireConfig.Current.GetBy(@item.class).new(@page, @browser).Exists(@item), :modifier => @modifier }
21
+ end
6
22
  end
7
23
  end
8
24
  end
@@ -2,12 +2,22 @@ module Sapphire
2
2
  module DSL
3
3
  module Data
4
4
  def Validate(hash)
5
- hash.keys.each do |key|
6
- if(hash[key].is_a? Symbol)
7
- return GetPageField(hash[key]).Equals(key.to_s)
8
- else
9
- return key.to_s == hash[key].to_s
10
- end
5
+ NullModifier.new(Validate.new(hash, @page, @browser))
6
+ end
7
+
8
+ class Validate
9
+ def initialize(item, page, browser)
10
+ @item = item
11
+ @page = page
12
+ @browser = browser
13
+ end
14
+
15
+ def ModifyWith(item)
16
+ @modifier = item
17
+ end
18
+
19
+ def execute
20
+ return { :value => SapphireConfig.Current.GetBy(@item.class).new(@page, @browser).Validate(@item), :modifier => @modifier }
11
21
  end
12
22
  end
13
23
  end
@@ -3,9 +3,9 @@ module Sapphire
3
3
  module Strategies
4
4
  class ClassStrategy < Strategy
5
5
  def Show(item, modifier)
6
- temp, @page = @browser.ShouldNavigateTo item
6
+ evaluation, @page = @browser.ShouldNavigateTo item
7
7
  @page.Init
8
- {:page => @page, :value => modifier.Modify(temp) }
8
+ {:page => @page, :value => evaluation }
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,11 @@ module Sapphire
5
5
  def Show(item, modifier)
6
6
  @page = item
7
7
  @page.Init
8
- {:page => @page, :value => modifier.Modify(true)}
8
+ {:page => @page, :value => Evaluation.new(true, true)}
9
+ end
10
+
11
+ def Exists(item)
12
+ Evaluation.new(item, nil)
9
13
  end
10
14
  end
11
15
  end
@@ -0,0 +1,16 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Strategies
4
+ class Evaluation
5
+
6
+ attr_reader :left
7
+ attr_reader :right
8
+
9
+ def initialize(left, right)
10
+ @left = left
11
+ @right = right
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,14 +3,23 @@ module Sapphire
3
3
  module Strategies
4
4
  class HashStrategy < Strategy
5
5
  def Show(item, modifier)
6
- ExecuteHashAgainstControl(item) do |control, arg|
6
+ ExecuteHashAgainstControl(item, @page) do |control, arg|
7
7
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
8
8
  text = wait.until { x = control
9
- x if (x.Equals(arg) || (!x.Equals("")))
9
+ x unless (!x.Equals(arg) && x.Equals(""))
10
10
  }
11
11
 
12
- puts arg
13
- modifier.Modify(text.Equals(arg))
12
+ return text.Equals(arg)
13
+ end
14
+ end
15
+
16
+ def Validate(hash)
17
+ Evaluation.new(hash.keys.first.to_s, hash[hash.keys.first].to_s)
18
+ end
19
+
20
+ def Error(item)
21
+ ExecuteHashAgainstControl(item, @page) do |control, arg|
22
+ return control.Equals(arg)
14
23
  end
15
24
  end
16
25
  end
@@ -8,9 +8,14 @@ class NullModifier
8
8
  @modifier = item
9
9
  end
10
10
 
11
- def Modify(arg)
12
- return @modifier.Modify(arg) if @modifier != nil
13
- arg if @modifier == nil
11
+ def Modify(item)
12
+ return @modifier.Modify(item) if @modifier != nil
13
+ item if @modifier == nil
14
+ end
15
+
16
+ def Evaluate(evaluation)
17
+ return @modifier.Evaluate(evaluation) if @modifier != nil
18
+ evaluation.left.should == evaluation.right if @modifier == nil
14
19
  end
15
20
 
16
21
  def execute
@@ -14,13 +14,13 @@ module Sapphire
14
14
  result = wait.until { y = modifier.Modify(x.displayed?)
15
15
  y unless y == false
16
16
  }
17
- return result
17
+ return Evaluation.new(modifier.Modify(x.displayed?), modifier.Modify(true))
18
18
  rescue
19
- return false
19
+ return Evaluation.new(true, "An error occurred.")
20
20
  end
21
21
  end
22
22
  rescue
23
- return false
23
+ return Evaluation.new(true, "An error occurred.")
24
24
  end
25
25
  end
26
26
  end
@@ -28,6 +28,10 @@ module Sapphire
28
28
 
29
29
  raise "cannot find control matching " + args.to_s + " for page " + @page.to_s
30
30
  end
31
+
32
+ def Validate(hash)
33
+ GetPageField(hash[hash.keys.first]).Equals(hash.keys.first.to_s)
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -50,7 +50,7 @@ module Sapphire
50
50
  def FindAllBy(symbol)
51
51
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
52
52
  element = wait.until { x = @browser.find_elements symbol, @hash.fetch(symbol)
53
- x
53
+ x unless x.count == 0
54
54
  }
55
55
  end
56
56
 
@@ -86,7 +86,7 @@ module Sapphire
86
86
  end
87
87
 
88
88
  def Equals(value)
89
- self.Text == value
89
+ Evaluation.new(self.Text, value)
90
90
  end
91
91
  end
92
92
  end
@@ -56,11 +56,12 @@ module Sapphire
56
56
  nav.AlternateUrls.each do |url|
57
57
  temp = self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase)
58
58
  if(temp)
59
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase), true)
59
60
  return temp, nav
60
61
  end
61
62
  end
62
63
  end
63
-
64
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + nav.Url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + nav.Url.upcase), true)
64
65
  return temp, nav
65
66
  end
66
67
 
@@ -75,11 +76,11 @@ module Sapphire
75
76
 
76
77
  def ShouldTransitionTo(url)
77
78
  if(url.instance_of?(String))
78
- temp = self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase)
79
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase), true)
79
80
  @rootUrl = url
80
81
  else
81
82
  x = url.new().Url
82
- temp = self.CurrentUrl.upcase.start_with?("HTTP://" + x.upcase) || temp = self.CurrentUrl.upcase.start_with?("HTTPS://" + x.upcase)
83
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + x.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + x.upcase), true)
83
84
  @rootUrl = x
84
85
  end
85
86
 
@@ -11,7 +11,7 @@ module Sapphire
11
11
  attr_reader :browser
12
12
 
13
13
  def initialize
14
- #@browser = Selenium::WebDriver.for :ie
14
+ @browser = Selenium::WebDriver.for :ie
15
15
  super(@browser)
16
16
  $browser = @browser
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapphire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-30 00:00:00.000000000Z
12
+ date: 2011-08-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: albacore
16
- requirement: &9415884 !ruby/object:Gem::Requirement
16
+ requirement: &9358284 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9415884
24
+ version_requirements: *9358284
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: selenium-webdriver
27
- requirement: &9415584 !ruby/object:Gem::Requirement
27
+ requirement: &9358020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9415584
35
+ version_requirements: *9358020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &9415296 !ruby/object:Gem::Requirement
38
+ requirement: &9357672 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9415296
46
+ version_requirements: *9357672
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email:
@@ -54,6 +54,7 @@ extra_rdoc_files: []
54
54
  files:
55
55
  - lib/sapphire/Configuration/AttrMethods.rb
56
56
  - lib/sapphire/Configuration/Config.rb
57
+ - lib/sapphire/Configuration/SapphireConfig.rb
57
58
  - lib/sapphire/DataAbstractions/Database.rb
58
59
  - lib/sapphire/DataAbstractions/NonQuery.rb
59
60
  - lib/sapphire/DataAbstractions/Query.rb
@@ -116,6 +117,7 @@ files:
116
117
  - lib/sapphire/DSL/TestPlans/TestPlan.rb
117
118
  - lib/sapphire/Strategies/ClassStrategy.rb
118
119
  - lib/sapphire/Strategies/DefaultStrategy.rb
120
+ - lib/sapphire/Strategies/Evaluation.rb
119
121
  - lib/sapphire/Strategies/HashStrategy.rb
120
122
  - lib/sapphire/Strategies/NullModifier.rb
121
123
  - lib/sapphire/Strategies/Strategy.rb