Search code examples
phplaravellaravel-dusk

Dusk does not handle POST requests the same way Laravel does when testing a form submission


When running tests in Dusk, submitting a form generates a validation error that reads "The query field is required." The error does not occur when testing the page with manual input.

I added dd( $request ) to the first line of the controller method that handles the POST request. When I test the page manually, the system dumps the request to the page. When I test the page with Dusk, I get a screenshot that shows the line of code was never executed: The page reloads with the validation error.

I have searched the form for a hidden input with a name of 'query.' It does not exist.

I have searched the controller class and base classes for any validations that test the 'query' input. I have found none.

Can anyone point me in the right direction to figure out why the page does not work in the automated testing environment, when it does work using the serve command?

Has anyone seen a similar error in the past?

Image shows the screen shot after Dusk clicks "Save" and submits the form. Test fails, because an unknown validation occurs before the App calls the controller.


Solution

  • Short Answer: Check the page to verify that the selector is grabbing the correct form. In this case, the tester forgot that a form existed in the menu bar. The test was clicking the button in the menu bar instead of in the main page content.

    Original Text: I guess sometimes you just need to walk away and come back to the problem. I was so focused on the form at the center of the page that I overlooked the form in the menu bar that has an input with the name 'query'.

    I was clicking the wrong button with my Dusk commands, because my selector applied to multiple buttons on separate forms.