sapphire 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -93,16 +93,37 @@ module Sapphire
93
93
  self.browser.get self.CurrentUrl
94
94
  end
95
95
 
96
- def ShouldNavigateTo(page, comparator)
97
- if(page.is_a? Class)
98
- $page = page.new
99
- else
100
- $page = page
96
+ def GetValue(item, key)
97
+
98
+ if item.is_a? Array
99
+ item.each do |sub_item|
100
+ value = GetValue(sub_item, key)
101
+ return value if !value.nil?
102
+ end
103
+ end
104
+
105
+ if item.is_a? Class and key.nil?
106
+ return item.new
101
107
  end
102
108
 
109
+ if item.is_a? Hash
110
+ return item[key] if item.has_key? key
111
+ end
112
+
113
+ nil
114
+ end
115
+
116
+ def ShouldNavigateTo(page, comparator)
117
+
118
+ $page = GetValue(page, nil)
119
+ $page ||= page
120
+
121
+ timeout = GetValue(page, :wait)
122
+ timeout ||= 20
123
+
103
124
  $page.Init
104
125
 
105
- wait = Selenium::WebDriver::Wait.new(:timeout => 20)
126
+ wait = Selenium::WebDriver::Wait.new(:timeout => timeout)
106
127
  begin
107
128
  item = wait.until {
108
129
  x = self.CurrentUrl.upcase.start_with?($page.Url.upcase)
@@ -26,7 +26,7 @@ module Sapphire
26
26
  end
27
27
 
28
28
  def Differ(comparator)
29
- return Fix(DifferComparison.new(Evaluation.new(@compare1 + @value, @compare2)), comparator)
29
+ return Fix(DifferComparison.new(Evaluation.new((@compare2 - @compare1).to_i, @value)), comparator)
30
30
  end
31
31
 
32
32
  def Fix(evaluation, comparator)
@@ -12,7 +12,6 @@ module Sapphire
12
12
  return nil
13
13
  }
14
14
  rescue
15
- puts "Cant find item!"
16
15
  return nil
17
16
  end
18
17
  end
@@ -26,6 +26,14 @@ module Sapphire
26
26
  @item.Evaluate
27
27
  end
28
28
 
29
+ def left
30
+ @item.left
31
+ end
32
+
33
+ def right
34
+ @item.right
35
+ end
36
+
29
37
  def execute
30
38
  @item.execute
31
39
  end
@@ -1,8 +1,8 @@
1
1
  module Sapphire
2
2
  module DSL
3
3
  module Browser
4
- def Show(item)
5
- Evaluator.new(item) do |item, comparator| item.Show(item, comparator) end
4
+ def Show(*item)
5
+ Evaluator.new(item) do |item, comparator| item.first.Show(item, comparator) end
6
6
  end
7
7
  end
8
8
  end
@@ -9,32 +9,15 @@ class Hash < Object
9
9
  end
10
10
 
11
11
  def Examine(item, comparator, &block)
12
- key = item.keys.first
13
- field = $page.Get(key)
14
- value = item[key]
12
+ key = item.first.keys.first if item.first.is_a? Hash
13
+ key = item.first.first if item.first.is_a? Array
15
14
 
16
15
  return FieldNotDefinedEvaluation.new(key, $page) if !$page.Contains key
17
16
 
18
- begin
19
- return FieldNotFoundEvaluation.new(key, $page, "selenium could not find the field") if field == nil
20
-
21
- begin
22
- wait = Selenium::WebDriver::Wait.new(:timeout => 5)
23
- result = wait.until {
24
- evaluation = block.call(field, value)
25
- y = evaluation.Evaluate()
26
- comparator = EqualsComparison.new(evaluation) if evaluation == nil
27
- evaluation if comparator.Compare(y == true, true)
28
- }
29
-
30
- return Fix(result, comparator)
31
- rescue => e
32
- return FieldNotFoundEvaluation.new(key, $page, e.to_s)
33
- end
17
+ field = $page.Get(key)
18
+ return FieldNotFoundEvaluation.new(key, $page, "selenium could not find the field") if field == nil
34
19
 
35
- rescue => e
36
- return FieldNotFoundEvaluation.new(key, $page, e.to_s)
37
- end
20
+ return Fix(field.Evaluate(key, item, comparator, block), comparator)
38
21
  end
39
22
 
40
23
  def Show(item, comparator)
@@ -43,49 +43,35 @@ class Symbol
43
43
  end
44
44
 
45
45
  def Selected(item, comparator)
46
- Examine(item, comparator) do |field|
46
+ Examine(item, comparator) do |field, value|
47
47
  field.Selected
48
48
  end
49
49
  end
50
50
 
51
51
  def Checked(item, comparator)
52
- Examine(item, comparator) do |field|
52
+ Examine(item, comparator) do |field, value|
53
53
  field.Checked
54
54
  end
55
55
  end
56
56
 
57
57
  def Show(item, comparator)
58
- Examine(item, comparator) do |field|
58
+ Examine(item, comparator) do |field, value|
59
59
  field.Visible
60
60
  end
61
61
  end
62
62
 
63
63
  def Examine(key, comparator, &block)
64
- field = $page.Get(key)
65
- element = field.Find(comparator)
66
-
67
- return Evaluation.new(true, true) if element.nil? and comparator.Compare(true, false)
64
+ item = key
65
+ key = item.first if item.is_a? Array
68
66
  return FieldNotDefinedEvaluation.new(key, $page) if !$page.Contains key
69
67
 
70
- begin
71
- return FieldNotFoundEvaluation.new(key, $page, "selenium could not find the field") if field == nil
72
-
73
- begin
74
- wait = Selenium::WebDriver::Wait.new(:timeout => 5)
75
- result = wait.until {
76
- y = comparator.Compare(block.call(field), true)
77
- y if y == true
78
- }
79
-
68
+ field = $page.Get(key)
69
+ return FieldNotFoundEvaluation.new(key, $page, "selenium could not find the field") if field == nil
80
70
 
81
- return Fix(Evaluation.new(block.call(field), true), comparator)
82
- rescue => e
83
- return FieldNotFoundEvaluation.new(key, $page, e.to_s)
84
- end
71
+ element = field.Find(comparator)
72
+ return Evaluation.new(true, true) if element.nil? and comparator.Compare(true, false)
85
73
 
86
- rescue => e
87
- return FieldNotFoundEvaluation.new(key, $page, e.to_s)
88
- end
74
+ return Fix(field.Evaluate(key, item, comparator, block), comparator)
89
75
  end
90
76
 
91
77
  def Fix(evaluation, comparator)
@@ -3,7 +3,6 @@ module ChildProcess
3
3
  module Lib
4
4
 
5
5
  def self.create_proc(cmd, opts = {})
6
- puts "1"
7
6
  cmd_ptr = F.from_string cmd
8
7
 
9
8
  flags = 0
@@ -10,7 +10,7 @@ module Sapphire
10
10
  end
11
11
 
12
12
  def Visible()
13
- $driver.AlertShown()
13
+ Evaluation.new($driver.AlertShown(), true)
14
14
  end
15
15
 
16
16
  def Find(comparator = nil)
@@ -51,7 +51,7 @@ module Sapphire
51
51
 
52
52
  def Visible
53
53
  control = self.Find
54
- control.displayed?
54
+ Evaluation.new(control.displayed?, true)
55
55
  end
56
56
 
57
57
  def Equals(value, comparator)
@@ -74,6 +74,45 @@ module Sapphire
74
74
  #error land
75
75
  return Evaluation.new(text, values)
76
76
  end
77
+
78
+ def Evaluate(key, arg, comparator, block)
79
+
80
+ value = GetValue(arg, key)
81
+ timeout = GetValue(arg, :wait)
82
+ timeout ||= 5
83
+
84
+ begin
85
+ evaluation = block.call(self, value)
86
+ wait = Selenium::WebDriver::Wait.new(:timeout => timeout)
87
+ result = wait.until {
88
+ evaluation = block.call(self, value)
89
+ y = evaluation.Evaluate()
90
+ comparator = EqualsComparison.new(evaluation) if evaluation == nil
91
+ evaluation if comparator.Compare(y == true, true)
92
+ }
93
+
94
+ return result
95
+ rescue
96
+ return Evaluation.new(evaluation.left, evaluation.right)
97
+ end
98
+ end
99
+
100
+ def GetValue(item, key)
101
+
102
+ if item.is_a? Array
103
+ item.each do |sub_item|
104
+ value = GetValue(sub_item, key)
105
+ return value if !value.nil?
106
+ end
107
+ end
108
+
109
+ if item.is_a? Hash
110
+ return item[key] if item.has_key? key
111
+ end
112
+
113
+ nil
114
+ end
115
+
77
116
  end
78
117
  end
79
118
  end
@@ -2,7 +2,7 @@ module Sapphire
2
2
  module WebAbstractions
3
3
  class CheckBox < Control
4
4
  def Check (value)
5
- checked = self.Checked
5
+ checked = self.Checked().Evaluate()
6
6
 
7
7
  if value && checked
8
8
  return;
@@ -17,7 +17,7 @@ module Sapphire
17
17
 
18
18
  def Checked
19
19
  radio = self.Find
20
- radio.attribute("checked") != nil
20
+ Evaluation.new(radio.attribute("checked") != nil, true)
21
21
  end
22
22
 
23
23
  def Clear
@@ -14,7 +14,14 @@ module Sapphire
14
14
  return EqualsComparison.new(Evaluation.new(item.text, value))
15
15
  end
16
16
  end
17
- return EqualsComparison.new(Evaluation.new("Value not found in list", value))
17
+
18
+ #if here then it couldnt make a match, build up the list of values
19
+ alltext = []
20
+ x.each do |item|
21
+ alltext << item.text
22
+ end
23
+
24
+ return EqualsComparison.new(Evaluation.new(alltext, value))
18
25
  end
19
26
 
20
27
  def In(values, comparator)
@@ -14,13 +14,13 @@ module Sapphire
14
14
  def Selected
15
15
  radio = self.Find
16
16
  val = radio.attribute("selected")
17
- return val != nil
17
+ return Evaluation.new(val != nil, true)
18
18
  end
19
19
 
20
20
  def Visible
21
21
  radio = self.Find
22
22
  x = radio.attribute("disabled")
23
- return (x == "false")
23
+ Evaluation.new((x == "false"), true)
24
24
  end
25
25
 
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
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.7.3
4
+ version: 0.7.4
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: 2012-02-28 00:00:00.000000000Z
12
+ date: 2012-03-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &9907608 !ruby/object:Gem::Requirement
16
+ requirement: &9733176 !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: *9907608
24
+ version_requirements: *9733176
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: colorize
27
- requirement: &9907356 !ruby/object:Gem::Requirement
27
+ requirement: &9732924 !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: *9907356
35
+ version_requirements: *9732924
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: Platform
38
- requirement: &9907104 !ruby/object:Gem::Requirement
38
+ requirement: &9732672 !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: *9907104
46
+ version_requirements: *9732672
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email: