phpunit-selenium icon indicating copy to clipboard operation
phpunit-selenium copied to clipboard

Is it compatible with Selenium Webdriver 3 + geckodriver ?

Open chandon opened this issue 6 years ago • 1 comments

Hello,

I'm trying to make phpunt-selenium work with Selenium Webdriver 3 + Firefox + Geckodriver, is phpunit-selenium comptabile ? php : 7.0 phpunit : 6.5.12 phpunit-selenium : 4.1.0 geckodriver : 0.19 (or 0.21) Firefox : 57.0.4

I mange to connect Phpunit and Geckodriver/Firefox, open a page with $this->url(), but when doing $this->byCssSelector('DIV'), i got an Exception :

InvalidArgumentException: Element not found.

vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element.php:82
vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element/Accessor.php:136
vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element/Accessor.php:175
vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element/Accessor.php:72
vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:416

After investigating, (geckodriver log + var_dump in vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase/Element.php:82), geckodriver returns a response :

array(1) {
  'element-6066-11e4-a52e-4f735466cecf' =>string(36) "4d645ed2-8069-4fb6-9f86-e1a33311ac7b"
}

an Element.php is waiting for array["ELEMENT"]

(see https://github.com/mozilla/geckodriver/issues/391)

So i think it's not compatible with geckodriver and Selenium 3 + Firefox ?

chandon avatar Sep 06 '18 20:09 chandon

No, it's not compatible now !

But I solved 95% of my problems by changing method fromResponseValue in Element.php. It's trying to get ELEMENT value (Selenium Format) or a key beginning with 'element' (W3C WebDriver format for geckodriver)

public static function fromResponseValue(
        array $value,
        PHPUnit_Extensions_Selenium2TestCase_URL $parentFolder,
        PHPUnit_Extensions_Selenium2TestCase_Driver $driver)
{
    $key = false;
    if (!isset($value['ELEMENT'])) {
        foreach ($value as $lKey => $val) {
            if (substr($lKey,0,7) === "element") {
                $key = $lKey;
                break;
            }
        }
        if (! $key) {
            throw new InvalidArgumentException('Element not found.');
        }
    } else {
        $key = "ELEMENT";
    }
    $url = $parentFolder->descend($value[$key]);
    return new self($driver, $url);
}

chandon avatar Sep 06 '18 23:09 chandon