Skip to content

fix for equals method when element id was 0 #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PHPWebDriver/WebDriverBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function curl($http_method,
}

$url = sprintf('%s%s', $this->url, $command);
if ($params && (is_int($params) || is_string($params))) {
if (is_int($params) || is_string($params)) {
$url .= '/' . $params;
}

Expand Down
78 changes: 78 additions & 0 deletions test/EqualsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
// Copyright 2012-present Element 34
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

require_once(dirname(__FILE__) . '/../PHPWebDriver/WebDriver.php');
require_once(dirname(__FILE__) . '/../PHPWebDriver/WebDriverBy.php');
require_once('LocalWebServer.php');

class AlertTest extends PHPUnit_Framework_TestCase {
protected static $pid;
protected static $port;

private $session;

public static function setUpBeforeClass() {
if (function_exists('pcntl_fork') && function_exists('posix_kill')) {
// get an empty socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, '127.0.0.1', 0);
socket_getsockname($socket, $socket_address, $port);
socket_close($socket);
// set it somewhere
self::$port = $port;
// fork the webserver
self::$pid = pcntl_fork();
if (self::$pid == -1) {
return $this->raiseError('Could not fork child process.');
} elseif (self::$pid == 0) {
$webserver = &new LocalWebServer('127.0.0.1', $port);
$webserver->_driver->setDebugMode(false);
$webserver->documentRoot = dirname(__FILE__) . '/../www';
$webserver->start();
} else {
// the parent process does not have to do anything
}
}
}

public function setUp() {
$driver = new PHPWebDriver_WebDriver();

$this->session = $driver->session();

$this->session->open("http://127.0.0.1:" . self::$port . "/equals.html");
}

public function tearDown() {
$this->session->close();
}

public static function tearDownAfterClass() {
posix_kill(self::$pid, SIGKILL);
}

/**
* @group equals
*/
public function testEquals() {
$id = 'title';

$e1 = $this->session->element(PHPWebDriver_WebDriverBy::ID, $id);
$e2 = $this->session->element(PHPWebDriver_WebDriverBy::ID, $id);

$this->assertTrue($e1->equals($e2->getID()));
}
}
7 changes: 7 additions & 0 deletions www/equals.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<div id="title">Title</div>
</body>
</html>