Codeception: [UnknownServerException] Cannot define class using reflection

Created on 30 Nov 2017  路  11Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

Run Acceptance tests on my vagrant box.

What do you get instead?

1) AdminCept: Test admin panel features
 Test  tests/acceptance/AdminCept.php

  [Facebook\WebDriver\Exception\UnknownServerException] Cannot define class using reflection  

/var/www/app-tfy-v3/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/var/www/app-tfy-v3/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:320
/var/www/app-tfy-v3/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:126
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Module/WebDriver.php:1421
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Module/WebDriver.php:413
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php:56
/var/www/app-tfy-v3/vendor/symfony/event-dispatcher/EventDispatcher.php:212
/var/www/app-tfy-v3/vendor/symfony/event-dispatcher/EventDispatcher.php:44
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:131
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:100
/var/www/app-tfy-v3/vendor/phpunit/phpunit/src/Framework/TestResult.php:395
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Test/Test.php:74
/var/www/app-tfy-v3/vendor/phpunit/phpunit/src/Framework/TestSuite.php:744
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:106
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/SuiteManager.php:157
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Codecept.php:188
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Codecept.php:157
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Command/Run.php:420
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Command/Run.php:347
/var/www/app-tfy-v3/vendor/symfony/console/Command/Command.php:264
/var/www/app-tfy-v3/vendor/symfony/console/Application.php:874
/var/www/app-tfy-v3/vendor/symfony/console/Application.php:228
/var/www/app-tfy-v3/vendor/symfony/console/Application.php:130
/var/www/app-tfy-v3/vendor/codeception/codeception/src/Codeception/Application.php:103
/var/www/app-tfy-v3/vendor/codeception/codeception/codecept:36

Provide test source code if related

<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('test admin panel features');

//1 - Try to login
$I->amOnPage('/app/login');

Details

  • Codeception version: 2.3.6
  • Chrome version: 62.0
  • Chromedriver version: 2.33
  • PHP Version: 7.1
  • Operating System: Ubuntu 16.04
  • Installation type: Composer
  • List of installed packages (composer show)
aws/aws-php-sns-message-validator         1.4.0   Amazon SNS message validation for PHP
aws/aws-sdk-php                           3.43.0  AWS SDK for PHP - Use Amazon Web Services in your ...
behat/gherkin                             v4.4.5  Gherkin DSL parser for PHP 5.3
bugsnag/bugsnag                           v3.9.0  Official Bugsnag notifier for PHP applications.
codeception/codeception                   2.3.6   BDD-style testing framework
composer/ca-bundle                        1.1.0   Lets you find a path to the system CA bundle, and ...
cronofy/cronofy                           v0.13.2 PHP wrapper for Cronofy's unified calendar API
doctrine/instantiator                     1.0.5   A small, lightweight utility to instantiate object...
dompdf/dompdf                             v0.8.2  DOMPDF is a CSS 2.1 compliant HTML to PDF converter
facebook/graph-sdk                        5.6.1   Facebook SDK for PHP
facebook/webdriver                        1.5.0   A PHP client for Selenium WebDriver
firebase/php-jwt                          v5.0.0  A simple library to encode and decode JSON Web Tok...
google/apiclient                          v2.2.1  Client library for Google APIs
google/apiclient-services                 v0.36   Client library for Google APIs
google/auth                               v1.1.0  Google Auth Library for PHP
guzzlehttp/guzzle                         6.3.0   Guzzle is a PHP HTTP client library
guzzlehttp/promises                       v1.3.1  Guzzle promises library
guzzlehttp/psr7                           1.4.2   PSR-7 message implementation that also provides co...
intercom/intercom-php                     v3.1.8  Intercom API client built on top of Guzzle 6
league/oauth2-client                      2.2.1   OAuth 2.0 Client Library
linkedinapi/linkedin                      1.1.0   PHP LinkedIn SDK
magroski/frogg                            v1.0.31 Nogg PHP Framework/Toolset for use with Phalcon Fr...
magroski/socialauth                       v1.0.3  Simple PHP wrapper for social authentication. Supp...
microsoft/microsoft-graph                 1.0.3   The Microsoft Graph SDK for PHP
mobiledetect/mobiledetectlib              2.8.26  Mobile_Detect is a lightweight PHP class for detec...
monolog/monolog                           1.23.0  Sends your logs to files, sockets, inboxes, databa...
mtdowling/jmespath.php                    2.4.0   Declaratively specify how to extract elements from...
myclabs/deep-copy                         1.7.0   Create deep copies (clones) of your objects
paragonie/random_compat                   v2.0.11 PHP 5.x polyfill for random_bytes() and random_int...
phalcon/ide-stubs                         v3.2.5  The most complete Phalcon Framework IDE stubs libr...
phalcon/zephir                            0.9.11  Zephir is a compiled high level language aimed to ...
phar-io/manifest                          1.0.1   Component for reading phar.io manifest information...
phar-io/version                           1.0.1   Library for handling version information and const...
phenx/php-font-lib                        0.5.1   A library to read, parse, export and make subsets ...
phenx/php-svg-lib                         v0.3    A library to read, parse and export to PDF SVG files.
php-mime-mail-parser/php-mime-mail-parser 2.9.4   Fully Tested Mailparse Extension Wrapper for PHP 5.4+
phpdocumentor/reflection-common           1.0.1   Common reflection classes used by phpdocumentor to...
phpdocumentor/reflection-docblock         4.2.0   With this component, a library can provide support...
phpdocumentor/type-resolver               0.4.0  
phpseclib/phpseclib                       2.0.9   PHP Secure Communications Library - Pure-PHP imple...
phpspec/prophecy                          1.7.3   Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage                 5.2.4   Library that provides collection, processing, and ...
phpunit/php-file-iterator                 1.4.5   FilterIterator implementation that filters files b...
phpunit/php-text-template                 1.2.1   Simple template engine.
phpunit/php-timer                         1.0.9   Utility class for timing
phpunit/php-token-stream                  2.0.2   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                           6.4.4   The PHP Unit Testing framework.
phpunit/phpunit-mock-objects              4.0.4   Mock Object library for PHPUnit
psr/cache                                 1.0.1   Common interface for caching libraries
psr/http-message                          1.0.1   Common interface for HTTP messages
psr/log                                   1.0.2   Common interface for logging libraries
sabberworm/php-css-parser                 8.1.0   Parser for CSS Files written in PHP
sebastian/code-unit-reverse-lookup        1.0.1   Looks up which function or method a line of code b...
sebastian/comparator                      2.1.0   Provides the functionality to compare PHP values f...
sebastian/diff                            2.0.1   Diff implementation
sebastian/environment                     3.1.0   Provides functionality to handle HHVM/PHP environm...
sebastian/exporter                        3.1.0   Provides the functionality to export PHP variables...
sebastian/global-state                    2.0.0   Snapshotting of global state
sebastian/object-enumerator               3.0.3   Traverses array structures and object graphs to en...
sebastian/object-reflector                1.1.1   Allows reflection of object attributes, including ...
sebastian/recursion-context               3.0.0   Provides functionality to recursively process PHP ...
sebastian/resource-operations             1.0.0   Provides a list of PHP built-in functions that ope...
sebastian/version                         2.0.1   Library that helps with managing the version numbe...
servo/fluidxml                            1.21    Concise and fluent XML manipulation library
stecman/symfony-console-completion        0.7.0   Automatic BASH completion for Symfony Console Comp...
symfony/browser-kit                       v3.3.6  Symfony BrowserKit Component
symfony/console                           v3.3.6  Symfony Console Component
symfony/css-selector                      v3.3.6  Symfony CssSelector Component
symfony/debug                             v3.3.6  Symfony Debug Component
symfony/dom-crawler                       v3.3.6  Symfony DomCrawler Component
symfony/event-dispatcher                  v3.3.6  Symfony EventDispatcher Component
symfony/finder                            v3.3.6  Symfony Finder Component
symfony/polyfill-mbstring                 v1.6.0  Symfony polyfill for the Mbstring extension
symfony/process                           v3.3.6  Symfony Process Component
symfony/yaml                              v3.3.6  Symfony Yaml Component
techpivot/phalcon-ci-installer            1.0.7   Composer integration for PHP applications to insta...
theseer/tokenizer                         1.1.0   A small library for converting tokenized PHP sourc...
twilio/sdk                                5.16.0  A PHP wrapper for Twilio's API
webmozart/assert                          1.2.0   Assertions to validate method input/output with ni...
  • Suite configuration:
class_name: AcceptanceTester
modules:
    enabled:
        - Helper\Acceptance
        - Phalcon:
            bootstrap: public/test.php
            cleanup: false
            savepoints: true
            part: orm
        - WebDriver:
            url: http://localhost/
            browser: chrome
            window_size: 1920x1080
            log_js_errors: true
        - Db
  • Vagrant boot script:
export DISPLAY=:10
cd /vagrant

echo "Starting Xvfb ..."
Xvfb :10 -screen 0 1920x1080x24 -ac &

echo "Starting Google Chrome ..."
google-chrome --remote-debugging-port=9222 &

echo "Starting Selenium ..."
cd /usr/local/bin
nohup java -jar ./selenium-server-standalone-3.7.1.jar &
WebDriver

Most helpful comment

I had the same problem, downgrading from Java 10 to Java 8 fixed the problem for me.

I am on Mac OS X and had Java installed via brew.

brew cask uninstall java
brew tap caskroom/versions
brew cask install java8
java -version

All 11 comments

It is an issue of Selenium or chromedriver.
Search finds it reported in a few places, e.g. https://github.com/SeleniumHQ/selenium/issues/4964
but I haven't managed to find any solutions.

I found this solution: https://botbot.me/freenode/selenium/search/?q=Cannot+define+class+using+reflection

Toman_: simonstewart: I found out why I got the "WebDriverException: Message: Cannot define class using reflection" (https://pastebin.com/2d2Cbks1)
Turns out I had a java installation I wasn't aware of, coming from java-common.
I assume I have installed it at a late hour.
Removing java-common, and then installing openjdk-8-jre, everything just worked. https://pastebin.com/459R6P4b

HI I am getting the same issue -
"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.12.0","name":"webdriverio"}}}
ERROR: Cannot define class using reflection
chrome
at new RuntimeError (C:\wireless-ui\node_modules\webdriverio\buildlib\utils\ErrorHandler.js:144:12)
at Request._callback (C:\wireless-ui\node_modules\webdriverio\buildlib\utils\RequestHandler.js:316:39)
at Request.self.callback (C:\wireless-ui\node_modules\webdriverio\node_modulesrequestrequest.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request. (C:\wireless-ui\node_modules\webdriverio\node_modulesrequestrequest.js:1163:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage. (C:\wireless-ui\node_modules\webdriverio\node_modulesrequestrequest.js:1085:12)
at Object.onceWrapper (events.js:313:30)
ERROR: Cannot define class using reflection
chrome
at new RuntimeError (C:\wireless-ui\node_modules\webdriverio\buildlib\utils\ErrorHandler.js:144:12)
at Request._callback (C:\wireless-ui\node_modules\webdriverio\buildlib\utils\RequestHandler.js:316:39)
at Request.self.callback (C:\wireless-ui\node_modules\webdriverio\node_modulesrequestrequest.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request. (C:\wireless-ui\node_modules\webdriverio\node_modulesrequestrequest.js:1163:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage. (C:\wireless-ui\node_modules\webdriverio\node_modulesrequestrequest.js:1085:12)
at Object.onceWrapper (events.js:313:30)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I had the same problem, downgrading from Java 10 to Java 8 fixed the problem for me.

I am on Mac OS X and had Java installed via brew.

brew cask uninstall java
brew tap caskroom/versions
brew cask install java8
java -version

I had the same problem, downgrading from Java 10 (installed normally) to Java 8 (installed with brew) brew install caskroom/versions/java8 fixed this problem for me.

I have pushed this issue in the Selenium Google Group , but no response from them yet : https://groups.google.com/forum/#!searchin/selenium-users/java$2010%7Csort:date/selenium-users/h_lCnJTtEb8/yteuaONXBgAJ

I encountered a similar problem following the installation guide or quickstart. Everything works correctly with java 8, but java 10 gives me this error:

$ codeceptjs run --steps
"before each" hook: codeceptjs.before for "start from home page":
     Can't connect to WebDriver.
Error: Cannot define class using reflection

Please make sure Selenium Server (ChromeDriver or PhantomJS) is running and accessible

@Naktibalda any reason you closed this issue? Will JDK10 not be supported?

It isn't an issue of Codeception.

It isn't an issue of Codeception.

Haha, oops, I commented on the wrong issue. Apologies.

On linux mint 19, I had to install the openjdk8 and execute selenium using:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar selenium-server-standalone-3.8.1.jar
Working fine now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshhornby picture joshhornby  路  3Comments

sasha-x picture sasha-x  路  3Comments

Renkas picture Renkas  路  3Comments

jterry picture jterry  路  3Comments

allen0817 picture allen0817  路  3Comments