Giter VIP home page Giter VIP logo

php-webdriver's Introduction

WebDriver for Selenium 2

This WebDriver client implementation is based on Meta/Facebook's original php-webdriver project by Justin Bishop. Meta/Facebook's current php-webdriver is a complete rewrite.

Distinguishing features:

Latest Stable Version Total Downloads

Links

Notes

  • The 5.2.x branch is no longer maintained. This branch features class names and file re-organization that follow PEAR/ZF1 conventions. Bug fixes and enhancements from the master branch likely won't be backported.

php-webdriver's People

Contributors

0x46616c6b avatar aik099 avatar alnutile avatar c960657 avatar cjmct89 avatar drscre avatar everzet avatar fbrnc avatar gggeek avatar guilhermeblanco avatar handrus avatar jubishop avatar kadse avatar mremi avatar mvorisek avatar oallain avatar pborreli avatar robocoder avatar shavounet avatar stof avatar stronk7 avatar tdhsmith avatar thejoelpatrol avatar vibbow avatar xmeltrut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-webdriver's Issues

Can't specify required capabilities

I'm trying to run selenium tests so that it only chooses a certain version of IE.

In WebDriver.php line 65 the $requiredCapbilties array gets overwritten with a blank array, meaning that I cannot make the browser version of IE required, only desired.

This is causing issues as it is opening the wrong version of IE to run the tests on.

Thanks.

how to install with composer

I downloaded the zip and extract the contents into a folder then install composer.phar and run

php composer.phar require instaclick/php-webdriver

but this couldn't install the dependencies.

How can I install instaclick/php-webdriver with composer?

WireProtocol Spec sessionId change

ghostdriver 1.0.4 included a change (https://github.com/detro/ghostdriver/issues/247) to how sessionId is returned, in order to conform with with the WireProtocol specs. It's no longer returned as part of a 302 redirect, it's included in the json response.

I got it to work by changing AbstractWebDriver::curl to return an array with 'value', 'info', and 'sessionId' keys. Then WebDriver::session uses that sessionId if it is set, but can still fall back to other methods.

Container->element can return null should throw an exception

The function element in Containter can return null. Where the docblock tells it should only return Element type.

See the call to return $this->webDriverElement($results['value']); at line 77.

webDriverElement can return null next to Element. This is inconsistent.

How to work with popup windows?

I'm trying to test Facebook sign-in, which involves popup windows. Is this even possible?

Looking at the session class, there aren't methods for selecting popup windows.

Thanks,
Moon

Exception raised on closing connection with Web driver (Selenium)

If a testsuite use the Selenium2Driver, session is not properly closed and after some time an exception will be raised:

[WebDriver\Exception\UnknownError] Session [ffcc81c9-cef1-4517-ab30-cb97b6114a47] was terminated due to TIMEOUT

#0 /var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php(141): WebDriver\Exception::factory(13, 'Session [08a112...')
#1 /var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Session.php(157): WebDriver\AbstractWebDriver->curl('DELETE', '')
#2 /var/www/html/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php(348): WebDriver\Session->close()
#3 /var/www/html/vendor/behat/mink/src/Session.php(78): Behat\Mink\Driver\Selenium2Driver->stop()
#4 /var/www/html/vendor/behat/mink/src/Mink.php(186): Behat\Mink\Session->stop()
#5 /var/www/html/vendor/behat/mink/src/Mink.php(46): Behat\Mink\Mink->stopSessions()
#6 [internal function]: Behat\Mink\Mink->__destruct()
#7 {main}

chrome / hub logs:

chrome_1           | 11:05:37.783 INFO - Executing: [find element: By.xpath: //html])
chrome_1           | 11:05:37.843 INFO - Done: [find element: By.xpath: //html]
chrome_1           | 11:05:37.856 INFO - Executing: [get text: 5 [[ChromeDriver: chrome on LINUX (96b0e9603a8e164374fec11e9525e1bb)] -> xpath: //html]])
chrome_1           | 11:05:38.275 INFO - Done: [get text: 5 [[ChromeDriver: chrome on LINUX (96b0e9603a8e164374fec11e9525e1bb)] -> xpath: //html]]
chrome_1           | 11:05:38.290 INFO - Executing: [take screenshot])
chrome_1           | 11:05:38.457 INFO - Done: [take screenshot]
chrome_1           | 11:05:38.555 INFO - Executing: [delete all cookies])
chrome_1           | 11:05:38.589 INFO - Done: [delete all cookies]
hub_1              | 11:06:08.981 WARN - session ext. key 08a1122c-5413-445d-a4bb-3b0f7fa0bf58 has TIMED OUT due to client inactivity and will be released.
chrome_1           | 11:06:08.984 INFO - Executing: [delete session: 08a1122c-5413-445d-a4bb-3b0f7fa0bf58])
chrome_1           | 11:06:09.177 INFO - Done: [delete session: 08a1122c-5413-445d-a4bb-3b0f7fa0bf58]

IMHO, the webdriver close a session that do not exist and an exception will be raised here:

vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php

// if not success, throw exception
        if ((int) $result['status'] !== 0) {
            throw WebDriverException::factory($result['status'], $message);
        }

because thre $result['status'] is 13.

If we call directly the proper function to close/delete sessions like

        $driver->getWebDriverSession()->close();
        $driver->stop();
    }

an exception will be raised because of the result code that is 12 in this case.

FF 27, Selenium 2.39 Element value not working ?

hi, Element::value() is not setting the value into the textbox.
I believe this is a bug.

// get input textbox
$user = $session->element('id', 'username');
// try setting a value into textbox
$user->value('John');

Empty response now triggers json exception (1.4.4)

We've discovered a critical breakage in our behat CI caused by the recent 1.4.4 release.

I've traced this to #67.

An example broken build can be seen at https://travis-ci.org/silverstripe/silverstripe-framework/jobs/248559035

Our selenium server log shows the requests being passed through to it without any apparent error.

10:32:36.017 INFO - Done: /session/96d209e0-a12b-43ae-aa50-eff91550202d/window/current/size

The issue is caused in AbstractWebDriver when $rawResult is empty. It looks as though selenium emits an empty body for this request. Previously in 1.4.3 this would incorrectly attempt to parse this as json, but fail silently.

In 1.4.4 this will incorrectly attempt to parse this as json, but raise an error.

What should probably happen is that empty results aren't parsed at all, but left empty.

We are using selenium 2.41.0.

All WebDriver\Exception\* exceptions can't be serialized

Because some of exception classes create on the fly by eval function:

        if (!class_exists($namespacedClassName, false)) {
            eval(
                'namespace ' . __CLASS__ . '; final class ' . $className . ' extends \\' . __CLASS__ . ' {}'
            );
        }

All these classes objects can't be unserialized, because you'll get __PHP_Incomplete_Class_Name

Also use eval not a good practice at all, because of code auto-completion in this case.

Support for injecting CURL options into WebDriver

Right now WebDriver is using Curl to send commands to Selenium server. This works just fine, when we're able to make a connection.

However when server isn't responding for 1 minute then connection just drops (default socket connection timeout in PHP). E.g. https://github.com/instaclick/php-webdriver/blob/master/lib/WebDriver/WebDriver.php#L72-L77

I propose that we allow user setting extra curl options (will go directly to service.curl used and to curl_setopt calls).

Related to Behat/MinkSelenium2Driver#48

Running JS/jQuery through php-webdriver

Hi all,

I am fairly new to the php-webdriver world. Im having trouble running javascript through my test scripts. Im trying some thing like:
$postButtonVisible = $this->session->execute(array('script' => "$('input[value="Post"]').filter(":visible")", 'args' => array()));

Seems to return NULL. But when i tried running the script on the web developer console on Chrome, i get the intended result. And also, if i run a simple script like the one suggested in the docs for php webdriver, it works just fine returning a string "xyz":
$postButtonVisible = $this->session->execute(array('script' => 'return "xyz"', 'args' => array()));

What am i doing wrong? Any help would be great. Thanks.

Selenium commands not documented in JsonWireProtocol

References:

Obsolete:

String GET_APP_CACHE = "getAppCache";
String CLEAR_APP_CACHE = "clearAppCache";

rethink WebDriver Environment

  • it's "final"; users can't subclass: they must overwrite with local mods
  • static methods; no DI/SI to override at runtime

Autoloading problem

Hi.

I am trying to change default curl service behaviour (as mentioned here: #51 (comment))
I've created subclass of CurlService, and in my application bootstrap file I do something like that:

require_once __DIR__ . '/vendor/autoload.php';

\Webdriver\ServiceFactory::getInstance()->setServiceClass('service.curl', '\Webdriver\Service\CurlTimeoutService');

But I get Fatal error: Class 'Webdriver\ServiceFactory' not found

To debug this problem I cloned your project and installed dependencies (via composer install).
In my test.php I have following code:

require_once __DIR__ .'/vendor/autoload.php';

var_dump(class_exists('\Webdriver\ServiceFactory', true));

Executing this code, I get false.
So, there is some autoloading problem.

I took a look your composer.json and found following line

It contains namespace name and directory mapped to this namespace. You are telling composer to search class \Webdriver\Foo in file lib/Foo.php. But in lib directory only Webdriver directory exists. More information about composer autoloading can be found here.

I have removed "Webdriver" from autoloading config, regenerated autoload files (composer install) and my script prints true.

Probably, this fix should solve my original problem.

Allow subclassing of WebDriver class

Currently the WebDriver class is declared final.

This is a pity, as the Selenium2Driver has a method setWebDriver which is typehinted against it.
This means that it is not easy for me to subclass either.
I propose that

  • either we remove the 'final' keyword from WebDriver
  • or we introduce an interface WebDriverInterface (all it needs is the session method) which can be used by 3rd parties for typehinting...

PHP Warning

Warning: array_merge(): Argument #1 is not an array in /home/kbushell/Projects/awardforce/bundles/shift/vendor/instaclick/php-webdriver/lib/WebDriver/WebDriver.php on line 59

Attempts to resolve this by forcing $desiredCapabilities to an array, has resulted in fatal errors from selenium -> something is not setup correctly here.

Class refactoring

BrowserName.php, CapabilityType.php, and Keys.php are class files that only contain constants. Basically, this acts as a namespace wrapper.

However, a fundamental concept is that classes encapsulate behaviour., but here, there are no methods. Also, there's a code smell here with the class naming (where a constant lives, vs where it is used).

Choices:

  1. merge Keys.php into Element.php; merge BrowserName.php into WebDriver.php; merge CapabilityType.php into Sessions.php, or
  2. rename Keys.php to WebDriver/Element/Interface.php, BrowserName.php to WebDriver/Interface.php, and CapabilityType.php into WebDriver/Sessions/Interface.php

(I'm leaning towards option 1 as it's simpler and lighter)

selenium-server-standalone-2.23.1 crashes

Many tests failed after fetching v1.0.2 I am running
java -jar selenium-server-standalone-2.23.1.jar locally.

The error is:

14:13:51.386 INFO - Executing: [delete session: 1343736817963] at URL: /session/1343736817963)
14:13:51.650 INFO - Done: /session/1343736817963
14:13:51.652 INFO - Executing: [new session: {browserName=firefox}] at URL: /session)
14:13:54.767 INFO - Done: /session
14:15:56.219 WARN - Fatal, unhandled exception: /session: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
14:15:56.219 INFO - WebDriver remote server: Fatal, unhandled exception: /session: org.openqa.selenium.WebDriverException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
Build info: version: '2.23.1', revision: '17143', time: '2012-06-08 18:59:04'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-26-generic', java.version: '1.7.0_03'
Driver info: driver.version: unknown
14:15:56.220 WARN - EXCEPTION
javax.servlet.ServletException: org.openqa.selenium.WebDriverException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
Build info: version: '2.23.1', revision: '17143', time: '2012-06-08 18:59:04'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-26-generic', java.version: '1.7.0_03'

Optional CURL parameters for \WebDriver\WebDriver::session()

It would be awesome to get the session() method having the same parameters as the other library methods implementing the $extraOptions array so we can set a curl timeout (and any other desired curlopts) on the session start call.

We have an issue with our Selenium Hub/Grid whereby sessions will attempt to be started but hang/crash on the server which causes the tests to hang forever. Whilst I realise this needs to be resolved at the root cause, it still seems that this would be a useful feature in any case.

Use dependency injection

Right now the pull model (the service factory) is used instead of push model (dependency injection). The only service that is available right now is CurlService and it's used in 2 classes only:

  • AbstractWebDriver
  • SauceRest

Proposing to:

  1. add an optional $curlService argument to constructor of mentioned classes
  2. when not given use service factory to create it
  3. add $defaultOptions constructor parameter to existing CurlService class, that would be stored as class property
  4. the CurlService::execute method would merge $defaultOptions property with $extraOptions method argument to get final list of curl options for a request

This would both preserve BC and make replacement of CurlService straight forward.

No more detailed error messages since 1.4.2

I am using the webdriver in combination with behat. Since the release of 1.4.2 we are getting unusable error messages from the php web-driver

Example:

Feature: xxx

  Scenario: yyy                                  # features/test.feature:3
    Given I am on "http://dingo.local/hase.html" # FeatureContext::visit()
    When I press "b"                             # FeatureContext::pressButton()
      exception 'WebDriver\Exception\CurlExec' with message 'Curl error thrown for http POST to http://localhost:4444/wd/hub/session/93d71c50-df17-4c66-9c8e-86e4d5a7fd90/element/0/click

      The requested URL returned error: 500 Internal Server Error' in vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
      Stack trace:

This is not helpful at all. When i am locking the php-webdriver to 1.4.1 the same test does the following:

    When I press "b"                             # FeatureContext::pressButton()
      exception 'WebDriver\Exception\ElementNotVisible' with message 'Element is not currently visible and so may not be interacted with
      Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
      System info: host: 'hans-guenther.local', ip: '192.168.10.118', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.6.0_65'
      Driver info: driver.version: unknown' in vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
      Stack trace:

This is (my) desired result here.

I debugged a bit and can track down the error to this commit:

3b11d17

When removing this line everything is working again. I am not into the internals and don't know what problem that commit exactly solved but it makes debugging behat results nearly impossible as there are no error details at all anymore ๐Ÿถ

Exception when accessing SauceLabs

I'm using SauceRest class that comes with this library to communicate with SauceLabs service.

Recently my build failed (see https://travis-ci.org/aik099/phpunit-mink/jobs/44319424) with following exception:

PHP Fatal error:  Uncaught exception 'WebDriver\Exception\CurlExec' with message 'Curl error thrown for http PUT to https://saucelabs.com/rest/v1/aik099/jobs/471ebd9080014f919bea959e2ee1a928 with params: {"passed":true}
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none' in /home/travis/build/aik099/phpunit-mink/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
Stack trace:
#0 /home/travis/build/aik099/phpunit-mink/vendor/instaclick/php-webdriver/lib/WebDriver/Service/CurlService.php(97): WebDriver\Exception::factory(-1, 'Curl error thro...')
#1 /home/travis/build/aik099/phpunit-mink/vendor/instaclick/php-webdriver/lib/WebDriver/SauceLabs/SauceRest.php(76): WebDriver\Service\CurlService->execute('PUT', 'https://saucela...', Array, Array)
#2 /home/travis/build/aik099/phpunit-mink/vendor/instaclick/php-webdriver/lib/WebDriver/SauceLabs/SauceRest.php(208): WebDriver\SauceLabs\SauceRest->execute('PUT', 'aik099/jobs/471...', Array)
#3 /home/travis/build/aik099/phpunit-min in /home/travis/build/aik099/phpunit-mink/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php on line 155

As you can see from the stack trace the SSL certificate on SauceLabs appears to be broken or something like that.

To solve that problem I propose to add extra curl options in https://github.com/instaclick/php-webdriver/blob/master/lib/WebDriver/SauceLabs/SauceRest.php#L76 that would allow to skip SSL certificate validation:

// don't verify SSL certificates
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => Array ('Expect:'),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.