Skip to content

Commit

Permalink
Merge pull request giorgiosironi#388 from paulbriton/2.x
Browse files Browse the repository at this point in the history
Implemented rect command
  • Loading branch information
giorgiosironi authored Nov 27, 2016
2 parents 2bad798 + 42d4b86 commit f4b406f
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .ci/common_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

SELENIUM_HUB_URL='http://127.0.0.1:4444'
SELENIUM_JAR=/usr/share/selenium/selenium-server-standalone.jar
SELENIUM_DOWNLOAD_URL=http://selenium-release.storage.googleapis.com/2.48/selenium-server-standalone-2.48.2.jar
SELENIUM_DOWNLOAD_URL=http://selenium-release.storage.googleapis.com/3.0/selenium-server-standalone-3.0.1.jar
GECKODRIVER_DOWNLOAD_URL=https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz
GECKODRIVER_TAR=/tmp/geckodriver.tar.gz
PHP_VERSION=$(php -v)
6 changes: 6 additions & 0 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ if [ ! -f "$SELENIUM_JAR" ]; then
sudo mkdir -p $(dirname "$SELENIUM_JAR")
sudo wget -nv -O "$SELENIUM_JAR" "$SELENIUM_DOWNLOAD_URL"
fi

if [ ! -f "/usr/local/bin/geckodriver" ]; then
echo "Downloading geckodriver"
sudo wget -nv -O "$GECKODRIVER_TAR" "$GECKODRIVER_DOWNLOAD_URL"
sudo tar -xvf "$GECKODRIVER_TAR" -C "/usr/local/bin/"
fi
9 changes: 7 additions & 2 deletions .ci/vagrant_pre_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main restr
sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise-backports main restricted universe multiverse" /etc/apt/sources.list
sed -i "1ideb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main restricted universe multiverse" /etc/apt/sources.list

apt-get install python-software-properties
apt-get update

apt-get install software-properties-common -y
apt-get install python-software-properties -y

apt-add-repository ppa:ondrej/php5-5.6 -y
apt-add-repository ppa:openjdk-r/ppa -y

apt-get update

# installing xvfb, java and php
apt-get install xvfb openjdk-7-jre-headless php5-cli php5-curl php5-xdebug ncurses-term unzip xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic vim -y --no-install-recommends
apt-get install xvfb openjdk-8-jre-headless php5-cli php5-curl php5-xdebug ncurses-term unzip xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic vim -y --no-install-recommends

2 changes: 2 additions & 0 deletions PHPUnit/Extensions/Selenium2TestCase/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* @method bool displayed() Checks an element's visibility
* @method bool enabled() Checks a form element's state
* @method bool equals(PHPUnit_Extensions_Selenium2TestCase_Element $another) Checks if the two elements are the same on the page
* @method array rect() Retrieves the element's coordinates: keys 'x', 'y', 'width' and 'height' in the returned array
* @method array location() Retrieves the element's position in the page: keys 'x' and 'y' in the returned array
* @method bool selected() Checks the state of an option or other form element
* @method array size() Retrieves the dimensions of the element: 'width' and 'height' of the returned array
Expand Down Expand Up @@ -107,6 +108,7 @@ protected function initCommands()
'equals' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Equals',
'location' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericAccessor',
'name' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericAccessor',
'rect' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Rect',
'selected' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericAccessor',
'size' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericAccessor',
'submit' => 'PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericPost',
Expand Down
73 changes: 73 additions & 0 deletions PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Rect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2010-2013, Sebastian Bergmann <[email protected]>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <[email protected]>
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 1.2.4
*/

/**
* Retrieves the element's coordinates
*
* @package PHPUnit_Selenium
* @author Giorgio Sironi <[email protected]>
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 1.2.4
*/
class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Rect
extends PHPUnit_Extensions_Selenium2TestCase_Command
{
/**
* @param array $parameter
*/
public function __construct($parameter,
PHPUnit_Extensions_Selenium2TestCase_URL $attributeResourceBaseUrl)
{
$this->jsonParameters = array();
$this->url = $attributeResourceBaseUrl->descend($parameter);
}

public function httpMethod()
{
return 'GET';
}
}
7 changes: 7 additions & 0 deletions Tests/Selenium2TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,4 +1147,11 @@ public function testGetSelectedOptionDataInMultiselect()
$this->assertSame('', $this->select($this->byId('theSelect'))->selectedValue());
$this->assertSame('', $this->select($this->byId('theSelect'))->selectedId());
}

public function testElementRectHeightAndWidth() {
$this->url('html/test_element_rect.html');
$coordinates = $this->byId('rect')->rect();
$this->assertEquals('50', $coordinates['width']);
$this->assertEquals('30', $coordinates['height']);
}
}
12 changes: 12 additions & 0 deletions selenium-1-tests/html/test_element_rect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>Element Rect page</title>
<script type="text/javascript">
</script>
</head>
<body>
This is a test of the rect command.

<div id="rect" style="width: 50px; height: 30px"></div>;
</body>
</html>

0 comments on commit f4b406f

Please sign in to comment.