symbiont 0.1.4 → 0.1.5

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.1.5 / 2012-09-12
5
+ --------------------------
6
+
7
+ This release offers just a few enhancements to using select lists and tables, particularly in terms of iterating through both and getting information.
8
+
9
+
4
10
  Version 0.1.4 / 2012-08-06
5
11
  --------------------------
6
12
 
data/app/app.rb CHANGED
@@ -42,6 +42,21 @@ module Symbiont
42
42
  erb :test_events
43
43
  end
44
44
 
45
+ get '/test_login' do
46
+ @title = "Simple Login Demonstration"
47
+ erb :test_login
48
+ end
49
+
50
+ get '/test_login_error' do
51
+ @title = "Test Login - Error Page"
52
+ erb :test_login_error
53
+ end
54
+
55
+ post '/test_login_success' do
56
+ @title = "Test Login - Success Page"
57
+ erb :test_login_success
58
+ end
59
+
45
60
  get '/test_database' do
46
61
  @title = "Sample Database Application"
47
62
  erb :test_database
@@ -164,4 +179,4 @@ module Symbiont
164
179
  end # class: TestApp
165
180
  end # module: Symbiont
166
181
 
167
- Symbiont::TestApp.run!
182
+ Symbiont::TestApp.run!
data/app/views/index.erb CHANGED
@@ -4,4 +4,5 @@
4
4
  <li><a id="test_page" href="test_page">Simple Object Page</a></li>
5
5
  <li><a id="test_events" href="test_events">Simple Events Page</a></li>
6
6
  <li><a id="test_database" href="test_database">Simple Database Application</a></li>
7
+ <li><a id="test_login" href="test_login">Simple Login Demonstration</a></li>
7
8
  </ul>
@@ -1,4 +1,4 @@
1
- <h1>Sample Database Application</h1>
1
+ <h1>Simple Database Application</h1>
2
2
 
3
3
  <iframe style="float: left;" id="loginSection" name="loginSection" src="login_page" width="500" height="300">
4
4
  </iframe>
@@ -0,0 +1,53 @@
1
+ <style>
2
+ body {
3
+ font-family: sans-serif;
4
+ color: black;
5
+ background: #DDDDDD;
6
+ text-align: center;
7
+ }
8
+ #login {
9
+ width: 30em;
10
+ height: 15em;
11
+ margin: 1em auto;
12
+ background: white;
13
+ border: 1px solid gray;
14
+ padding: 10px 30px;
15
+ text-align: left;
16
+ }
17
+ </style>
18
+
19
+ <h1>Simple Login Demonstration</h1>
20
+
21
+ <div id='login'>
22
+ <h2>Login Page</h2>
23
+ <p>Enter your user name and password and click the login button.</p>
24
+ <form name='login_form' action="/test_login_success" method="post" onsubmit="return login()">
25
+ <table>
26
+ <tr>
27
+ <td>User Name:</td>
28
+ <td><input id="username" name="username_field" size="30" type="text" /></td>
29
+ </tr>
30
+ <tr>
31
+ <td>Password:</td>
32
+ <td><input id="password" name="password_field" size="30" type="password" /></td>
33
+ </tr>
34
+ <tr>
35
+ <td>&nbsp;</td>
36
+ <td><input name="login_button" type="submit" value="LOGIN" /></td>
37
+ </tr>
38
+ </table>
39
+ </form>
40
+ </div>
41
+
42
+ <script type="text/javascript">
43
+ function login() {
44
+ if (document.login_form.username_field.value == 'demo' &&
45
+ document.login_form.password_field.value == 'testing') {
46
+ return true
47
+ }
48
+ else {
49
+ window.location="test_login_error"
50
+ return false
51
+ }
52
+ }
53
+ </script>
@@ -0,0 +1,22 @@
1
+ <style>
2
+ body {
3
+ font-family: sans-serif;
4
+ color: black;
5
+ background: #DDDDDD;
6
+ text-align: center;
7
+ }
8
+ #login {
9
+ width: 30em;
10
+ height: 15em;
11
+ margin: 1em auto;
12
+ background: white;
13
+ border: 1px solid gray;
14
+ padding: 10px 30px;
15
+ text-align: left;
16
+ }
17
+ </style>
18
+
19
+ <div id='login'>
20
+ <h1>Error Page</h1>
21
+ <p>Login failed. Invalid user name and/or password.</p>
22
+ </div>
@@ -0,0 +1,22 @@
1
+ <style>
2
+ body {
3
+ font-family: sans-serif;
4
+ color: black;
5
+ background: #DDDDDD;
6
+ text-align: center;
7
+ }
8
+ #login {
9
+ width: 30em;
10
+ height: 15em;
11
+ margin: 1em auto;
12
+ background: white;
13
+ border: 1px solid gray;
14
+ padding: 10px 30px;
15
+ text-align: left;
16
+ }
17
+ </style>
18
+
19
+ <div id='login'>
20
+ <h1>Welcome Page</h1>
21
+ <p>Login succeeded. Now you can <a href="test_login">logout</a>.</p>
22
+ </div>
data/cucumber.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  <% browser = "BROWSER=firefox" %>
2
2
  <% std_opts = "--tags ~@wip --color --format pretty --no-source" %>
3
+ <% rpt_opts = "--format html --out output/specs-report.html" %>
3
4
 
4
5
  default: <%= browser %> <%= std_opts %> -r specs specs
6
+ report: <%= browser %> <%= std_opts %> <%= rpt_opts %> -r specs specs
@@ -1,3 +1,3 @@
1
1
  module Symbiont
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -35,6 +35,10 @@ module Symbiont
35
35
  @web_object.click
36
36
  end
37
37
 
38
+ def clear
39
+ @web_object.clear
40
+ end
41
+
38
42
  def attribute(name)
39
43
  @web_object.attribute_value(name)
40
44
  end
@@ -0,0 +1,10 @@
1
+ module Symbiont
2
+ module WebObjects
3
+ class Option < WebObject
4
+
5
+ end # class: Option
6
+
7
+ ::Symbiont::WebObjects.class_for_tag[:option] = ::Symbiont::WebObjects::Option
8
+
9
+ end # module: WebObjects
10
+ end # module: Symbiont
@@ -2,7 +2,69 @@ module Symbiont
2
2
  module WebObjects
3
3
 
4
4
  class SelectList < WebObject
5
+ # This method is used to return an Option object based on the index provided.
6
+ # @return [Symbiont::WebObjects::Option]
7
+ def [](idx)
8
+ Object::Symbiont::WebObjects::Option.new(options[idx])
9
+ end
5
10
 
11
+ # This method returns an array of Option objects that are contained within
12
+ # a select list object.
13
+ # @return [array of Symbiont::WebObjects::Option]
14
+ def options
15
+ web_objects = []
16
+ options = @web_object.wd.find_elements(:xpath, option_xpath)
17
+ options.each do |opt|
18
+ web_objects << Object::Symbiont::WebObjects::Option.new(opt)
19
+ end
20
+ web_objects
21
+ end
22
+
23
+ # Selects an option from the select list.
24
+ def select(value)
25
+ @web_object.select(value)
26
+ end
27
+
28
+ # Selects the option whose value attribute matches the provided string.
29
+ def select_value(value)
30
+ @web_object.select_value(value)
31
+ end
32
+
33
+ # This method returns an array of strings that contain the text of the
34
+ # currently selected options in a select list.
35
+ # @return [Array<String>]
36
+ def selected_options
37
+ @web_object.selected_options.map { |e| e.text }.compact
38
+ end
39
+
40
+ # This method returns an array of strings that contain the values of the
41
+ # currently selected options in a select list.
42
+ # @return [Array<String>]
43
+ def selected_values
44
+ @web_object.selected_options.map { |e| e.value }.compact
45
+ end
46
+
47
+ # This method returns true if any of the text or the lable of any option
48
+ # that is selected matches the provided value.
49
+ # @param [String, Regexp] value A value to check for
50
+ # @return [Boolean]
51
+ def selected?(value)
52
+ @web_object.selected? value
53
+ end
54
+
55
+ # This method checks to see if the select list has one or more options
56
+ # where the text or the label matches the provided value.
57
+ # @param [String, Regexp] value A value to check for.
58
+ # @return [Boolean]
59
+ def include?(value)
60
+ @web_object.include? value
61
+ end
62
+
63
+ protected
64
+
65
+ def option_xpath
66
+ ".//child::option"
67
+ end
6
68
  end # class: SelectList
7
69
 
8
70
  ::Symbiont::WebObjects.class_for_tag[:select] = ::Symbiont::WebObjects::SelectList
@@ -10,6 +10,7 @@ module Symbiont
10
10
  # @return [Symbiont::WebObjects::TableRow]
11
11
  def [](index)
12
12
  index = find_by_title(index) if index.kind_of?(String)
13
+ return nil unless index
13
14
  Object::Symbiont::WebObjects::TableRow.new(@web_object[index])
14
15
  end
15
16
 
@@ -10,6 +10,7 @@ module Symbiont
10
10
  # @return [Symbiont::WebObjects::TableCell]
11
11
  def [](index)
12
12
  index = find_by_title(index) if index.kind_of?(String)
13
+ return nil unless index
13
14
  Object::Symbiont::WebObjects::TableCell.new(@web_object[index])
14
15
  end
15
16
 
@@ -37,8 +38,9 @@ module Symbiont
37
38
 
38
39
  def find_by_title(column_text)
39
40
  table = @web_object.parent
41
+ table = table.parent if table.tag_name == 'tbody'
40
42
  first_row = table[0]
41
- first_row.cells.find_index {|column| column.text == column_text}
43
+ first_row.cells.find_index {|column| column.text.include? column_text}
42
44
  end
43
45
 
44
46
  end # class: TableRow
@@ -67,6 +67,11 @@ describe "Web Objects" do
67
67
  watir_definition.click
68
68
  end
69
69
 
70
+ it "should allow a clear event on a web object" do
71
+ watir_browser.should_receive(:clear)
72
+ watir_definition.clear
73
+ end
74
+
70
75
  it "should wait for a web object to be actionable" do
71
76
  watir_browser.should_receive(:wait_until_present).twice.with(5)
72
77
  watir_definition.when_actionable(5)
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbiont::WebObjects::Option do
4
+ describe "implementation" do
5
+ it "should register with an option tag" do
6
+ ::Symbiont::WebObjects.get_class_for(:option).should == ::Symbiont::WebObjects::Option
7
+ end
8
+ end
9
+ end
@@ -4,6 +4,15 @@ describe Symbiont::WebObjects::SelectList do
4
4
  describe "implementation" do
5
5
  let(:select_list_object) { double('select_list_object') }
6
6
  let(:select_list) { Symbiont::WebObjects::SelectList }
7
+ let(:select_list_actual) { Symbiont::WebObjects::SelectList.new(select_list_object) }
8
+ let(:list_opts) { [select_list_object, select_list_object] }
9
+
10
+ before(:each) do
11
+ select_list_object.stub(:find_elements).and_return(select_list_object)
12
+ select_list_object.stub(:wd).and_return(select_list_object)
13
+ select_list_object.stub(:include?)
14
+ end
15
+
7
16
  it "should reference standard usable selectors" do
8
17
  [:class, :id, :name, :index, :xpath].each do |s|
9
18
  locator = select_list.provide_locator_for s => 'value'
@@ -14,5 +23,47 @@ describe Symbiont::WebObjects::SelectList do
14
23
  it "should register with a select list tag" do
15
24
  ::Symbiont::WebObjects.get_class_for(:select).should == ::Symbiont::WebObjects::SelectList
16
25
  end
26
+
27
+ it "should return an option when indexed" do
28
+ select_list_object.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(list_opts)
29
+ select_list_actual[0].should be_instance_of Symbiont::WebObjects::Option
30
+ end
31
+
32
+ it "should return an array of options" do
33
+ select_list_object.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(list_opts)
34
+ select_list_actual.options.size.should == 2
35
+ end
36
+
37
+ it "should return an array of selected options" do
38
+ select_list_object.stub(:selected_options).and_return(list_opts)
39
+ select_list_object.stub(:text).and_return(select_list_object)
40
+ select_list_actual.selected_options.should == list_opts
41
+ end
42
+
43
+ it "should determine if an option is selected" do
44
+ select_list_object.stub(:selected?).with('testing').and_return(true)
45
+ select_list_actual.selected?('testing')
46
+ end
47
+
48
+ it "should determine if an option is available" do
49
+ select_list_object.stub(:include?).with('testing').and_return(true)
50
+ select_list_actual.include?('testing')
51
+ end
52
+
53
+ it "should get the values for any selected options" do
54
+ select_list_object.stub(:selected_options).and_return(list_opts)
55
+ select_list_object.stub(:value).and_return(select_list_object)
56
+ select_list_actual.selected_values.should == list_opts
57
+ end
58
+
59
+ it "should be able to select an item by value" do
60
+ select_list_object.should_receive(:select_value).and_return(true)
61
+ select_list_actual.select_value('testing')
62
+ end
63
+
64
+ it "should be able to select an item by option" do
65
+ select_list_object.should_receive(:select).and_return(true)
66
+ select_list_actual.select('testing')
67
+ end
17
68
  end
18
69
  end
@@ -33,6 +33,7 @@ describe Symbiont::WebObjects::TableRow do
33
33
  table_row = Symbiont::WebObjects::TableRow.new(table_row_object)
34
34
  table_row_object.should_receive(:[]).with("column_text").and_return(table_row_object)
35
35
  table_row_object.should_receive(:[]).with(0).and_return(table_row_object)
36
+ table_row_object.should_receive(:tag_name)
36
37
  table_row_object.should_receive(:parent).and_return(table_row_object)
37
38
  table_row_object.should_receive(:cells).and_return(table_row_object)
38
39
  table_row_object.should_receive(:find_index).and_return("column_text")
@@ -3,6 +3,19 @@ require 'spec_helper'
3
3
  describe Symbiont::WebObjects::Table do
4
4
  describe "implementation" do
5
5
  let(:table_object) { double('table_object') }
6
+ let(:table_row_object) { double('table_row_object') }
7
+ let(:table) { Symbiont::WebObjects::Table }
8
+
9
+ it "should reference standard usable selectors" do
10
+ [:class, :id, :name, :index, :xpath].each do |s|
11
+ locator = table.provide_locator_for s => 'value'
12
+ locator.keys.first.should == s
13
+ end
14
+ end
15
+
16
+ it "should register with a table tag" do
17
+ ::Symbiont::WebObjects.get_class_for(:table).should == ::Symbiont::WebObjects::Table
18
+ end
6
19
 
7
20
  context "on the watir platform" do
8
21
  let(:watir_table) { Symbiont::WebObjects::Table.new(table_object) }
@@ -43,10 +56,6 @@ describe Symbiont::WebObjects::Table do
43
56
  watir_table.each { |e| count += 1 }
44
57
  count.should == 2
45
58
  end
46
-
47
- it "should register with a table tag" do
48
- ::Symbiont::WebObjects.get_class_for(:table).should == ::Symbiont::WebObjects::Table
49
- end
50
59
  end
51
60
  end
52
61
  end
@@ -51,6 +51,8 @@ class SimpleObjectPage
51
51
  text_field :bookPubID, id: "bookPubID"
52
52
  text_field :fake_text_field, id: "fake_text_field"
53
53
 
54
+ select_list :subatomicParticles, id: "subatomicID"
55
+
54
56
  select_list :physicsConceptsID, id: "physicsConceptsID"
55
57
  select_list :physicsConceptsName, name: "physicsConceptsName"
56
58
  select_list :physicsConceptsClass, class: "physicsConceptsClass"
@@ -6,12 +6,24 @@ Feature: Ability to Support Select List Web Objects
6
6
  And the physics concepts select list should be visible
7
7
  And the physics concepts select list should be enabled
8
8
  And the physics concepts select list should be a select list object
9
-
9
+ And the physics concepts select list should include "Bose-Einstein Condensates"
10
+
10
11
  Scenario: Select item in select list and get current selection from it
11
12
  When "Tachyonic Antitravel" is selected from physics concepts on the object test page
12
13
  Then the physics concepts select list should have the second option selected
13
14
  And the physics concepts select list should be displaying "Tachyonic Antitravel"
14
-
15
+
16
+ Scenario: Select item in select list by value
17
+ When "option3" is selected from the physics concepts list
18
+ Then the physics concepts select list should be displaying "Bose-Einstein Condensates"
19
+ And the selected option on the physics concepts select list should have a value of "option3"
20
+
21
+ Scenario: Selecting multiple items from a list and clearing the list
22
+ When "Photon" and "Quark" are selected from the subatomic particles select list
23
+ Then the subatomic particles list should be displaying "Photon" and "Quark"
24
+ When the select list is cleared
25
+ Then the select list should have no selected options
26
+
15
27
  Scenario: Handling a non-existent select list
16
28
  When on the object test page
17
29
  Then the fake select list should not exist
@@ -3,6 +3,21 @@ When (/^"([^"]*)" is selected from physics concepts on the object test page$/) d
3
3
  @page.physicsConceptsID = text
4
4
  end
5
5
 
6
+ When (/^"(.*?)" is selected from the physics concepts list$/) do |text|
7
+ step %{on the object test page}
8
+ @page.physicsConceptsID_object.select_value(text)
9
+ end
10
+
11
+ When (/^"(.*?)" and "(.*?)" are selected from the subatomic particles select list$/) do |first, second|
12
+ step %{on the object test page}
13
+ @page.subatomicParticles_object.select(first)
14
+ @page.subatomicParticles_object.select(second)
15
+ end
16
+
17
+ When (/^the select list is cleared$/) do
18
+ @page.subatomicParticles_object.clear
19
+ end
20
+
6
21
  When (/^the physics concepts on the object test page is selected by "([^"]*)"$/) do |locator|
7
22
  option = "Tachyonic Antitravel"
8
23
  @page = SimpleObjectPage.new(@browser, true)
@@ -39,6 +54,8 @@ end
39
54
 
40
55
  Then (/^the physics concepts select list should be displaying "([^"]*)"$/) do |text|
41
56
  @page.physicsConceptsID.should == text
57
+ @page.physicsConceptsID_object.selected?(text)
58
+ @page.physicsConceptsID_object.selected?(text).should be_true
42
59
  end
43
60
 
44
61
  Then (/^the fake select list should not exist$/) do
@@ -70,3 +87,20 @@ end
70
87
  Then (/^the sith power select list should not be enabled$/) do
71
88
  @page.sithPowerID_enabled?.should == false
72
89
  end
90
+
91
+ Then (/^the physics concepts select list should include "(.*?)"$/) do |text|
92
+ @page.physicsConceptsID_object.should include text
93
+ @page.physicsConceptsID_object.include?(text)
94
+ end
95
+
96
+ Then (/^the selected option on the physics concepts select list should have a value of "(.*?)"$/) do |text|
97
+ @page.physicsConceptsID_object.selected_values[0].should == text
98
+ end
99
+
100
+ Then (/^the subatomic particles list should be displaying "(.*?)" and "(.*?)"$/) do |first, second|
101
+ @page.subatomicParticles_object.selected_options.should == [second, first]
102
+ end
103
+
104
+ Then (/^the select list should have no selected options$/) do
105
+ @page.subatomicParticles_object.selected_options.should be_empty
106
+ end
@@ -42,7 +42,8 @@ Then (/^the savings value cell for February should be "([^"]*)"$/) do |text|
42
42
  end
43
43
 
44
44
  Then (/^the data for row "([^"]*)" should be "([^"]*)", "([^"]*)", and "([^"]*)"$/) do |row, col1, col2, col3|
45
- table_row = @object[row.to_i - 1]
45
+ row = (row.to_i - 1) if row.to_i > 0
46
+ table_row = @object[row]
46
47
  table_row[0].text.should == col1
47
48
  table_row[1].text.should == col2
48
49
  table_row[2].text.should == col3
@@ -71,3 +72,11 @@ end
71
72
  Then (/^the symbol for carbon should be "([^"]*)"$/) do |text|
72
73
  @page.atomicTable_object["Carbon"]["Symbol"].text.should == text
73
74
  end
75
+
76
+ Then (/^the data for row "(.*?)" should be unavailable$/) do |row|
77
+ @object[row].should be_nil
78
+ end
79
+
80
+ Then (/^the data for column "(.*?)" and row "(.*?)" should be unavailable$/) do |column, row|
81
+ @object[row][column].should be_nil
82
+ end
data/specs/table.feature CHANGED
@@ -29,3 +29,11 @@ Feature: Ability to Support Table Web Objects
29
29
  Scenario: Get information from a table by named column and row
30
30
  When getting information from the atomic elements table
31
31
  Then the symbol for carbon should be "C"
32
+
33
+ Scenario: Get information from a table with invalid row information
34
+ When getting information from the atomic elements table
35
+ Then the data for row "testing" should be unavailable
36
+
37
+ Scenario: Get information from a table with invalid column information
38
+ When getting information from the atomic elements table
39
+ Then the data for column "QA" and row "Element" should be unavailable
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.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -130,6 +130,9 @@ files:
130
130
  - app/views/success_2.erb
131
131
  - app/views/test_database.erb
132
132
  - app/views/test_events.erb
133
+ - app/views/test_login.erb
134
+ - app/views/test_login_error.erb
135
+ - app/views/test_login_success.erb
133
136
  - app/views/test_page.erb
134
137
  - cucumber.yml
135
138
  - lib/symbiont.rb
@@ -150,6 +153,7 @@ files:
150
153
  - lib/symbiont/web_objects/checkbox.rb
151
154
  - lib/symbiont/web_objects/div.rb
152
155
  - lib/symbiont/web_objects/link.rb
156
+ - lib/symbiont/web_objects/option.rb
153
157
  - lib/symbiont/web_objects/radio.rb
154
158
  - lib/symbiont/web_objects/select_list.rb
155
159
  - lib/symbiont/web_objects/span.rb
@@ -181,6 +185,7 @@ files:
181
185
  - spec/symbiont/web_objects/checkbox_spec.rb
182
186
  - spec/symbiont/web_objects/div_spec.rb
183
187
  - spec/symbiont/web_objects/link_spec.rb
188
+ - spec/symbiont/web_objects/option_spec.rb
184
189
  - spec/symbiont/web_objects/radio_spec.rb
185
190
  - spec/symbiont/web_objects/select_list_spec.rb
186
191
  - spec/symbiont/web_objects/span_spec.rb