fluent 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +21 -0
  3. data/lib/fluent.rb +29 -2
  4. data/lib/fluent/enclosers.rb +35 -0
  5. data/lib/fluent/evaluators.rb +82 -0
  6. data/lib/fluent/factory.rb +31 -0
  7. data/lib/fluent/generators.rb +116 -18
  8. data/lib/fluent/platform_selenium.rb +18 -0
  9. data/lib/fluent/platform_selenium/platform_object.rb +21 -0
  10. data/lib/fluent/platform_watir/platform_object.rb +181 -14
  11. data/lib/fluent/platform_watir/platform_web_elements/checkbox.rb +21 -0
  12. data/lib/fluent/platform_watir/platform_web_elements/radio.rb +21 -0
  13. data/lib/fluent/platform_watir/platform_web_elements/select_list.rb +30 -4
  14. data/lib/fluent/platform_watir/platform_web_elements/text_field.rb +13 -0
  15. data/lib/fluent/platform_watir/platform_web_elements/web_element.rb +84 -5
  16. data/lib/fluent/platforms.rb +2 -1
  17. data/lib/fluent/version.rb +1 -1
  18. data/lib/fluent/web_elements/cell.rb +16 -0
  19. data/lib/fluent/web_elements/checkbox.rb +4 -0
  20. data/lib/fluent/web_elements/div.rb +16 -0
  21. data/lib/fluent/web_elements/list_item.rb +16 -0
  22. data/lib/fluent/web_elements/ordered_list.rb +16 -0
  23. data/lib/fluent/web_elements/radio.rb +4 -0
  24. data/lib/fluent/web_elements/select_list.rb +4 -0
  25. data/lib/fluent/web_elements/span.rb +16 -0
  26. data/lib/fluent/web_elements/table.rb +16 -0
  27. data/lib/fluent/web_elements/text_area.rb +16 -0
  28. data/lib/fluent/web_elements/text_field.rb +8 -0
  29. data/lib/fluent/web_elements/unordered_list.rb +16 -0
  30. data/lib/fluent/web_elements/web_element.rb +12 -0
  31. data/spec/enclosers_spec.rb +38 -0
  32. data/spec/evaluators_spec.rb +88 -0
  33. data/spec/factory_spec.rb +42 -0
  34. data/spec/fluent_spec.rb +32 -1
  35. data/spec/generators/cell_generators_spec.rb +50 -0
  36. data/spec/generators/div_generators_spec.rb +49 -0
  37. data/spec/generators/list_item_generators_spec.rb +53 -0
  38. data/spec/generators/ordered_list_generators_spec.rb +53 -0
  39. data/spec/generators/span_generators_spec.rb +49 -0
  40. data/spec/generators/table_generators_spec.rb +49 -0
  41. data/spec/generators/text_area_generators_spec.rb +55 -0
  42. data/spec/generators/unordered_list_generators_spec.rb +53 -0
  43. data/spec/generators_spec.rb +40 -0
  44. data/spec/mock_app.rb +17 -0
  45. data/spec/platform_object_spec.rb +9 -0
  46. data/spec/web_element_spec.rb +15 -0
  47. data/spec/web_element_watir_spec.rb +123 -5
  48. data/spec/web_elements/checkbox_spec.rb +21 -0
  49. data/spec/web_elements/radio_spec.rb +21 -0
  50. data/spec/web_elements/select_list_spec.rb +41 -0
  51. data/spec/web_elements/text_field_spec.rb +16 -0
  52. metadata +48 -2
@@ -28,4 +28,5 @@ module Fluent
28
28
  end
29
29
  end
30
30
 
31
- require 'fluent/platform_watir'
31
+ require 'fluent/platform_watir'
32
+ require 'fluent/platform_selenium'
@@ -1,3 +1,3 @@
1
1
  module Fluent
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class Cell < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -9,6 +9,10 @@ module Fluent
9
9
 
10
10
  def include_platform_specifics_for(platform)
11
11
  super
12
+ if platform[:platform] == :watir_webdriver
13
+ require 'fluent/platform_watir/platform_web_elements/checkbox'
14
+ self.class.send :include, Fluent::Platforms::WatirWebDriver::CheckBox
15
+ end
12
16
  end
13
17
 
14
18
  end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class Div < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class ListItem < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class OrderedList < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -9,6 +9,10 @@ module Fluent
9
9
 
10
10
  def include_platform_specifics_for(platform)
11
11
  super
12
+ if platform[:platform] == :watir_webdriver
13
+ require 'fluent/platform_watir/platform_web_elements/radio'
14
+ self.class.send :include, Fluent::Platforms::WatirWebDriver::Radio
15
+ end
12
16
  end
13
17
 
14
18
  end
@@ -7,6 +7,10 @@ module Fluent
7
7
  include_platform_specifics_for platform
8
8
  end
9
9
 
10
+ def option_xpath
11
+ './/child::option'
12
+ end
13
+
10
14
  def include_platform_specifics_for(platform)
11
15
  super
12
16
  if platform[:platform] == :watir_webdriver
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class Span < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class Table < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class TextArea < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -6,9 +6,17 @@ module Fluent
6
6
  @web_element = web_element
7
7
  include_platform_specifics_for platform
8
8
  end
9
+
10
+ def append(text)
11
+ web_element.send_keys(text)
12
+ end
9
13
 
10
14
  def include_platform_specifics_for(platform)
11
15
  super
16
+ if platform[:platform] == :watir_webdriver
17
+ require 'fluent/platform_watir/platform_web_elements/text_field'
18
+ self.class.send :include, Fluent::Platforms::WatirWebDriver::TextField
19
+ end
12
20
  end
13
21
 
14
22
  end
@@ -0,0 +1,16 @@
1
+ module Fluent
2
+ module WebElements
3
+ class UnorderedList < WebElement
4
+
5
+ def initialize(web_element, platform)
6
+ @web_element = web_element
7
+ include_platform_specifics_for platform
8
+ end
9
+
10
+ def include_platform_specifics_for(platform)
11
+ super
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -8,6 +8,10 @@ module Fluent
8
8
  @web_element = web_element
9
9
  include_platform_specifics_for platform
10
10
  end
11
+
12
+ def text
13
+ web_element.text
14
+ end
11
15
 
12
16
  def click
13
17
  web_element.click
@@ -21,6 +25,14 @@ module Fluent
21
25
  not enabled?
22
26
  end
23
27
 
28
+ def style(property)
29
+ web_element.style property
30
+ end
31
+
32
+ def class_name
33
+ attribute('class')
34
+ end
35
+
24
36
  def include_platform_specifics_for(platform)
25
37
  if platform[:platform] == :watir_webdriver
26
38
  require 'fluent/platform_watir/platform_web_elements/web_element'
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ class EnclosersTest
4
+ include Fluent
5
+
6
+ end
7
+
8
+ describe Fluent::Enclosers do
9
+ let(:watir_browser) { mock_browser_for_watir }
10
+ let(:watir_definition) { EnclosersTest.new(watir_browser) }
11
+
12
+ context 'a definition using watir-webdriver' do
13
+ it 'should handle alert message boxes' do
14
+ watir_browser.should_receive(:alert).exactly(3).times.and_return(watir_browser)
15
+ watir_browser.should_receive(:exists?).and_return(true)
16
+ watir_browser.should_receive(:text)
17
+ watir_browser.should_receive(:ok)
18
+ watir_definition.will_alert do
19
+ end
20
+ end
21
+
22
+ it 'should handle confirmation message boxes' do
23
+ watir_browser.should_receive(:alert).exactly(3).times.and_return(watir_browser)
24
+ watir_browser.should_receive(:exists?).and_return(true)
25
+ watir_browser.should_receive(:text)
26
+ watir_browser.should_receive(:ok)
27
+ watir_definition.will_confirm(true) do
28
+ end
29
+ end
30
+
31
+ it 'should handle prompt message boxes' do
32
+ watir_browser.should_receive(:wd).twice.and_return(watir_browser)
33
+ watir_browser.should_receive(:execute_script).twice
34
+ watir_definition.will_prompt('Testing') do
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'mock_app'
3
+
4
+ describe Fluent::Evaluators do
5
+ let(:watir_browser) { mock_browser_for_watir }
6
+ let(:watir_definition) { TestDefinition.new(watir_browser) }
7
+
8
+ describe 'browser-level actions' do
9
+ context 'a definition using watir-webdriver' do
10
+ it 'should get the active url' do
11
+ watir_browser.should_receive(:url).twice.and_return('http://localhost:9292')
12
+ watir_definition.url.should == 'http://localhost:9292'
13
+ watir_definition.current_url.should == 'http://localhost:9292'
14
+ end
15
+
16
+ it 'should be able to clear all of the cookies from the browser' do
17
+ watir_browser.should_receive(:cookies).twice.and_return(watir_browser)
18
+ watir_browser.should_receive(:clear).twice
19
+ watir_definition.remove_cookies
20
+ watir_definition.clear_cookies
21
+ end
22
+
23
+ it 'should be able to refresh the page contents' do
24
+ watir_browser.should_receive(:refresh).twice.and_return(watir_browser)
25
+ watir_definition.refresh_page
26
+ watir_definition.refresh
27
+ end
28
+
29
+ it 'should run a script against the browser' do
30
+ watir_browser.should_receive(:execute_script).twice.and_return('input')
31
+ watir_definition.run_script('return document.activeElement').should == 'input'
32
+ watir_definition.execute_script('return document.activeElement').should == 'input'
33
+ end
34
+
35
+ it 'should get a screenshot' do
36
+ watir_browser.should_receive(:wd).twice.and_return(watir_browser)
37
+ watir_browser.should_receive(:save_screenshot).twice
38
+ watir_definition.screenshot('testing.png')
39
+ watir_definition.save_screenshot('testing.png')
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'page-level actions' do
45
+ context 'a definition using watir-webdriver' do
46
+ it 'should return all the markup on a page' do
47
+ watir_browser.should_receive(:html).twice.and_return('<h1>Page Title</h1>')
48
+ watir_definition.markup.should == '<h1>Page Title</h1>'
49
+ watir_definition.html.should == '<h1>Page Title</h1>'
50
+ end
51
+
52
+ it 'should return the title of a page' do
53
+ watir_browser.should_receive(:title).twice.and_return('Page Title')
54
+ watir_definition.page_title.should == 'Page Title'
55
+ watir_definition.title.should == 'Page Title'
56
+ end
57
+
58
+ it 'should return all the text on a page' do
59
+ watir_browser.should_receive(:text).twice.and_return('page text')
60
+ watir_definition.page_text.should == 'page text'
61
+ watir_definition.text.should == 'page text'
62
+ end
63
+
64
+ it 'should wait for jquery pending requests to finish' do
65
+ watir_browser.should_receive(:execute_script).with('return jQuery.active').and_return(0)
66
+ watir_definition.wait_for_pending_requests
67
+ end
68
+
69
+ it 'should return an exception if pending requests did not finish' do
70
+ watir_browser.should_receive(:execute_script).at_least(1).times.with('return jQuery.active').and_return(1)
71
+ expect { watir_definition.wait_for_pending_requests(0.1) }.to raise_error
72
+ end
73
+
74
+ it 'should wait for a condition to be true' do
75
+ watir_browser.should_receive(:wait_until).with(5, 'some condition')
76
+ watir_definition.wait_until(5, 'some condition')
77
+ end
78
+
79
+ it 'should wait for a condition to be true with any page level timeout' do
80
+ Fluent.page_level_wait = 30
81
+ watir_browser.should_receive(:wait_until).with(30, nil)
82
+ watir_definition.wait_until
83
+ end
84
+
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'mock_app'
3
+
4
+ class TestFactory
5
+ include Fluent::Factory
6
+
7
+ attr_accessor :browser
8
+ end
9
+
10
+ class DefinitionTest
11
+ include Fluent
12
+
13
+ url_is 'http://localhost:9292'
14
+ end
15
+
16
+ describe Fluent::Factory do
17
+ before(:each) do
18
+ @factory = TestFactory.new
19
+ @factory.browser = mock_browser_for_watir
20
+ end
21
+
22
+ it 'should create a new definition object and view it, using on_view' do
23
+ @factory.browser.should_receive(:goto)
24
+ @factory.on_view DefinitionTest do |page|
25
+ page.should be_instance_of DefinitionTest
26
+ end
27
+ end
28
+
29
+ it 'should create a new definition object, using on' do
30
+ @factory.browser.should_not_receive(:goto)
31
+ @factory.on DefinitionTest do |page|
32
+ page.should be_instance_of DefinitionTest
33
+ end
34
+ end
35
+
36
+ it 'should set a reference to be used outside the factory' do
37
+ active = @factory.on DefinitionTest
38
+ current = @factory.instance_variable_get '@active'
39
+ current.should === active
40
+ end
41
+
42
+ end
data/spec/fluent_spec.rb CHANGED
@@ -5,5 +5,36 @@ describe Fluent do
5
5
  it 'should return version information' do
6
6
  Fluent.version.should == "Fluent v#{Fluent::VERSION}"
7
7
  end
8
-
8
+
9
+ it 'should set the element level wait default to 5' do
10
+ Fluent.instance_variable_set('@element_wait', nil)
11
+ Fluent.element_level_wait.should == 5
12
+ end
13
+
14
+ it 'should allow the element level wait to be set' do
15
+ Fluent.instance_variable_set('@element_wait', 10)
16
+ Fluent.element_level_wait.should == 10
17
+ end
18
+
19
+ it 'should be able to set an element level wait value' do
20
+ Fluent.element_level_wait = 10
21
+ value = Fluent.instance_variable_get('@element_wait')
22
+ value.should == 10
23
+ end
24
+
25
+ it 'should set the page level wait default to 15' do
26
+ Fluent.instance_variable_set('@page_wait', nil)
27
+ Fluent.page_level_wait.should == 15
28
+ end
29
+
30
+ it 'should allow the page level wait to be set' do
31
+ Fluent.instance_variable_set('@page_wait', 10)
32
+ Fluent.page_level_wait.should == 10
33
+ end
34
+
35
+ it 'should be able to set a page level wait value' do
36
+ Fluent.page_level_wait = 30
37
+ value = Fluent.instance_variable_get('@page_wait')
38
+ value.should == 30
39
+ end
9
40
  end