sapphire 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/lib/sapphire.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "test/unit"
2
+ require "rubygems"
3
+ require "rspec"
4
+ require 'yaml'
5
+ require 'selenium-webdriver'
6
+ require 'delegate'
7
+ require 'Forwardable'
8
+ require 'win32ole'
9
+ require 'json'
10
+
11
+ Dir[File.dirname(__FILE__) + '/sapphire/Testing/*.rb'].each {|file| require file }
12
+ Dir[File.dirname(__FILE__) + '/sapphire/WebAbstractions/Controls/Base/*.rb'].each {|file| require file }
13
+ Dir[File.dirname(__FILE__) + '/sapphire/WebAbstractions/Controls/*.rb'].each {|file| require file }
14
+ Dir[File.dirname(__FILE__) + '/sapphire/DataAbstractions/*.rb'].each {|file| require file }
15
+ Dir[File.dirname(__FILE__) + '/sapphire/DSL/Browser/*.rb'].each {|file| require file }
16
+ Dir[File.dirname(__FILE__) + '/sapphire/DSL/Configuration/*.rb'].each {|file| require file }
17
+ Dir[File.dirname(__FILE__) + '/sapphire/DSL/Data/*.rb'].each {|file| require file }
18
+ Dir[File.dirname(__FILE__) + '/sapphire/DSL/Scenarios/*.rb'].each {|file| require file }
19
+
20
+ module Sapphire
21
+ module Sapphire
22
+ include DSL::Scenarios
23
+ include DSL::Browser
24
+ include DSL::Configuration
25
+ include DSL::Data
26
+ include DataAbstractions
27
+ include WebAbstractions
28
+ include Testing
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ class Browser
5
+ def Close
6
+ sleep(2)
7
+ $browser.close
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,12 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Check(*args)
5
+ ExecuteAgainstControl(args) do |control, arg|
6
+ control.Check true
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,15 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Clear(item)
5
+ if(item.is_a? Class)
6
+ x = item.new
7
+ x.Clear
8
+ return
9
+ end
10
+ @page.Reset
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,12 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Click(*args)
5
+ ExecuteAgainstControl(args) do |control, arg|
6
+ control.Click
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Exit(item)
5
+ x = item.new
6
+ x.Close
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+
@@ -0,0 +1,15 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Complete(page)
5
+ if(page.is_a? Class)
6
+ x = page.new(@browser)
7
+ else
8
+ x = page
9
+ end
10
+ @page = x.Complete
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,11 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def CurrentUrl(value)
5
+ url = @browser.CurrentUrl
6
+ url == value
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,12 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Error(hash)
5
+ ExecuteHashAgainstControl(hash) do |control, arg|
6
+ control.Text.should == arg
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,45 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def ExecuteHashAgainstControl(hash, &block)
5
+ hash.keys.each do |key|
6
+ @page.fields.each do |field|
7
+ field.keys.each do |field_key|
8
+ if(field_key == key)
9
+ block.call(field[key], hash[key])
10
+ return
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ raise "cannot find control matching " + hash.to_s + " for page " + @page.to_s
17
+ end
18
+
19
+ def ExecuteAgainstControl(*args, &block)
20
+ @page.fields.each do |field|
21
+ field.keys.each do |field_key|
22
+ args.each do |arg_array|
23
+ arg_array.each do |arg|
24
+ if(field_key == arg)
25
+ block.call(field[field_key], arg)
26
+ return
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ arglist = ""
34
+ args.each do |arg_array|
35
+ arg_array.each do |arg|
36
+ arglist += arg.to_s + ", "
37
+ end
38
+ end
39
+
40
+ raise "Cannot find controls matching: " + arglist + "for page " + @page.to_s
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,22 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Exists(symbol)
5
+ @page.fields.each do |field|
6
+ field.keys.each do |field_key|
7
+ if(field_key == symbol)
8
+ begin
9
+ x = field[field_key].FindWithoutWait
10
+ return x.displayed?
11
+ rescue
12
+ return false
13
+ end
14
+ end
15
+ end
16
+ end
17
+ false
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,10 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def For(item)
5
+ {item => GetPageField(item).Text}
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Hide(args)
5
+ IsHidden(args).should == true
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,28 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def IsHidden(args)
5
+ @page.fields.each do |field|
6
+ field.keys.each do |field_key|
7
+ if(field_key == args)
8
+ begin
9
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
10
+ element = wait.until { x = field[field_key].Find
11
+ x and !x.displayed?
12
+ }
13
+ if(element)
14
+ return element.displayed?
15
+ end
16
+ rescue
17
+ return true
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ raise "cannot find control matching " + args.to_s + " for page " + @page.to_s
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,25 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def IsVisible(args)
5
+ @page.fields.each do |field|
6
+ field.keys.each do |field_key|
7
+ if(field_key == args)
8
+ begin
9
+ x = field[field_key].Find
10
+ if(x)
11
+ return x.displayed?
12
+ end
13
+ rescue
14
+ return false
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ raise "cannot find control matching " + args.to_s + " for page " + @page.to_s
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,12 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def MouseOver(*args)
5
+ ExecuteAgainstControl(args) do |control, arg|
6
+ control.MouseOver
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Navigate(page)
5
+ @page = @browser.NavigateTo(page)
6
+ @page.Init
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,11 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Reload(item)
5
+ @browser.Reload
6
+ Should Show item
7
+ end
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,12 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Set(hash)
5
+ ExecuteHashAgainstControl(hash) do |control, arg|
6
+ control.Set arg
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,10 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Should(item)
5
+ item
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,26 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Show(item)
5
+
6
+ if(item.is_a? Hash)
7
+ ExecuteHashAgainstControl(item) do |control, arg|
8
+ control.Text.should == arg
9
+ end
10
+ return
11
+ elsif(item.is_a? Symbol)
12
+ IsVisible(item).should == true
13
+ return
14
+ elsif(item.is_a? Class)
15
+ @page = @browser.ShouldNavigateTo item
16
+ sleep(1)
17
+ else
18
+ @page = item
19
+ end
20
+
21
+ @page.Init
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,16 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Start(browser)
5
+ if(browser == ConfigurationBrowser)
6
+ @browser = AppConfig.Current.Browser
7
+ else
8
+ @browser = browser
9
+ end
10
+
11
+ @browser.SetRootUrl(@rootUrl)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,10 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def To(url)
5
+ url
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Track(hash)
5
+ $tracker ||= {}
6
+ $tracker.merge! hash
7
+ end
8
+
9
+ def Tracker(item)
10
+ $tracker[item]
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,10 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Transition(url)
5
+ @browser.ShouldTransitionTo url
6
+ end
7
+ end
8
+ end
9
+ end
10
+