symbiont 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Change Log and History
2
2
  ======================
3
3
 
4
+ Version 0.0.2 / 2012-03-15
5
+ --------------------------
6
+
7
+ This implementation of Symbiont is designed to show the basics of how platform objects, web objects, and a generator mechanism work together to create a test script style that normalizes execution with Selenium and Watir and provides a convention-based approach to interaction with browser objects.
8
+
9
+
4
10
  Version 0.0.1 / 2012-03-02
5
11
  --------------------------
6
12
 
data/README.md CHANGED
@@ -6,6 +6,8 @@ Description
6
6
 
7
7
  The Symbiont gem is designed to provide an open framework for running automated tests against a browser using popular web testing interfaces.
8
8
 
9
+ Right now the best information on the purpose of this project and how it works can be found on [my Symbiont-tagged blog posts](http://testerstories.com/?cat=16).
10
+
9
11
 
10
12
  Meaning
11
13
  -------
@@ -15,5 +15,80 @@ module Symbiont
15
15
  end
16
16
  end
17
17
 
18
+ # This method allows for a begin_at() method in definitions. The
19
+ # URL provided can be navigated to using the generated start()
20
+ # method on a definition instance.
21
+ #
22
+ # @see Symbiont::Generators#url_is
23
+ # @param [String] url the resource identifier to access
24
+ # @return [Nil]
25
+ def begin_at(url)
26
+ define_method("start") do
27
+ @platform.visit(url)
28
+ end
29
+ end
30
+
31
+ # Definition method for links. Methods for the following actions will
32
+ # be created:
33
+ # * reference a link (identifier_object, identifier_link)
34
+ # * click a link (identifier)
35
+ # @param [Symbol] identifier the friendly name of the web object
36
+ # @param [optional, Hash] locator the key/values that identify the object
37
+ # @return [Object] instance of Symbiont::WebObjects::Link
38
+ def link(identifier, locator)
39
+ define_method("#{identifier}_object") do
40
+ @platform.get_link_for(locator.clone)
41
+ end
42
+
43
+ alias_method "#{identifier}_link".to_sym, "#{identifier}_object".to_sym
44
+
45
+ define_method(identifier) do
46
+ @platform.click_link_for(locator.clone)
47
+ end
48
+ end
49
+
50
+ # Definition method for buttons. Methods for the following actions will
51
+ # be created:
52
+ # * reference a button (identifier_object, identifier_button)
53
+ # * click a button (identifier)
54
+ # @param [Symbol] identifier the friendly name of the web object
55
+ # @param [optional, Hash] locator the key/values that identify the object
56
+ # @return [Object] instance of Symbiont::WebObjects::Button
57
+ def button(identifier, locator)
58
+ define_method("#{identifier}_object") do
59
+ @platform.get_button_for(locator.clone)
60
+ end
61
+
62
+ alias_method "#{identifier}_button".to_sym, "#{identifier}_object".to_sym
63
+
64
+ define_method(identifier) do
65
+ @platform.click_button_for(locator.clone)
66
+ end
67
+ end
68
+
69
+ # Definition method for text fields. Methods for the following actions
70
+ # will be created:
71
+ # * reference a text field (identifier_object, identifier_button)
72
+ # * get text from a text field (identifier)
73
+ # * set text in a text field (identifier=)
74
+ # @param [Symbol] identifier the friendly name of the web object
75
+ # @param [optional, Hash] locator the key/values that identify the object
76
+ # @return [Object] instance of Symbiont::WebObjects::TextField
77
+ def text_field(identifier, locator)
78
+ define_method("#{identifier}_object") do
79
+ @platform.get_text_field_for(locator.clone)
80
+ end
81
+
82
+ alias_method "#{identifier}_text_field".to_sym, "#{identifier}_object".to_sym
83
+
84
+ define_method(identifier) do
85
+ @platform.get_text_field_value_for(locator.clone)
86
+ end
87
+
88
+ define_method("#{identifier}=") do |value|
89
+ @platform.set_text_field_value_for(locator.clone, value)
90
+ end
91
+ end
92
+
18
93
  end # module: Generators
19
94
  end # module: Symbiont
@@ -14,8 +14,58 @@ module Symbiont
14
14
  @browser.navigate.to(url)
15
15
  end
16
16
 
17
+ # Platform method to return a link object.
18
+ # Link objects are of type: Symbiont::WebObjects::Link
19
+ # @see Symbiont::Generators#link
20
+ def get_link_for(locator)
21
+ web_object = @browser.find_element(locator.keys.first, locator.values.first)
22
+ WebObjects::Link.new()
23
+ end
24
+
25
+ # Platform method to click a link object.
26
+ # @see Symbiont::Generators#link
27
+ def click_link_for(locator)
28
+ @browser.find_element(locator.keys.first, locator.values.first).click
29
+ end
30
+
31
+ # Platform method to return a button object.
32
+ # Button objects are of type: Symbiont::WebObjects::Button
33
+ # @see Symbiont::Generators#button
34
+ def get_button_for(locator)
35
+ web_object = @browser.find_element(locator.keys.first, locator.values.first)
36
+ WebObjects::Button.new()
37
+ end
38
+
39
+ # Platform method to click a button object.
40
+ # @see Symbiont::Generators#button
41
+ def click_button_for(locator)
42
+ @browser.find_element(locator.keys.first, locator.values.first).click
43
+ end
44
+
45
+ # Platform method to return a text field object.
46
+ # Text field objects are of type: Symbiont::WebObjects::TextField
47
+ # @see Symbiont::Generators#text_field
48
+ def get_text_field_for(locator)
49
+ web_object = @browser.find_element(locator.keys.first, locator.values.first)
50
+ WebObjects::TextField.new()
51
+ end
52
+
53
+ # Platform method to retrieve text from a text field object.
54
+ # @see Symbiont::Generators#text_field
55
+ def get_text_field_value_for(locator)
56
+ @browser.find_element(locator.keys.first, locator.values.first).attribute('value')
57
+ end
58
+
59
+ # Platform method to enter text into a text field object.
60
+ # @see Symbiont::Generators#text_field
61
+ def set_text_field_value_for(locator, value)
62
+ @browser.find_element(locator.keys.first, locator.values.first).clear
63
+ @browser.find_element(locator.keys.first, locator.values.first).send_keys(value)
64
+ end
17
65
  end # class: PlatformObject
18
66
 
19
67
  end # module: SeleniumWebDriver
20
68
  end # module: Platforms
21
- end # module: Symbiont
69
+ end # module: Symbiont
70
+
71
+ Dir["#{File.dirname(__FILE__)}/../web_objects/**/*.rb"].sort.each { |file| require file }
@@ -14,8 +14,57 @@ module Symbiont
14
14
  @browser.goto(url)
15
15
  end
16
16
 
17
+ # Platform method to return a link object.
18
+ # Link objects are of type: Symbiont::WebObjects::Link
19
+ # @see Symbiont::Generators#link
20
+ def get_link_for(locator)
21
+ web_object = @browser.instance_eval "link(locator)"
22
+ WebObjects::Link.new()
23
+ end
24
+
25
+ # Platform method to click a link object.
26
+ # @see Symbiont::Generators#link
27
+ def click_link_for(locator)
28
+ @browser.instance_eval "link(locator).click"
29
+ end
30
+
31
+ # Platform method to return a button object.
32
+ # Button objects are of type: Symbiont::WebObjects::Button
33
+ # @see Symbiont::Generators#button
34
+ def get_button_for(locator)
35
+ web_object = @browser.instance_eval "button(locator)"
36
+ WebObjects::Button.new()
37
+ end
38
+
39
+ # Platform method to click a button object.
40
+ # @see Symbiont::Generators#button
41
+ def click_button_for(locator)
42
+ @browser.instance_eval "button(locator).click"
43
+ end
44
+
45
+ # Platform method to return a text field object.
46
+ # Text field objects are of type: Symbiont::WebObjects::TextField
47
+ # @see Symbiont::Generators#text_field
48
+ def get_text_field_for(locator)
49
+ @browser.instance_eval "text_field(locator)"
50
+ WebObjects::TextField.new()
51
+ end
52
+
53
+ # Platform method to retrieve text from a text field object.
54
+ # @see Symbiont::Generators#text_field
55
+ def get_text_field_value_for(locator)
56
+ @browser.instance_eval "text_field(locator).value"
57
+ end
58
+
59
+ # Platform method to enter text into a text field object.
60
+ # @see Symbiont::Generators#text_field
61
+ def set_text_field_value_for(locator, value)
62
+ @browser.instance_eval "text_field(locator).set(value)"
63
+ end
17
64
  end # class: PlatformObject
18
65
 
19
66
  end # module: WatirWebDriver
20
67
  end # module: Platforms
21
- end # module: Symbiont
68
+ end # module: Symbiont
69
+
70
+ Dir["#{File.dirname(__FILE__)}/../web_objects/**/*.rb"].sort.each { |file| require file }
@@ -1,3 +1,3 @@
1
- module Symbiont
2
- VERSION = "0.0.1"
3
- end
1
+ module Symbiont
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,9 @@
1
+ module Symbiont
2
+ module WebObjects
3
+
4
+ class WebObject
5
+
6
+ end # class: WebObject
7
+
8
+ end # module: WebObjects
9
+ end # module: Symbiont
@@ -0,0 +1,9 @@
1
+ module Symbiont
2
+ module WebObjects
3
+
4
+ class Button < WebObject
5
+
6
+ end # class: Button
7
+
8
+ end # module: WebObjects
9
+ end # module: Symbiont
@@ -0,0 +1,9 @@
1
+ module Symbiont
2
+ module WebObjects
3
+
4
+ class Link < WebObject
5
+
6
+ end # class: Link
7
+
8
+ end # module: WebObjects
9
+ end # module: Symbiont
@@ -0,0 +1,9 @@
1
+ module Symbiont
2
+ module WebObjects
3
+
4
+ class TextField < WebObject
5
+
6
+ end # class: TextField
7
+
8
+ end # module: WebObjects
9
+ end # module: Symbiont
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,11 @@ class DefinitionTest
15
15
  include Symbiont
16
16
 
17
17
  url_is "http://localhost:4567"
18
+ begin_at "http://localhost:4567"
19
+
20
+ link :reset_password, id: "resetPassword"
21
+ button :submit, id: "btnSubmit"
22
+ text_field :login_name, id: "loginName"
18
23
  end
19
24
 
20
25
  def mock_browser_for_watir
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont::Generators do
4
+ let(:watir_browser) { mock_browser_for_watir }
5
+ let(:selenium_browser) { mock_browser_for_selenium }
6
+ let(:watir_definition) { DefinitionTest.new(watir_browser) }
7
+ let(:selenium_definition) { DefinitionTest.new(selenium_browser) }
8
+
9
+ describe "button web objects" do
10
+ context "when declared in a definition" do
11
+ it "should generate methods for referencing the button" do
12
+ watir_definition.should respond_to(:submit_object)
13
+ watir_definition.should respond_to(:submit_button)
14
+
15
+ selenium_definition.should respond_to(:submit_object)
16
+ selenium_definition.should respond_to(:submit_button)
17
+ end
18
+ end
19
+
20
+ context "used by the watir platform" do
21
+ it "should locate the button" do
22
+ watir_browser.should_receive(:button).and_return(watir_browser)
23
+ web_object = watir_definition.submit_object
24
+ web_object.should_not be_nil
25
+ web_object.should be_instance_of Symbiont::WebObjects::Button
26
+ end
27
+
28
+ it "should click the button" do
29
+ watir_browser.should_receive(:button).and_return(watir_browser)
30
+ watir_browser.should_receive(:click)
31
+ watir_definition.submit
32
+ end
33
+ end
34
+
35
+ context "used by the selenium platform" do
36
+ it "should locate the button" do
37
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
38
+ web_object = selenium_definition.submit_object
39
+ web_object.should_not be_nil
40
+ web_object.should be_instance_of Symbiont::WebObjects::Button
41
+ end
42
+
43
+ it "should click the button" do
44
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
45
+ selenium_browser.should_receive(:click)
46
+ selenium_definition.submit
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont::Generators do
4
+ let(:watir_browser) { mock_browser_for_watir }
5
+ let(:selenium_browser) { mock_browser_for_selenium }
6
+ let(:watir_definition) { DefinitionTest.new(watir_browser) }
7
+ let(:selenium_definition) { DefinitionTest.new(selenium_browser) }
8
+
9
+ describe "link web objects" do
10
+ context "when declared in a definition" do
11
+ it "should generate methods for referencing the link" do
12
+ watir_definition.should respond_to(:reset_password_object)
13
+ watir_definition.should respond_to(:reset_password_link)
14
+
15
+ selenium_definition.should respond_to(:reset_password_object)
16
+ selenium_definition.should respond_to(:reset_password_link)
17
+ end
18
+ end
19
+
20
+ context "when used by the watir platform" do
21
+ it "should locate the link" do
22
+ watir_browser.should_receive(:link).and_return(watir_browser)
23
+ web_object = watir_definition.reset_password_object
24
+ web_object.should_not be_nil
25
+ web_object.should be_instance_of Symbiont::WebObjects::Link
26
+ end
27
+
28
+ it "should click the link" do
29
+ watir_browser.stub_chain(:link, :click)
30
+ watir_definition.reset_password
31
+ end
32
+ end
33
+
34
+ context "when used by the selenium platform" do
35
+ it "should locate the link" do
36
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
37
+ web_object = selenium_definition.reset_password_object
38
+ web_object.should_not be_nil
39
+ web_object.should be_instance_of Symbiont::WebObjects::Link
40
+ end
41
+
42
+ it "should click the link" do
43
+ selenium_browser.stub_chain(:find_element, :click)
44
+ selenium_definition.reset_password
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont::Generators do
4
+ let(:watir_browser) { mock_browser_for_watir }
5
+ let(:selenium_browser) { mock_browser_for_selenium }
6
+ let(:watir_definition) { DefinitionTest.new(watir_browser) }
7
+ let(:selenium_definition) { DefinitionTest.new(selenium_browser) }
8
+
9
+ describe "text field web objects" do
10
+ context "when declared in a definition" do
11
+ it "should generate methods for referencing the text field" do
12
+ watir_definition.should respond_to(:login_name_text_field)
13
+ watir_definition.should respond_to(:login_name_object)
14
+
15
+ selenium_definition.should respond_to(:login_name_text_field)
16
+ selenium_definition.should respond_to(:login_name_object)
17
+ end
18
+ end
19
+
20
+ context "when used by the watir platform" do
21
+ it "should locate the text field" do
22
+ watir_browser.should_receive(:text_field).and_return(watir_browser)
23
+ web_object = watir_definition.login_name_object
24
+ web_object.should_not be_nil
25
+ web_object.should be_instance_of Symbiont::WebObjects::TextField
26
+ end
27
+
28
+ it "should retrieve text from the text field" do
29
+ watir_browser.should_receive(:text_field).and_return(watir_browser)
30
+ watir_browser.should_receive(:value).and_return("testing")
31
+ watir_definition.login_name.should == "testing"
32
+ end
33
+
34
+ it "should enter text into a text field" do
35
+ watir_browser.should_receive(:text_field).and_return(watir_browser)
36
+ watir_browser.should_receive(:set).with("testing")
37
+ watir_definition.login_name = "testing"
38
+ end
39
+ end
40
+
41
+ context "when used by the selenium platform" do
42
+ it "should locate the text field" do
43
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
44
+ web_object = selenium_definition.login_name_object
45
+ web_object.should_not be_nil
46
+ web_object.should be_instance_of Symbiont::WebObjects::TextField
47
+ end
48
+
49
+ it "should retrieve text from the text field" do
50
+ selenium_browser.should_receive(:find_element).and_return(selenium_browser)
51
+ selenium_browser.should_receive(:attribute).with('value').and_return("testing")
52
+ selenium_definition.login_name.should == "testing"
53
+ end
54
+
55
+ it "should enter text into a text field" do
56
+ selenium_browser.should_receive(:find_element).twice.and_return(selenium_browser)
57
+ selenium_browser.should_receive(:clear)
58
+ selenium_browser.should_receive(:send_keys).with("testing")
59
+ selenium_definition.login_name = "testing"
60
+ end
61
+ end
62
+ end
63
+ end
@@ -12,6 +12,11 @@ describe Symbiont::Generators do
12
12
  watir_browser.should_receive(:goto)
13
13
  watir_definition.view
14
14
  end
15
+
16
+ it "should navigate to the page when started" do
17
+ watir_browser.should_receive(:goto)
18
+ watir_definition.start
19
+ end
15
20
  end
16
21
  end
17
22
 
@@ -22,6 +27,12 @@ describe Symbiont::Generators do
22
27
  selenium_browser.should_receive(:to)
23
28
  selenium_definition.view
24
29
  end
30
+
31
+ it "should navigate to the page when started" do
32
+ selenium_browser.should_receive(:navigate).and_return(selenium_browser)
33
+ selenium_browser.should_receive(:to)
34
+ selenium_definition.start
35
+ end
25
36
  end
26
37
  end
27
38
 
@@ -6,10 +6,30 @@ class Login
6
6
  include Symbiont
7
7
 
8
8
  url_is "http://localhost:4567"
9
+ begin_at "http://localhost:4567"
10
+
11
+ link :test_page, id: "testPage"
12
+ button :clickme, id: "clickme_id"
13
+ text_field :book_title, id: "title"
9
14
  end
10
15
 
11
16
  @browser_selenium = Selenium::WebDriver.for(:firefox)
12
17
  selenium_test = Login.new(@browser_selenium)
13
18
  selenium_test.view
14
19
 
20
+ test_link = selenium_test.test_page_object
21
+ puts test_link
22
+ selenium_test.test_page
23
+
24
+ test_text_field = selenium_test.book_title_object
25
+ puts test_text_field
26
+
27
+ selenium_test.book_title = "Revelation Space"
28
+ book = selenium_test.book_title
29
+ puts "Book title is '#{book}'."
30
+
31
+ test_button = selenium_test.clickme_object
32
+ puts test_button
33
+ selenium_test.clickme
34
+
15
35
  @browser_selenium.close
@@ -6,10 +6,30 @@ class Login
6
6
  include Symbiont
7
7
 
8
8
  url_is "http://localhost:4567"
9
+ begin_at "http://localhost:4567"
10
+
11
+ link :test_page, id: "testPage"
12
+ button :clickme, id: "clickme_id"
13
+ text_field :book_title, id: "title"
9
14
  end
10
15
 
11
16
  @browser_watir = Watir::Browser.new(:firefox)
12
17
  watir_test = Login.new(@browser_watir)
13
18
  watir_test.view
14
19
 
15
- @browser_watir.close
20
+ test_link = watir_test.test_page_object
21
+ puts test_link
22
+ watir_test.test_page
23
+
24
+ test_text_field = watir_test.book_title_object
25
+ puts test_text_field
26
+
27
+ watir_test.book_title = "Revelation Space"
28
+ book = watir_test.book_title
29
+ puts "Book title is '#{book}'."
30
+
31
+ test_button = watir_test.clickme_object
32
+ puts test_button
33
+ watir_test.clickme
34
+
35
+ @browser_watir.close
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbiont
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-03-02 00:00:00.000000000Z
12
+ date: 2012-03-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &21048780 !ruby/object:Gem::Requirement
16
+ requirement: &27142536 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *21048780
24
+ version_requirements: *27142536
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simplecov
27
- requirement: &21048504 !ruby/object:Gem::Requirement
27
+ requirement: &27142260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.6.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *21048504
35
+ version_requirements: *27142260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: watir-webdriver
38
- requirement: &21048228 !ruby/object:Gem::Requirement
38
+ requirement: &27141972 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.5.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *21048228
46
+ version_requirements: *27141972
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: selenium-webdriver
49
- requirement: &28582476 !ruby/object:Gem::Requirement
49
+ requirement: &27141684 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 2.20.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *28582476
57
+ version_requirements: *27141684
58
58
  description: An endosymbiotic facultative library for web application testing.
59
59
  email:
60
60
  - jeffnyman@gmail.com
@@ -76,7 +76,14 @@ files:
76
76
  - lib/symbiont/platform_watir/platform_object.rb
77
77
  - lib/symbiont/platforms.rb
78
78
  - lib/symbiont/version.rb
79
+ - lib/symbiont/web_objects/_common.rb
80
+ - lib/symbiont/web_objects/button.rb
81
+ - lib/symbiont/web_objects/link.rb
82
+ - lib/symbiont/web_objects/text_field.rb
79
83
  - spec/spec_helper.rb
84
+ - spec/symbiont/generators/button_generators_spec.rb
85
+ - spec/symbiont/generators/link_generators_spec.rb
86
+ - spec/symbiont/generators/text_field_generators_spec.rb
80
87
  - spec/symbiont/generators_spec.rb
81
88
  - spec/symbiont/platform_object_spec.rb
82
89
  - spec/symbiont/symbiont_spec.rb