Codeception / Codeception

Full-stack testing PHP framework
http://codeception.com
MIT License
4.77k stars 1.3k forks source link

pressKey returns Array to string conversion #5848

Closed michalper closed 4 years ago

michalper commented 4 years ago

What are you trying to achieve?

$I->pressKey('.select2-input', 'pro');

What do you get instead?

Array to string conversion

Provide console output if related. Use -vvv mode for more details.

michalper@ST000156 sportsadminv3 % php vendor/bin/codecept run acceptance -g failed1 -vvv
Codeception PHP Testing Framework v4.1.0
Powered by PHPUnit 9.0.1 by Sebastian Bergmann and contributors.
Running with seed: 

[Groups] failed1 

  [Connecting To Db] {"config":{"populate":false,"cleanup":false,"reconnect":false,"waitlock":0,"dump":null,"populator":null,"dsn":"mysql:host=localhost;dbname=head","user":"root","password":"root"},"options":[]}
  [Db] Connected to default head

Acceptance Tests (1) -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: WebDriver, \Helper\Acceptance, Db, DbHelper, Laravel5
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  [RunProcess] Starting exec docker run --net=host -e TZ="Europe/Warsaw" selenium/standalone-chrome
AddParticipantToStageCest: Add participant to stage
Signature: Tests\Acceptance\Season\AddParticipantToStageCest:addParticipantToStage
Test: tests/acceptance/competition/AddParticipantToStageCest.php:addParticipantToStage
Scenario --
  [Database] Transaction started
 I login as admin 
   I am on page "/auth/logout"
  [GET] http://dev.statscore.com/auth/logout
   I wait for element visible "#loginform"
   I fill field "email","*********"
   I fill field "password","*********"
   I click "#login"
   I wait for element "#content-header > h1",10
 I am on page "/sportsadmin/stages/76523/participants/create"
  [GET] http://dev.statscore.com/sportsadmin/stages/76523/participants/create
 I click ".select2-container"
 I wait for element visible ".select2-input",20
 I press key ".select2-input","pro"
 I make screenshot "AddParticipantToStageCest_2020-02-13T13:06:23+01:00"
  [Screenshot Saved] file:///Users/michalper/web/sportsadminv3/tests/_output/debug/AddParticipantToStageCest_2020-02-13T13:06:23+01:00.png
  Screenshot and page source were saved into '/Users/michalper/web/sportsadminv3/tests/_output/' dir
 ERROR 

  [Database] Transaction cancelled; all changes reverted.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 14.89 seconds, Memory: 30.00 MB

There was 1 error:

---------
1) AddParticipantToStageCest: Add participant to stage
 Test  tests/acceptance/competition/AddParticipantToStageCest.php:addParticipantToStage

  [ErrorException] Array to string conversion  

Scenario Steps:

 11. $I->makeScreenshot("AddParticipantToStageCest_2020-02-13T13:06:23+01:00") at tests/_support/Helper/AcceptanceCest.php:11
 10. $I->pressKey(".select2-input","pro") at tests/acceptance/competition/AddParticipantToStageCest.php:31
 9. $I->waitForElementVisible(".select2-input",20) at tests/acceptance/competition/AddParticipantToStageCest.php:30
 8. $I->click(".select2-container") at tests/acceptance/competition/AddParticipantToStageCest.php:29
 7. $I->amOnPage("/sportsadmin/stages/76523/participants/create") at tests/acceptance/competition/AddParticipantToStageCest.php:27
 6. $I->waitForElement("#content-header > h1",10) at tests/_support/AcceptanceTester.php:83

/Users/michalper/web/sportsadminv3/vendor/sentry/sentry/src/ErrorHandler.php:379
/Users/michalper/web/sportsadminv3/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebElement.php:333
/Users/michalper/web/sportsadminv3/vendor/codeception/module-webdriver/src/Codeception/Module/WebDriver.php:2902
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Step.php:266
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Scenario.php:76
/Users/michalper/web/sportsadminv3/tests/_support/_generated/AcceptanceTesterActions.php:2826
/Users/michalper/web/sportsadminv3/tests/acceptance/competition/AddParticipantToStageCest.php:31
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Lib/Di.php:127
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Test/Cest.php:138
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Test/Cest.php:150
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Test/Cest.php:82
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Test/Test.php:88
/Users/michalper/web/sportsadminv3/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
/Users/michalper/web/sportsadminv3/vendor/codeception/phpunit-wrapper/src/Runner.php:117
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/SuiteManager.php:161
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Codecept.php:196
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Codecept.php:163
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Command/Run.php:503
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Command/Run.php:397
/Users/michalper/web/sportsadminv3/vendor/symfony/console/Command/Command.php:255
/Users/michalper/web/sportsadminv3/vendor/symfony/console/Application.php:1012
/Users/michalper/web/sportsadminv3/vendor/symfony/console/Application.php:272
/Users/michalper/web/sportsadminv3/vendor/symfony/console/Application.php:148
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/src/Codeception/Application.php:117
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/app.php:46
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/app.php:47
/Users/michalper/web/sportsadminv3/vendor/codeception/codeception/codecept:7

Artifacts:

Png: /Users/michalper/web/sportsadminv3/tests/_output/Tests.Acceptance.Season.AddParticipantToStageCest.addParticipantToStage.fail.png
Html: /Users/michalper/web/sportsadminv3/tests/_output/Tests.Acceptance.Season.AddParticipantToStageCest.addParticipantToStage.fail.html

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
  [Db] Disconnected from default

Provide test source code if related

<?php

namespace Tests\Acceptance\Season;

use AcceptanceTester;
use Exception;
use Facebook\WebDriver\WebDriverKeys;
use Helper\Acceptance;
use Helper\AcceptanceCest;

/**
 * Class AddParticipantToStageCest
 * @package Tests\Acceptance\Season
 */
class AddParticipantToStageCest extends AcceptanceCest
{
    private const URL = '/sportsadmin/stages/76523/participants/create';

    /**
     * @param AcceptanceTester $I
     * @throws Exception
     */
    public function addParticipantToStage(AcceptanceTester $I): void
    {
        $I->loginAsAdmin()
            ->amOnPage(static::URL);

        $I->click('.select2-container');
        $I->waitForElementVisible('.select2-input', Acceptance::DEFAULT_TIMEOUT);
        $I->pressKey('.select2-input', 'pro');
        $I->waitForElementVisible('.select2-result-label', Acceptance::DEFAULT_TIMEOUT);
        $I->pressKey('.select2-input', WebDriverKeys::ENTER);
        $I->submitForm('.form-horizontal', []);
        $I->waitForElementVisible('.alert-success', Acceptance::DEFAULT_TIMEOUT);

        $I->see('Participant has been added to stage', '.alert-success');
    }
}

Details

# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

actor: AcceptanceTester
modules:
  enabled:
    - WebDriver:
        url: 'http://dev.statscore.com/'
        window_size: false
        log_js_errors: true
        port: 4444
        browser: chrome
        capabilities:
          chromeOptions:
            args: ["--window-size=1600,900", "--headless"]
    - \Helper\Acceptance
    - Db
    - DbHelper
    - Laravel5:
        part: ORM
        environment_file: .env
  config:
    Db:
      dsn: 'mysql:host=localhost;dbname=head'
      user: 'root'
      password: 'root'
      populate: false
      cleanup: false
extensions:
  enabled:
    - Codeception\Extension\RunProcess:
        0: exec docker run --net=host -e TZ="Europe/Warsaw" selenium/standalone-chrome
        sleep: 7 # wait 7 second for processes to boot
Naktibalda commented 4 years ago

It is a known issue of php-webdriver https://github.com/php-webdriver/php-webdriver/issues/758 It is already fixed and will be released as php-webdriver/webdriver 1.8.1

michalper commented 4 years ago

Ok, thanks for your information. Waiting for 1.8.1.

OndraM commented 4 years ago

Php-webdriver 1.8.1 which includes the fix has just been released :rocket: