New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selected value is ignored when `selectOption` is combined with `fillField` #3953

Closed
ruudvanderweijde opened this Issue Jan 25, 2017 · 6 comments

Comments

Projects
None yet
3 participants
@ruudvanderweijde

ruudvanderweijde commented Jan 25, 2017

What are you trying to achieve?

I want to select a value in a dropdown, and fill a text field and submit the form.

What do you get instead?

The dropdown value is reset when the form is submitted.

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

 I see "select=two,search=searchterm"
 FAIL

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 2.48 seconds, Memory: 10.00MB

There was 1 failure:

---------
1) TestCest: some Test
 Test  tests/acceptance/TestCest.someTest
 Step  See "select=two,search=searchterm"
 Fail  Failed asserting that  on page /test?select_name=one&search_name=searchterm
-->  first second Submit select=one,search=searchterm /* 1) { setTimeout(function(){ options.maxTries--; request(url, onSuccess, onError, payload, options); }, 500); return null; } if (200 === xhr.status) { (onSuccess || noop)(xhr); } else { (onError || noop)(xhr); } }; xhr.send(payload || ''); }, getPr
[Content too long to display. See complete response in '.../tests/_output/' directory]
--> contains "select=two,search=searchterm".

Scenario Steps:

 5. $I->see("select=two,search=searchterm") at tests/acceptance/TestCest.php:21
 4. $I->click("Submit") at tests/acceptance/TestCest.php:20
 3. $I->fillField("search_name","searchterm") at tests/acceptance/TestCest.php:19
 2. $I->selectOption("select_name","two") at tests/acceptance/TestCest.php:18
 1. $I->amOnPage("/test") at tests/acceptance/TestCest.php:16

Provide test source code if related

    public function someTest(AcceptanceTester $I)
    {
        $I->amOnPage('/test');

        $I->selectOption('select_name', 'two');
        $I->fillField('search_name', 'searchterm');
        $I->click('Submit');

        $I->see('select=two,search=searchterm');
    }
<html>
<body>
<form action="/test">
    <select name="select_name" id="select_id">
        <option value="one">first</option>
        <option value="two">second</option>
    </select>
    <input type="text" name="search_name">
    <button>Submit</button>
</form>
{{ output|default('') }}
</body>
</html>
Controller action:

    public function testAction(Request $request)
    {
        $output = []; 
        $select = $request->get('select_name');
        $search = $request->get('search_name');
        if ($select) {
            $output[] = 'select=' . $select;
        }
        if ($search) {
            $output[] = 'search=' . $search;
        }

        return $this->render('test.html.twig', ['output' => implode(',', $output)]);
    }

Details

  • Codeception version: 2.2.8
  • PHP Version: 7.1
  • Operating System: Ubuntu 14.04.5 LTS
  • Installation type: Composer
  • List of installed packages (composer show)
  • Suite configuration:
class_name: AcceptanceTester
modules:
    enabled:
        - AcceptanceHelper:
            ... parameters

env:
    php:
        modules:
            enabled:
                - AcceptanceHelper
                - PhpBrowser:
                    url: 'somebaseurl'

Order of statements

This worked fine in version 2.2.7.
I've managed to work around the problem in 2.2.8 by changing the order of selectOption and fillField:

        $I->fillField('search_name', 'searchterm');
        $I->selectOption('select_name', 'two');
 I see "select=two,search=searchterm"
 PASSED
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jan 26, 2017

Member

Probably it was caused by #3825 ?
@JorisVanEijden Could you check it?

Member

Naktibalda commented Jan 26, 2017

Probably it was caused by #3825 ?
@JorisVanEijden Could you check it?

@JorisVanEijden

This comment has been minimized.

Show comment
Hide comment
@JorisVanEijden

JorisVanEijden Jan 26, 2017

Contributor

I checked, it's not caused by my PR.
I added the test and it fails both with my code change and without it.
In the first case select_name is 'one', in the second case it's ''.

Potentially interesting fact: it works fine when the form uses POST, but fails with GET.

Contributor

JorisVanEijden commented Jan 26, 2017

I checked, it's not caused by my PR.
I added the test and it fails both with my code change and without it.
In the first case select_name is 'one', in the second case it's ''.

Potentially interesting fact: it works fine when the form uses POST, but fails with GET.

@ruudvanderweijde

This comment has been minimized.

Show comment
Hide comment
@ruudvanderweijde

ruudvanderweijde Jan 26, 2017

The other interesting fact is that this worked fine in 2.2.7 (I wrote this before, but could be helpful for anyone trying to find the problem)

ruudvanderweijde commented Jan 26, 2017

The other interesting fact is that this worked fine in 2.2.7 (I wrote this before, but could be helpful for anyone trying to find the problem)

@JorisVanEijden

This comment has been minimized.

Show comment
Hide comment
@JorisVanEijden

JorisVanEijden Jan 26, 2017

Contributor

Rolling back commit 4f6e2ed fixes this issue.
So it looks like it's caused by PR #3873

Contributor

JorisVanEijden commented Jan 26, 2017

Rolling back commit 4f6e2ed fixes this issue.
So it looks like it's caused by PR #3873

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jan 26, 2017

Member

This issue only happens when GET method is used, POST works correctly.

Member

Naktibalda commented Jan 26, 2017

This issue only happens when GET method is used, POST works correctly.

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Jan 26, 2017

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Jan 26, 2017

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jan 26, 2017

Member

This issue only happens when form uses GET method and has no id
https://github.com/Codeception/Codeception/blob/2.2.8/src/Codeception/Lib/InnerBrowser.php#L852-L856

$action = (string)$this->getFormUrl($form);
$identifier = $form->attr('id') ?: $action;
if (!isset($this->forms[$identifier])) {
    $this->forms[$identifier] = $this->getFormFromCrawler($form, $action);
}

getFormUrl calls \Symfony\Component\DomCrawler\Form::getUri which adds names and values of input fields to uri when GET method is used.
I fixed it by using form action attribute as identifier.

Member

Naktibalda commented Jan 26, 2017

This issue only happens when form uses GET method and has no id
https://github.com/Codeception/Codeception/blob/2.2.8/src/Codeception/Lib/InnerBrowser.php#L852-L856

$action = (string)$this->getFormUrl($form);
$identifier = $form->attr('id') ?: $action;
if (!isset($this->forms[$identifier])) {
    $this->forms[$identifier] = $this->getFormFromCrawler($form, $action);
}

getFormUrl calls \Symfony\Component\DomCrawler\Form::getUri which adds names and values of input fields to uri when GET method is used.
I fixed it by using form action attribute as identifier.

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