Test buttons or links in Mojo::Test

19 views
Skip to first unread message

yanni1...@g.ucla.edu

unread,
Dec 26, 2017, 10:52:54 PM12/26/17
to Mojolicious
Hello all,

How do I test if 
a button (e.g. <a href="?msgid=0" class="btn btn-default btn-xs" style="font-size:x-small;color:black" > do not show again</a>
or a link (e.g. <a href="/aboutus">About Us</a>
works, using Mojo::Test? I want to make sure that when the user clicks on them they can be redirected to the right page, and I want my test object to follow those links and test the content of the new page.

Thanks!

Ni

sri

unread,
Dec 27, 2017, 11:48:39 AM12/27/17
to Mojolicious
There is no built in feature for "clicking"  on links yet. We've been discussing it for some time,
but not found the right way to do it yet. You have to do it manually, or use a 3rd party module.

--
sebastian

Jan Henning Thorsen

unread,
Dec 28, 2017, 7:33:59 AM12/28/17
to Mojolicious
I've always done this manually. Something like this:

$t->get_ok('/')->status_is(200)->element_exists('a[href*="msgid"]');
$t->get_ok($t->tx->res->dom->at('a[href*="msgid"]')->{href})->status_is(302)->header_like(Location => qr{something});
$t->get_ok($t->tx->res->headers->location)->status_is(200)->element_exists_not('a[href*="msgid="]');

I like how it's dynamic, but at the same time very explicit.

yanni1...@g.ucla.edu

unread,
Dec 28, 2017, 10:00:37 PM12/28/17
to Mojolicious
Thank you all!
Reply all
Reply to author
Forward
0 new messages