Skip to content

$I->click does not work with submit button outside form #5425

Closed

Description

@martin-schulze-vireso

What are you trying to achieve?

Submit a form with a submit button outside the form:

<form id="form-id"></form>
<input type="submit" form="form-id" />

What do you get instead?

The click runs through without error but my test fails due to an unsubmitted form.

Details

I am using $I->click(['xpath' => '//input[@type="submit"][@form="selection"]']); in the test code.
Stepping through with the debugger, I noticed that InnerBrowser::clickButton has a DOM traversal loop and a warning codecept_debug('Button is not inside a link or a form'); that indicates that this code relies on the button being inside the form. Furthermore, it is very unfortunate that the return false is ignored further up the callstack, thus losing the information of the failure to submit the form.

  • Codeception version: 2.5.2
  • PHP Version: 7.3.1
  • Operating System: Linux
  • Installation type: Composer
  • List of installed packages
behat/gherkin                      v4.6.0  Gherkin DSL parser for PHP 5.3
codeception/codeception            2.5.2   BDD-style testing framework
codeception/phpunit-wrapper        7.6.1   PHPUnit classes used by Codeception
codeception/stub                   2.0.4   Flexible Stub wrapper for PHPUnit's Mock Builder
doctrine/instantiator              1.1.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
facebook/webdriver                 1.6.0   A PHP client for Selenium WebDriver
guzzlehttp/guzzle                  6.3.3   Guzzle is a PHP HTTP client library
guzzlehttp/promises                v1.3.1  Guzzle promises library
guzzlehttp/psr7                    1.5.2   PSR-7 message implementation that also provides common utility methods
myclabs/deep-copy                  1.8.1   Create deep copies (clones) of your objects
phar-io/manifest                   1.0.3   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    2.0.1   Library for handling version information and constraints
phpdocumentor/reflection-common    1.0.1   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  4.3.0   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver        0.4.0
phpspec/prophecy                   1.8.0   Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          6.1.4   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          2.0.2   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1   Simple template engine.
phpunit/php-timer                  2.0.0   Utility class for timing
phpunit/php-token-stream           3.0.1   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    7.5.3   The PHP Unit Testing framework.
psr/http-message                   1.0.1   Common interface for HTTP messages
ralouphie/getallheaders            2.0.5   A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup 1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator               3.0.2   Provides the functionality to compare PHP values for equality
sebastian/diff                     3.0.1   Diff implementation
sebastian/environment              4.1.0   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 3.1.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state             2.0.0   Snapshotting of global state
sebastian/object-enumerator        3.0.3   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         1.1.1   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        3.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations      2.0.1   Provides a list of PHP built-in functions that operate on resources
sebastian/version                  2.0.1   Library that helps with managing the version number of Git-hosted PHP projects
symfony/browser-kit                v4.2.2  Symfony BrowserKit Component
symfony/console                    v4.2.2  Symfony Console Component
symfony/contracts                  v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/css-selector               v4.2.2  Symfony CssSelector Component
symfony/dom-crawler                v4.2.2  Symfony DomCrawler Component
symfony/event-dispatcher           v4.2.2  Symfony EventDispatcher Component
symfony/finder                     v4.2.2  Symfony Finder Component
symfony/polyfill-ctype             v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-mbstring          v1.10.0 Symfony polyfill for the Mbstring extension
symfony/process                    v4.2.2  Symfony Process Component
symfony/yaml                       v4.2.2  Symfony Yaml Component
theseer/tokenizer                  1.1.0   A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                   1.4.0   Assertions to validate method input/output with nice error messages.
  • Suite configuration:
actor: AcceptanceTester
modules:
    enabled:
        - PhpBrowser:
            url: http://localhost:8080/<redacted>
        - \Helper\Acceptance
        - Db:
                dsn: 'mysql:host=localhost:33060;dbname=db'
                populator: 'mysql -h localhost -P 33060 --protocol tcp -u $user --password=$password $dbname < $dump'
                user: '<redacted>'
                password: '<redacted>'
                dump: 
                    - '<redacted>'
                populate: true
                reconnect: false
                waitlock: 10

Activity

  1. changed the title [-]AcceptanceTester::click does not work with button outside form[/-] [+]$I->click does not work with submit button outside form[/+] on Mar 5, 2019
  2. Naktibalda commented on Mar 19, 2019

    @Naktibalda
    Member

    It returns false to fix #3783

    Do you agree that throwing an appropriate exception would be a better fix than ignoring click?

  3. martin-schulze-vireso commented on Mar 20, 2019

    @martin-schulze-vireso
    Author

    Obviously, I would prefer to have the form submitted. Lacking that, I think the exception is the best way because it isn't as easily ignored as a returned false.

  4. added a commit that references this issue on Apr 23, 2019
    b7ecd5f
  5. added a commit that references this issue on Apr 23, 2019
    b9e55f8
  6. Naktibalda commented on Jan 4, 2021

    @Naktibalda
    Member

    This issue was completely fixed in Codeception 4 by Codeception/lib-innerbrowser#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions