Skip to content

Commit

Permalink
Merge branch '1.2' into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 24, 2022
2 parents a1009a8 + d3080f4 commit ce75810
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 40 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:
# Every Sunday at 1:20pm UTC
schedule:
- cron: '20 13 * * 0'

jobs:
ci:
name: CI
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule')
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
17 changes: 17 additions & 0 deletions .github/workflows/keepalive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Keepalive

on:
workflow_dispatch:
# The 24th of every month at 1:50pm UTC
schedule:
- cron: '50 13 24 * *'

jobs:
keepalive:
name: Keepalive
# Only run cron on the silverstripe account
if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Keepalive
uses: silverstripe/gha-keepalive@v1
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Mink Facebook WebDriver extension

[![CI](https://github.com/silverstripe/MinkFacebookWebDriver/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/MinkFacebookWebDriver/actions/workflows/ci.yml)

Currently forked from [https://github.com/minkphp/MinkSelenium2Driver/] and updated to use
the [facebook php webdriver](https://github.com/facebook/php-webdriver).

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"php-webdriver/webdriver": "^1.4"
},
"require-dev": {
"mink/driver-testsuite": "dev-master"
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<file>src</file>

<!-- base rules are PSR-12 -->
<rule ref="PSR12" >
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>

<!-- include php files only -->
<arg name="extensions" value="php"/>
</ruleset>
30 changes: 0 additions & 30 deletions phpunit.xml.dist

This file was deleted.

26 changes: 17 additions & 9 deletions src/FacebookWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FacebookWebDriver extends CoreDriver
/**
* Default browser
*/
const DEFAULT_BROWSER = 'chrome';
public const DEFAULT_BROWSER = 'chrome';

/**
* Hostname of driver
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function initChromeCapabilities(DesiredCapabilities $caps, $config)
} else {
$chromeOptions[$capability] = $value;
}
$caps->setCapability('chrome.'.$capability, $value);
$caps->setCapability('chrome.' . $capability, $value);
}

$caps->setCapability('chromeOptions', $chromeOptions);
Expand Down Expand Up @@ -290,7 +290,7 @@ protected function withSyn()
);

if (!$hasSyn) {
$synJs = file_get_contents(__DIR__.'/Resources/syn.js');
$synJs = file_get_contents(__DIR__ . '/Resources/syn.js');
$this->webDriver->executeScript($synJs);
}

Expand Down Expand Up @@ -318,7 +318,7 @@ protected static function charToOptions($char, $modifier = null)
);

if ($modifier) {
$options[$modifier.'Key'] = 1;
$options[$modifier . 'Key'] = 1;
}

return json_encode($options);
Expand Down Expand Up @@ -584,7 +584,7 @@ public function findElementXpaths($xpath)

$elements = array();
foreach ($nodes as $i => $node) {
$elements[] = sprintf('(%s)[%d]', $xpath, $i+1);
$elements[] = sprintf('(%s)[%d]', $xpath, $i + 1);
}

return $elements;
Expand Down Expand Up @@ -734,7 +734,9 @@ public function setValue($xpath, $value)
$elementType = strtolower($element->getAttribute('type') ?? '');

if (in_array($elementType, array('submit', 'image', 'button', 'reset'))) {
throw new DriverException(sprintf('Impossible to set value an element with XPath "%s" as it is not a select, textarea or textbox', $xpath));
$message = 'Impossible to set value an element with XPath "%s" as it is not a select, ';
$message = $message . 'textarea or textbox';
throw new DriverException(sprintf($message, $xpath));
}

if ('checkbox' === $elementType) {
Expand Down Expand Up @@ -828,7 +830,8 @@ public function selectOption($xpath, $value, $multiple = false)
return;
}

throw new DriverException(sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath));
$message = 'Impossible to select an option on the element with XPath "%s" as it is not a select or radio input';
throw new DriverException(sprintf($message, $xpath));
}

/**
Expand Down Expand Up @@ -1176,7 +1179,11 @@ private function selectOptionOnElement(RemoteWebElement $element, $value, $multi
{
$escapedValue = $this->xpathEscaper->escapeLiteral($value);
// The value of an option is the normalized version of its text when it has no value attribute
$optionQuery = sprintf('.//option[@value = %s or (not(@value) and normalize-space(.) = %s)]', $escapedValue, $escapedValue);
$optionQuery = sprintf(
'.//option[@value = %s or (not(@value) and normalize-space(.) = %s)]',
$escapedValue,
$escapedValue
);
$option = $this->findElement($optionQuery, $element); // Avoids selecting values from other select boxes

if ($multiple || !$element->getAttribute('multiple')) {
Expand Down Expand Up @@ -1224,7 +1231,8 @@ private function deselectAllOptions(RemoteWebElement $element)
*/
private function ensureInputType(RemoteWebElement $element, $xpath, $type, $action)
{
if ('input' !== $element->getTagName()
if (
'input' !== $element->getTagName()
|| $type !== $element->getAttribute('type')
) {
throw new DriverException(
Expand Down

0 comments on commit ce75810

Please sign in to comment.