sapphire 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/lib/sapphire.rb +30 -0
  2. data/lib/sapphire/DSL/Browser/Browser.rb +13 -0
  3. data/lib/sapphire/DSL/Browser/Check.rb +12 -0
  4. data/lib/sapphire/DSL/Browser/Clear.rb +15 -0
  5. data/lib/sapphire/DSL/Browser/Click.rb +12 -0
  6. data/lib/sapphire/DSL/Browser/Close.rb +12 -0
  7. data/lib/sapphire/DSL/Browser/Complete.rb +15 -0
  8. data/lib/sapphire/DSL/Browser/CurrentUrl.rb +11 -0
  9. data/lib/sapphire/DSL/Browser/Error.rb +12 -0
  10. data/lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb +45 -0
  11. data/lib/sapphire/DSL/Browser/Exists.rb +22 -0
  12. data/lib/sapphire/DSL/Browser/For.rb +10 -0
  13. data/lib/sapphire/DSL/Browser/Hide.rb +10 -0
  14. data/lib/sapphire/DSL/Browser/IsHidden.rb +28 -0
  15. data/lib/sapphire/DSL/Browser/IsVisible.rb +25 -0
  16. data/lib/sapphire/DSL/Browser/MouseOver.rb +12 -0
  17. data/lib/sapphire/DSL/Browser/Navigate.rb +11 -0
  18. data/lib/sapphire/DSL/Browser/Reload.rb +11 -0
  19. data/lib/sapphire/DSL/Browser/Set.rb +12 -0
  20. data/lib/sapphire/DSL/Browser/Should.rb +10 -0
  21. data/lib/sapphire/DSL/Browser/Show.rb +26 -0
  22. data/lib/sapphire/DSL/Browser/Start.rb +16 -0
  23. data/lib/sapphire/DSL/Browser/To.rb +10 -0
  24. data/lib/sapphire/DSL/Browser/Tracker.rb +15 -0
  25. data/lib/sapphire/DSL/Browser/Transition.rb +10 -0
  26. data/lib/sapphire/DSL/Browser/Uncheck.rb +12 -0
  27. data/lib/sapphire/DSL/Browser/With.rb +10 -0
  28. data/lib/sapphire/DSL/Configuration/ConfiguredBrowser.rb +13 -0
  29. data/lib/sapphire/DSL/Configuration/ConfiguredUser.rb +11 -0
  30. data/lib/sapphire/DSL/Configuration/Use.rb +15 -0
  31. data/lib/sapphire/DSL/Data/Exist.rb +11 -0
  32. data/lib/sapphire/DSL/Data/Find.rb +10 -0
  33. data/lib/sapphire/DSL/Data/GetPageField.rb +17 -0
  34. data/lib/sapphire/DSL/Data/Underscore.rb +9 -0
  35. data/lib/sapphire/DSL/Data/Validate.rb +16 -0
  36. data/lib/sapphire/DSL/Data/Verify.rb +10 -0
  37. data/lib/sapphire/DSL/Scenarios/Is.rb +9 -0
  38. data/lib/sapphire/DSL/Scenarios/Pending.rb +29 -0
  39. data/lib/sapphire/DSL/Scenarios/and.rb +25 -0
  40. data/lib/sapphire/DSL/Scenarios/background.rb +23 -0
  41. data/lib/sapphire/DSL/Scenarios/dsl.rb +60 -0
  42. data/lib/sapphire/DSL/Scenarios/finally.rb +32 -0
  43. data/lib/sapphire/DSL/Scenarios/given.rb +57 -0
  44. data/lib/sapphire/DSL/Scenarios/runner.rb +30 -0
  45. data/lib/sapphire/DSL/Scenarios/scenario.rb +51 -0
  46. data/lib/sapphire/DSL/Scenarios/then.rb +34 -0
  47. data/lib/sapphire/DSL/Scenarios/when.rb +47 -0
  48. data/lib/sapphire/DataAbstractions/Database.rb +57 -0
  49. data/lib/sapphire/DataAbstractions/Query.rb +20 -0
  50. data/lib/sapphire/Testing/Executable.rb +30 -0
  51. data/lib/sapphire/Testing/RSpecRunner.rb +85 -0
  52. data/lib/sapphire/Testing/RakeTask.rb +109 -0
  53. data/lib/sapphire/Testing/ResultList.rb +19 -0
  54. data/lib/sapphire/Testing/ResultTree.rb +37 -0
  55. data/lib/sapphire/Testing/ScenarioResult.rb +31 -0
  56. data/lib/sapphire/Testing/TestResult.rb +24 -0
  57. data/lib/sapphire/Testing/TestRunnerAdapter.rb +62 -0
  58. data/lib/sapphire/WebAbstractions/Controls/Base/Control.rb +74 -0
  59. data/lib/sapphire/WebAbstractions/Controls/Base/Page.rb +47 -0
  60. data/lib/sapphire/WebAbstractions/Controls/Base/WebBrowser.rb +74 -0
  61. data/lib/sapphire/WebAbstractions/Controls/Button.rb +9 -0
  62. data/lib/sapphire/WebAbstractions/Controls/CheckBox.rb +28 -0
  63. data/lib/sapphire/WebAbstractions/Controls/Chrome.rb +21 -0
  64. data/lib/sapphire/WebAbstractions/Controls/DropDown.rb +25 -0
  65. data/lib/sapphire/WebAbstractions/Controls/FireFox.rb +22 -0
  66. data/lib/sapphire/WebAbstractions/Controls/Hyperlink.rb +8 -0
  67. data/lib/sapphire/WebAbstractions/Controls/Image.rb +9 -0
  68. data/lib/sapphire/WebAbstractions/Controls/InternetExplorer.rb +21 -0
  69. data/lib/sapphire/WebAbstractions/Controls/Label.rb +8 -0
  70. data/lib/sapphire/WebAbstractions/Controls/RadioButton.rb +18 -0
  71. data/lib/sapphire/WebAbstractions/Controls/TextBox.rb +31 -0
  72. data/lib/sapphire/WebAbstractions/Controls/Title.rb +12 -0
  73. data/lib/sapphire/version.rb +3 -0
  74. metadata +152 -0
@@ -0,0 +1,31 @@
1
+ module Sapphire
2
+ module Testing
3
+ class ScenarioResult
4
+
5
+ attr_reader :results
6
+ attr_accessor :myId
7
+ attr_reader :type
8
+
9
+ def initialize(text)
10
+ @text = text
11
+ @results = []
12
+ @leaf = true
13
+ @myId = -1
14
+ @type = 'pass'
15
+ end
16
+
17
+ def AddChild(result)
18
+ @results << result
19
+ end
20
+
21
+ def set_id(id)
22
+ @myId = id
23
+ end
24
+
25
+ def set_type(type)
26
+ @type = type
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ module Sapphire
2
+ module Testing
3
+ class TestResult
4
+
5
+ attr_reader :execution_time
6
+ attr_reader :message
7
+ attr_reader :myId
8
+ attr_reader :text
9
+ attr_reader :type
10
+ attr_reader :stack
11
+ attr_reader :message
12
+
13
+ def initialize(type, text, message, stack, execution_time, id)
14
+ @myId = id
15
+ @text = text
16
+ @execution_time = execution_time
17
+ @message = message
18
+ @stack = stack
19
+ @type = type
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,62 @@
1
+ module Sapphire
2
+ module Testing
3
+ module TestRunnerAdapter
4
+
5
+ def execute(id)
6
+
7
+ self.backgrounds.each do |b|
8
+
9
+ b.execute id
10
+
11
+ end
12
+
13
+ self.givens.each do |g|
14
+
15
+ g.when.each do |w|
16
+
17
+ g.execute id
18
+
19
+ g.and.each do |g_a|
20
+
21
+ g_a.execute id
22
+
23
+ end
24
+
25
+ w.execute id
26
+
27
+ w.and.each do |w_a|
28
+
29
+ w_a.execute id
30
+
31
+ end
32
+
33
+ w.then.each do |t|
34
+
35
+ t.execute id
36
+
37
+ t.and.each do |t_a|
38
+
39
+ t_a.execute id
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ if(g.finally)
48
+
49
+ g.finally.execute id
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+
61
+
62
+
@@ -0,0 +1,74 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Control
4
+ def initialize(browser, hash)
5
+ @browser = browser
6
+ @hash = hash
7
+ end
8
+
9
+ def Find
10
+ if(@hash.has_key?(:id))
11
+ FindBy :id
12
+ elsif (@hash.has_key?(:name))
13
+ FindBy :name
14
+ elsif (@hash.has_key?(:xpath))
15
+ FindBy :xpath
16
+ end
17
+ end
18
+
19
+ def FindWithoutWait
20
+ if(@hash.has_key?(:id))
21
+ FindWithoutWaitBy :id
22
+ elsif (@hash.has_key?(:name))
23
+ FindWithoutWaitBy :name
24
+ elsif (@hash.has_key?(:xpath))
25
+ FindWithoutWaitBy :xpath
26
+ end
27
+ end
28
+
29
+ def FindWithoutWaitBy(symbol)
30
+ @browser.find_element symbol, @hash.fetch(symbol)
31
+ end
32
+
33
+ def FindBy(symbol)
34
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
35
+ element = wait.until { x = @browser.find_element symbol, @hash.fetch(symbol)
36
+ x
37
+ }
38
+ end
39
+
40
+ def FindParent(hash)
41
+ if(hash.has_key?(:id))
42
+ @browser.find_element :id, hash.fetch(:id)
43
+ elsif (hash.has_key?(:name))
44
+ @browser.find_element :name, hash.fetch(:name)
45
+ elsif (hash.has_key?(:xpath))
46
+ @browser.find_element :xpath, hash.fetch(:xpath)
47
+ end
48
+ end
49
+
50
+ def Text
51
+ text = self.Find
52
+ text.text
53
+ end
54
+
55
+ def Click
56
+ control = self.Find
57
+ control.click
58
+ end
59
+
60
+ def MouseOver
61
+ if(@hash.has_key?(:id))
62
+ @browser.execute_script("document.getElementById('"+ @hash.fetch(:id) +"').style.visibility = 'visible'; ")
63
+ elsif (@hash.has_key?(:name))
64
+ @browser.execute_script("document.getElementById('"+ @hash.fetch(:name) +"').style.visibility = 'visible'; ")
65
+ elsif (@hash.has_key?(:xpath))
66
+ @browser.execute_script("document.evaluate( '" + @hash.fetch(:xpath) + "', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.visibility = 'visible'; ")
67
+ end
68
+ sleep(1)
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+
@@ -0,0 +1,47 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Page
4
+
5
+ attr_reader :fields
6
+
7
+ def initialize(browser)
8
+ @browser = browser
9
+ @fields = []
10
+ end
11
+
12
+ def DropDown(*args)
13
+ @fields << { args.first => DropDown.new(@browser, args[1]) }
14
+ end
15
+
16
+ def TextBox(*args)
17
+ @fields << { args.first => TextBox.new(@browser, args[1]) }
18
+ end
19
+
20
+ def RadioButton(*args)
21
+ @fields << { args.first => RadioButton.new(@browser, args[1]) }
22
+ end
23
+
24
+ def CheckBox(*args)
25
+ @fields << { args.first => CheckBox.new(@browser, args[1]) }
26
+ end
27
+
28
+ def Button(*args)
29
+ @fields << { args.first => Button.new(@browser, args[1]) }
30
+ end
31
+
32
+ def Label(*args)
33
+ @fields << { args.first => Label.new(@browser, args[1]) }
34
+ end
35
+
36
+ def Image(*args)
37
+ @fields << { args.first => Image.new(@browser, args[1]) }
38
+ end
39
+
40
+ def Hyperlink(*args)
41
+ @fields << { args.first => Hyperlink.new(@browser, args[1]) }
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,74 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ module WebBrowser
4
+
5
+ attr_reader :rootUrl
6
+
7
+ def Init(url)
8
+ @rootUrl = url
9
+ end
10
+
11
+ def SetRootUrl(url)
12
+ if(url.instance_of?(String))
13
+ self.Init(url)
14
+ else
15
+ x = url.new().Url
16
+ self.Init(x)
17
+ end
18
+ end
19
+
20
+ def NavigateTo(page)
21
+ if(page.is_a? Class)
22
+ nav = page.new self
23
+ else
24
+ nav = page
25
+ end
26
+
27
+ self.browser.get "https://" + nav.Url
28
+ nav
29
+ end
30
+
31
+ def CurrentUrl
32
+ self.current_url
33
+ end
34
+
35
+ def Reload
36
+ self.browser.get self.current_url
37
+ end
38
+
39
+ def ShouldNavigateTo(page)
40
+ if(page.is_a? Class)
41
+ nav = page.new self
42
+ else
43
+ nav = page
44
+ end
45
+
46
+ self.current_url.upcase.start_with?("HTTPS://" + nav.Url.upcase).should == true
47
+
48
+ nav
49
+ end
50
+
51
+ def Run(background)
52
+ scenario = background.new self
53
+ scenario.Run
54
+ end
55
+
56
+ def ShouldShow(page)
57
+ self.ShouldNavigateTo page
58
+ end
59
+
60
+ def ShouldTransitionTo(url)
61
+ if(url.instance_of?(String))
62
+ self.current_url.upcase.start_with?("HTTPS://" + url.upcase).should == true
63
+ @rootUrl = url
64
+ else
65
+ x = url.new().Url
66
+ self.current_url.upcase.start_with?("HTTPS://" + x.upcase).should == true
67
+ @rootUrl = x
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../WebAbstractions/Controls/Base/Control', File.dirname(__FILE__))
2
+
3
+ module Sapphire
4
+ module WebAbstractions
5
+ class Button < Control
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,28 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class CheckBox < Control
4
+ def Check (value)
5
+
6
+ if value && self.IsChecked
7
+ return;
8
+ end
9
+
10
+ if !value && !self.IsChecked
11
+ return;
12
+ end
13
+
14
+ radio = self.Find
15
+ radio.click
16
+
17
+ end
18
+
19
+ def IsChecked
20
+
21
+ radio = self.Find
22
+ radio.attribute("checked");
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,21 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ def Chrome(url)
4
+ ChromeBrowser.new
5
+ end
6
+
7
+ class ChromeBrowser < DelegateClass(Selenium::WebDriver::Chrome::Bridge)
8
+ include WebBrowser
9
+
10
+ attr_reader :browser
11
+
12
+ def initialize()
13
+ @browser = Selenium::WebDriver.for :chrome
14
+ super @browser
15
+ $browser = @browser
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+
@@ -0,0 +1,25 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class DropDown < Control
4
+ def Selected= (value)
5
+ text = self.Find
6
+ text.send_keys value
7
+ end
8
+
9
+ def Selected
10
+ text = self.Find
11
+ text.value
12
+ end
13
+
14
+ def Set(value)
15
+ text = self.Find
16
+ text.send_keys value
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+
24
+
25
+
@@ -0,0 +1,22 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class FireFoxBrowser < DelegateClass(Selenium::WebDriver::Firefox::Bridge)
4
+ include WebBrowser
5
+
6
+ attr_reader :browser
7
+
8
+ def initialize()
9
+ @browser = Selenium::WebDriver.for :firefox
10
+ super(@browser)
11
+ $browser = @browser
12
+ end
13
+
14
+ end
15
+
16
+ def FireFox(url)
17
+ FireFoxBrowser.new
18
+ end
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,8 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Hyperlink < Control
4
+
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,9 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Image < Control
4
+
5
+ end
6
+ end
7
+ end
8
+
9
+