Skip to content

Commit

Permalink
Merge pull request cheezy#250 from sedx/add_bold_tag
Browse files Browse the repository at this point in the history
Add support bold tag
cheezy committed Dec 8, 2014
2 parents 0d65186 + aa33d56 commit 611bd0e
Showing 18 changed files with 274 additions and 10 deletions.
21 changes: 21 additions & 0 deletions features/bold.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Bold

Background:
Given I am on the static elements page

Scenario: Getting the text of headings
When I get the bold text for the "b" element
Then I should see "some text in bold" in bold

Scenario Outline: Locating b on the Page
When I search bold text for the b by "<search_by>"
Then I should see "some text in bold" in bold

Scenarios:
| search_by |
| id |
| class |
| name |
| xpath |
| index |
| css |
2 changes: 1 addition & 1 deletion features/html/multi_elements.html
Original file line number Diff line number Diff line change
@@ -139,6 +139,6 @@ <h6 class="h6">H6 Three</h6>
<input type="file" class="file_field_class" title="File Field 1" />
<input type="file" class="file_field_class" title="File Field 2" />
<input type="file" class="file_field_class" title="File Field 3" />

In bold <b>One B</b> and <b>Two B</b> for example text
</body>
</html>
3 changes: 1 addition & 2 deletions features/html/static_elements.html
Original file line number Diff line number Diff line change
@@ -176,7 +176,6 @@ <h3 id="h3_id" class="h3_class" name="h3_name">h3's are cool</h3>
<h4 id="h4_id" class="h4_class" name="h4_name">h4's are cool</h4>
<h5 id="h5_id" class="h5_class" name="h5_name">h5's are cool</h5>
<h6 id="h6_id" class="h6_class" name="h6_name">h6's are cool</h6>

<a href="success.html" target="_blank">New Window</a>
<a href="failure.html" target="_blank">Another New Window</a>

@@ -199,7 +198,7 @@ <h6 id="h6_id" class="h6_class" name="h6_name">h6's are cool</h6>
<figure id='figure_id'>
<img src="images/img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">
</figure>

This text have <b id="b_id" class="b_class" name="b_name">some text in bold</b>
</body>
</html>

6 changes: 6 additions & 0 deletions features/multi_elements.feature
Original file line number Diff line number Diff line change
@@ -484,3 +484,9 @@ Feature: Multi Elements
And the text for label 1 should be "Label 1"
And the text for label 2 should be "Label 2"
And the text for label 3 should be "Label 3"

Scenario: Selecting bs using an identifier
When I select the bs
Then I should have 2 bs
And the text for b 1 should be "One B"
And the text for b 2 should be "Two B"
12 changes: 12 additions & 0 deletions features/step_definitions/bold_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
When /^I get the bold text for the "([^\"]*)" element$/ do |el|
@b = @page.send "#{el}_id"
end

Then /^I should see "([^\"]*)" in bold$/ do |text|
@b.should == text
end

When /^I search bold text for the (\w+) by "([^"]*)"$/ do |text_decorator, type|
@b = @page.send "#{text_decorator}_#{type}"
end

13 changes: 13 additions & 0 deletions features/step_definitions/multi_elements_steps.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ class MultiElementsPage
labels(:the_labels, :class => 'label')
file_fields(:the_file_fields, :class => 'file_field_class')
elements(:generic_label, :label, :class => 'label')
b(:bs)
end


@@ -526,3 +527,15 @@ class MultiElementsPage
When(/^I select the multiple elements with a tag label$/) do
@elements = @page.generic_label_elements
end

When /^I select the bs"$/ do
@elements = @page.b_elements
end

Then /^I should have (\d+) bs$/ do |num_bs|
@elements.size.should == num_bs.to_i
end

Then /^the text for b (\d+) should be "([^\"]*)"$/ do |b_num, text|
@elements[b_num.to_i - 1].text.should == text
end
9 changes: 9 additions & 0 deletions features/support/page.rb
Original file line number Diff line number Diff line change
@@ -360,5 +360,14 @@ class Page
figure(:figure_id, :id => 'figure_id')

svg(:svg_id, :id => 'the_svg')

b(:b_id, :id => 'b_id')
b(:b_class, :class => 'b_class')
b(:b_css, :css => '.b_class')
b(:b_name, :name => 'b_name')
b(:b_index, :index => 0)
b(:b_xpath, :xpath => '//b')
b(:b_class_index, :class => 'b_class', :index => 0)
b(:b_name_index, :name => 'b_name', :index => 0)
end

27 changes: 27 additions & 0 deletions lib/page-object/accessors.rb
Original file line number Diff line number Diff line change
@@ -1120,6 +1120,33 @@ def video(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'video_for', &block)
end

#
# adds three methods - one to retrieve the text of a b element, another to
# retrieve a b element, and another to check for it's existence.
#
# @example
# b(:bold, :id => 'title')
# # will generate 'bold', 'bold_element', and 'bold?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a b. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def b(name, identifier={:index => 0}, &block)
standard_methods(name, identifier,'b_for', &block)
define_method(name) do
return platform.b_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end

#
# adds two methods - one to retrieve a svg, and another to check
# the svg's existence.
1 change: 1 addition & 0 deletions lib/page-object/elements.rb
Original file line number Diff line number Diff line change
@@ -55,5 +55,6 @@ def element_class_for(tag_name, type=nil)
require 'page-object/elements/media'
require 'page-object/elements/audio'
require 'page-object/elements/video'
require 'page-object/elements/bold'


11 changes: 11 additions & 0 deletions lib/page-object/elements/bold.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module PageObject
module Elements
class Bold < Element

end

::PageObject::Elements.tag_to_class[:b] = ::PageObject::Elements::Bold


end
end
2 changes: 1 addition & 1 deletion lib/page-object/elements/element.rb
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ def method_missing(*args, &block)
protected

def self.should_build_watir_xpath identifier
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video'].include? identifier[:tag_name] and identifier[:name]
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video', 'b'].include? identifier[:tag_name] and identifier[:name]
end

def self.build_xpath_for identifier
1 change: 1 addition & 0 deletions lib/page-object/locator_generator.rb
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ module LocatorGenerator
:canvas,
:audio,
:video,
:b,
:svg]

def self.generate_locators(target)
26 changes: 26 additions & 0 deletions lib/page-object/platforms/selenium_webdriver/page_object.rb
Original file line number Diff line number Diff line change
@@ -1002,6 +1002,32 @@ def svgs_for(identifier)
find_selenium_elements(identifier, Elements::Element, 'svg')
end


#
# platform method to retrieve the text from a b
# See PageObject::Accessors#b
#
def b_text_for(identifier)
process_selenium_call(identifier, Elements::Bold, 'b') do |how, what|
@browser.find_element(how, what).text
end
end

#
# platform method to retrieve the h1 element
# See PageObject::Accessors#b
#
def b_for(identifier)
find_selenium_element(identifier, Elements::Bold, 'b')
end

#
# platform method to retrieve all b elements
#
def bs_for(identifier)
find_selenium_elements(identifier, Elements::Bold, 'b')
end

private

def process_selenium_call(identifier, type, tag, other=nil)
23 changes: 23 additions & 0 deletions lib/page-object/platforms/watir_webdriver/page_object.rb
Original file line number Diff line number Diff line change
@@ -930,6 +930,29 @@ def svg_for(identifier)
def svgs_for(identifier)
find_watir_elements("element(identifier)", Elements::Element, identifier)
end

#
# platform method to retrieve the text for a b
# See PageObject::Accessors#b
#
def b_text_for(identifier)
process_watir_call("b(identifier).text", Elements::Bold, identifier, nil, 'b')
end

#
# platform method to retrieve the b element
# See PageObject::Accessors#h1
#
def b_for(identifier)
find_watir_element("b(identifier)", Elements::Bold, identifier, 'b')
end

#
# platform method to retrieve an array of bs
#
def bs_for(identifier)
find_watir_elements("bs(identifier)", Elements::Bold, identifier, 'b')
end

private

36 changes: 36 additions & 0 deletions spec/page-object/element_locators_spec.rb
Original file line number Diff line number Diff line change
@@ -683,6 +683,29 @@ class ElementLocatorsTestPageObject
watir_browser.should_receive(:audio).with(:index => 0).and_return(watir_browser)
watir_page_object.element(:audio)
end

it "should find a b element" do
watir_browser.should_receive(:b).with(:id => 'blah').and_return(watir_browser)
element = watir_page_object.b_element(:id => 'blah')
element.should be_instance_of PageObject::Elements::Bold
end

it "should find a b element using a default identifier" do
watir_browser.should_receive(:b).with(:index => 0).and_return(watir_browser)
watir_page_object.b_element
end

it "should find all b elements" do
watir_browser.should_receive(:bs).with(:id => 'blah').and_return([watir_browser])
elements = watir_page_object.b_elements(:id => 'blah')
elements[0].should be_instance_of PageObject::Elements::Bold
end

it "should find all b elements using no parameters" do
watir_browser.should_receive(:bs).with({}).and_return([watir_browser])
watir_page_object.b_elements
end

end

context "when using Selenium" do
@@ -1061,5 +1084,18 @@ class ElementLocatorsTestPageObject
selenium_browser.should_receive(:find_elements).with(:tag_name, 'audio').and_return([selenium_browser])
selenium_page_object.audio_elements
end
it "should find a b element" do
selenium_browser.should_receive(:find_element).with(:id,'blah').and_return(selenium_browser)
element = selenium_page_object.b_element(:id => 'blah')
element.should be_instance_of PageObject::Elements::Bold
end


it "should find all b elements" do
selenium_browser.should_receive(:find_elements).with(:id, 'blah').and_return([selenium_browser])
elements = selenium_page_object.b_elements(:id => 'blah')
elements[0].should be_instance_of PageObject::Elements::Bold
end

end
end
29 changes: 29 additions & 0 deletions spec/page-object/elements/bold_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'
require 'page-object/elements'

describe PageObject::Elements::Bold do
let(:bold) { PageObject::Elements::Bold }

describe "when mapping how to find an element" do
it "should map watir types to same" do
[:class, :id, :index, :name, :xpath].each do |t|
identifier = bold.watir_identifier_for t => 'value'
identifier.keys.first.should == t
end
end

it "should map selenium types to same" do
[:class, :id, :index, :name, :xpath].each do |t|
key, value = bold.selenium_identifier_for t => 'value'
key.should == t
end
end
end

describe "interface" do

it "should register with tag :b" do
::PageObject::Elements.element_class_for(:b).should == ::PageObject::Elements::Bold
end
end
end
20 changes: 20 additions & 0 deletions spec/page-object/selenium_accessors_spec.rb
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ class SeleniumAccessorsTestPageObject
canvas(:my_canvas, :id => 'canvas')
audio(:acdc, :id => 'audio_id')
video(:movie, :id => 'movie_id')
b(:bold, :id=>'bold')
end

class SeleniumBlockPageObject
@@ -129,6 +130,10 @@ class SeleniumBlockPageObject
video :movie do |element|
'video'
end

b :bold do |element|
'b'
end
end

describe PageObject::Accessors do
@@ -586,4 +591,19 @@ class SeleniumBlockPageObject
end
end
end

describe "b accessors" do
it "should retrieve the text from the b" do
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
selenium_browser.should_receive(:text).and_return("value")
selenium_page_object.bold.should == "value"
end

it "should retrieve the element from the page" do
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
element = selenium_page_object.bold_element
element.should be_instance_of PageObject::Elements::Bold
end
end

end
42 changes: 36 additions & 6 deletions spec/page-object/watir_accessors_spec.rb
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ class WatirAccessorsTestPageObject
canvas(:my_canvas, :id => 'canvas_id')
audio(:acdc, :id => 'audio_id')
video(:movie, :id => 'video_id')
b(:bold,:id=>'bold')
end

class WatirBlockPageObject
@@ -129,6 +130,9 @@ class WatirBlockPageObject
video :movie do |element|
"video"
end
b :bold do |element|
"b"
end
end

describe PageObject::Accessors do
@@ -158,7 +162,7 @@ def initialize(b, v, url)
SymbolPageUrl.new(watir_browser, true, 'custom')

watir_browser.should_receive(:goto).with('different')
SymbolPageUrl.new(watir_browser, true, 'different')
SymbolPageUrl.new(watir_browser, true, 'different')
end

it "should not navigate to a page when not requested" do
@@ -537,7 +541,7 @@ def mock_driver_for(tag)
element = watir_page_object.state_element
element.should be_instance_of PageObject::Elements::SelectList
end

it "should return list of selection options" do
option1 = double('option')
option2 = double('option')
@@ -547,11 +551,11 @@ def mock_driver_for(tag)
select_element = double("select")
select_element.should_receive(:options).twice.and_return([option1, option2])
watir_page_object.should_receive(:state_element).and_return(select_element)

watir_page_object.state_options.should == ["CA","OH"]
end


end


@@ -1080,7 +1084,7 @@ def mock_driver_for(tag)
end
end
end

describe "audio accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
@@ -1104,4 +1108,30 @@ def mock_driver_for(tag)
end
end
end

describe "b accessors" do
context "when called on a page object" do
it "should generate accessor methods" do
watir_page_object.should respond_to(:bold)
watir_page_object.should respond_to(:bold_element)
end

it "should call a block on the element method when present" do
block_page_object.bold_element.should == "b"
end
end

it "should retrieve the text from the b" do
watir_browser.should_receive(:b).and_return(watir_browser)
watir_browser.should_receive(:text).and_return("value")
watir_page_object.bold.should == "value"
end

it "should retrieve the element from the page" do
watir_browser.should_receive(:b).and_return(watir_browser)
element = watir_page_object.bold_element
element.should be_instance_of PageObject::Elements::Bold
end
end

end

0 comments on commit 611bd0e

Please sign in to comment.