Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8507163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:47:29+00:00 2026-06-11T02:47:29+00:00

I want to test a page with a form which, when submitted, will redirect

  • 0

I want to test a page with a form which, when submitted, will redirect to the resulting page for the submitted item.

My Mojolicious controller contains:

sub submit_new {
    my $self = shift;

    my $new = $self->db->resultset('Item')->new( {
        title       => $self->param('title'),
        description => $self->param('description'),
    } );
    $new->insert;

    # show the newly submitted item
    my $id = $new->id;
    $self->redirect_to("/items/$id");
}

The test script for this controller contains:

use Test::More;
use Test::Mojo;

my $t = Test::Mojo->new('MyApp');

my $tx = $t->ua->build_form_tx('/items/new/submit' => $data);
$tx->req->method('POST');
$t->tx( $t->ua->start($tx) )
  ->status_is(302);

My issue is that it stops with the 302 status. How do I proceed with the redirect so I can verify the resulting item page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:47:31+00:00Added an answer on June 11, 2026 at 2:47 am

    Set the matching setting from Mojo::UserAgent:

    $t->ua->max_redirects(10)
    

    Also, you don’t need to build the form post manually:

    $t->post_form_ok('/items/new/submit' => $data)->status_is(...);
    

    Reference:

    • http://mojolicio.us/perldoc/Test/Mojo#ua
    • http://mojolicio.us/perldoc/Mojo/UserAgent#max_redirects
    • http://mojolicio.us/perldoc/Test/Mojo#post_form_ok
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div on page, which content will change by javascript, I want
Basically, we want to A/B test 2 different page layout headers. There are some
I want to get the text field test out of this web page. How
A specific page in my web application has a URL www.example.com/Test/Index However, I want
I want to test Add new item activity in my application. When user fills
I want to test if a sentence contains anything else than white-space characters. This
I have a facebook application that consists of a form which values i want
Am using Django's form for my login page. I want to set focus to
I want to create simple select menu which changes <div> layers in JSF page.
We have a browser test page which is used to diagnose user problems. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.