Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/SeleniumClientTest/phpunit.xml
/build
/.idea
/*.project
15 changes: 13 additions & 2 deletions SeleniumClient/By.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@ public static function cssSelector($selectorValue) { return new By("css selector
* @return \SeleniumClient\By
*/
public static function id($selectorValue) { return new By("id", $selectorValue); }


/**
* Locate by JavaScript selector
* @param string $selectorValue
* @param string $selectorDefinition
* @return \SeleniumClient\By
*/
public static function jsSelector($selectorValue, $selectorDefinition = '$')
{
return new By("js selector {$selectorDefinition}", $selectorValue);
}

/**
* Locate by element's name
* @param unknown_type $selectorValue
* @param String $selectorValue
* @return \SeleniumClient\By
*/
public static function name($selectorValue) { return new By("name", $selectorValue); }
Expand Down
26 changes: 13 additions & 13 deletions SeleniumClient/DesiredCapabilities.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php
// Copyright 2012-present Nearsoft, Inc
// 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
// Copyright 2012-present Nearsoft, Inc

// 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.

namespace SeleniumClient;

use SeleniumClient\CapabilityType;

require_once 'CapabilityType.php';
require_once __DIR__ . '/CapabilityType.php';

class DesiredCapabilities {

Expand Down
62 changes: 42 additions & 20 deletions SeleniumClient/Http/HttpClient.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
// Copyright 2012-present Nearsoft, Inc
// 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
// Copyright 2012-present Nearsoft, Inc

// 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.

namespace SeleniumClient\Http;
Expand Down Expand Up @@ -38,32 +38,52 @@ public function setTrace($value)
$this->_trace = $value;
return $this;
}

public function setUrl($value)

/**
* @param string $value
* @return $this
*/
public function setUrl($value)
{
$this->_url = $value;
return $this;
}


/**
* @param bool $value
* @return $this
*/
public function setPolling($value)
{
$this->_polling = $value;
return $this;
}


/**
* @param string $value
* @return $this
*/
public function setJsonParams($value)
{
$this->_jsonParams = $value;
return $this;
}


/**
* @param string $value
* @return $this
*/
public function setHttpMethod($value)
{
$this->_httpMethod = $value;
return $this;
}

public function execute()

/**
* @return string The response body
* @throws \Exception
*/
public function execute()
{
if (empty($this->_url) || empty($this->_httpMethod)) { throw new \Exception("Must specify URL and HTTP METHOD"); }

Expand Down Expand Up @@ -96,7 +116,7 @@ public function execute()
echo "URL: " . $this->_url . "\n";
echo "METHOD: " . $this->_httpMethod . "\n";

echo "PARAMETTERS: ";
echo "PARAMETERS: ";
if (is_array($this->_jsonParams)) { echo print_r($this->_jsonParams); }
else echo "NONE"; { echo "\n"; }

Expand All @@ -112,5 +132,7 @@ public function execute()

$this->_responseHeaders = $responseHeaders;
$this->_responseBody = $responseBody;

return $this->_responseBody;
}
}
50 changes: 29 additions & 21 deletions SeleniumClient/Http/HttpFactory.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
<?php
// Copyright 2012-present Nearsoft, Inc
// 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
// Copyright 2012-present Nearsoft, Inc

// 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.

namespace SeleniumClient\Http;

abstract class HttpFactory{

const PRODUCTIONMODE = "PRODUCTION";
const TESTINGMODE = "TESTING";

public static function getClient($environment)
const TESTINGMODE = "TESTING";

/**
* @param string $environment
* @return HttpClient
* @throws \Exception
*/
public static function getClient($environment)
{
switch(strtoupper($environment))
{
case HttpFactory::PRODUCTIONMODE :
require_once("SeleniumAdapter.php");
case HttpFactory::PRODUCTIONMODE:
require_once __DIR__ . "/SeleniumAdapter.php";
return new SeleniumAdapter();
break;
case HttpFactory::TESTINGMODE:
require_once("../../SeleniumClientTest/HttpClientMock.php");
return new \HttpClientMock();
break;
/*
case HttpFactory::TESTINGMODE:
require_once __DIR__ . "/../../SeleniumClientTest/HttpClientMock.php";
return new \HttpClientMock();
break;
*/
}
throw new \Exception( 'Invalid environment' );
}
}
32 changes: 16 additions & 16 deletions SeleniumClient/Http/SeleniumAdapter.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<?php
// Copyright 2012-present Nearsoft, Inc
// 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
// Copyright 2012-present Nearsoft, Inc

// 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.

namespace SeleniumClient\Http;

require_once "Exceptions.php";
require_once __DIR__ . "/Exceptions.php";

class SeleniumAdapter extends HttpClient
{
public function execute()
{
parent::execute();
$responseBody = parent::execute();

$this->validateSeleniumResponseCode();
$this->validateHttpCode ();
$this->validateHttpCode();

return $this->_responseBody;
return $responseBody;
}

protected function validateHttpCode()
Expand Down
78 changes: 39 additions & 39 deletions SeleniumClient/SelectElement.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
// Copyright 2012-present Nearsoft, Inc
// 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
// Copyright 2012-present Nearsoft, Inc

// 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.

namespace SeleniumClient;

require_once 'WebElement.php';
require_once __DIR__ . '/WebElement.php';

class SelectElement
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public function selectByValue($value)
$matched = false;
foreach($options as $option)
{

/** @var $option WebElement */
if(!$option->isSelected())
{
$option->click();
Expand All @@ -62,30 +62,30 @@ public function selectByValue($value)
}
}

/**
* Sets an option selected by a partial text match
* @param String $text
* @throws \Exception
*/
public function selectByPartialText($text)
{
$options = $this->_element->findElements(By::xPath(".//option[contains(text(), '" . $text . "')]"));
$matched = false;
foreach($options as $option)
{
if(!$option->isSelected())
{
$option->click();
}
$matched = true;
}
if (!$matched)
{
throw new \Exception("Cannot locate option in select element with text: " . $text);
}
/**
* Sets an option selected by a partial text match
* @param String $text
* @throws \Exception
*/
public function selectByPartialText($text)
{
$options = $this->_element->findElements(By::xPath(".//option[contains(text(), '" . $text . "')]"));

$matched = false;
foreach($options as $option)
{
/** @var $option WebElement */
if(!$option->isSelected())
{
$option->click();
}

$matched = true;
}

if (!$matched)
{
throw new \Exception("Cannot locate option in select element with text: " . $text);
}
}
}
Loading