Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cheezy/page-object
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezy committed Jan 7, 2016
2 parents ffd71d5 + bf6a69e commit c49e2ae
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 1 deletion.
13 changes: 13 additions & 0 deletions features/element.feature
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,16 @@ Feature: Elements
Scenario: Element size
When I retrieve a link element
Then I should be able to know its size

Scenario: Getting the height of an element
When I retrieve a link element
Then the element height is not 0

Scenario: Getting the width of an element
When I retrieve a link element
Then the element width is not 0

Scenario: Getting the centre of an element
When I retrieve a button element
Then the element centre should be greater than element y position
And the element centre should be greater than element x position
18 changes: 18 additions & 0 deletions features/step_definitions/element_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,21 @@ class DoubleClickPage
expect(@element.size.width).to be > 0
expect(@element.size.height).to be > 0
end

Then(/the element height is not 0/) do
(@element.height.is_a? Integer).should ==true
@element.height.should > 0
end

Then(/the element width is not 0/) do
(@element.width.is_a? Integer).should ==true
@element.width.should > 0
end

Then(/the element centre should be greater than element y position/) do
@element.centre['y'].should > @element.location.y
end

Then(/the element centre should be greater than element x position/) do
@element.centre['x'].should > @element.location.x
end
23 changes: 23 additions & 0 deletions lib/page-object/platforms/selenium_webdriver/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,29 @@ def size
element.size
end

#
# Get height of element
#
def height
element.size['height']
end

#
# Get width of element
#
def width
element.size['width']
end

#
# Get centre coordinates of element
#
def centre
location = element.location
size = element.size
{'y' => (location['y'] + (size['height']/2)), 'x' => (location['x'] + (size['width']/2))}
end

private

def bridge
Expand Down
32 changes: 31 additions & 1 deletion lib/page-object/platforms/watir_webdriver/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ def focus
def select_text(text)
element.select_text text
end


#
# Right click on an element
#
def right_click
element.right_click
end

#
# Waits until the element is present
#
Expand Down Expand Up @@ -257,6 +264,29 @@ def location
def size
element.wd.size
end

#
# Get height of element
#
def height
element.wd.size['height']
end

#
# Get width of element
#
def width
element.wd.size['width']
end

#
# Get centre coordinates of element
#
def centre
location = element.wd.location
size = element.wd.size
{'y' => (location['y'] + (size['height']/2)), 'x' => (location['x'] + (size['width']/2))}
end
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/page-object/elements/selenium_element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,35 @@
expect(@selenium_driver).to receive(:size)
@selenium_element.size
end

it "should have a height" do
expect(@selenium_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(@selenium_element.height).to eql 20
end

it "should have a width" do
expect(@selenium_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(@selenium_element.width).to eql 30
end

it "should have a centre" do
expect(@selenium_driver).to receive(:location).and_return({'y' => 80, 'x' => 40})
expect(@selenium_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(@selenium_element.centre).to include(
'y' => 90,
'x' => 55
)
end

it "should have a centre greater than y position" do
expect(@selenium_driver).to receive(:location).and_return({'y' => 80, 'x' => 40}).twice
expect(@selenium_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(@selenium_element.centre['y']).to be > @selenium_element.location['y']
end

it "should have a centre greater than x position" do
expect(@selenium_driver).to receive(:location).and_return({'y' => 80, 'x' => 40}).twice
expect(@selenium_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(@selenium_element.centre['x']).to be > @selenium_element.location['x']
end
end
36 changes: 36 additions & 0 deletions spec/page-object/elements/watir_element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,40 @@
expect(watir_driver).to receive(:size)
watir_element.size
end

it "should have a height" do
allow(watir_driver).to receive(:wd).and_return(watir_driver)
expect(watir_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(watir_element.height).to eql 20
end

it "should have a width" do
allow(watir_driver).to receive(:wd).and_return(watir_driver)
expect(watir_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(watir_element.width).to eql 30
end

it "should have a centre" do
allow(watir_driver).to receive(:wd).and_return(watir_driver)
expect(watir_driver).to receive(:location).and_return({'y' => 80, 'x' => 40})
expect(watir_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(watir_element.centre).to include(
'y' => 90,
'x' => 55
)
end

it "should have a centre greater than y position" do
allow(watir_driver).to receive(:wd).and_return(watir_driver)
expect(watir_driver).to receive(:location).and_return({'y' => 80, 'x' => 40}).twice
expect(watir_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(watir_element.centre['y']).to be > watir_element.location['y']
end

it "should have a centre greater than x position" do
allow(watir_driver).to receive(:wd).and_return(watir_driver)
expect(watir_driver).to receive(:location).and_return({'y' => 80, 'x' => 40}).twice
expect(watir_driver).to receive(:size).and_return({'width' => 30, 'height' => 20})
expect(watir_element.centre['x']).to be > watir_element.location['x']
end
end

0 comments on commit c49e2ae

Please sign in to comment.