RT 6.0.3 Documentation

RT::Test::Playwright

NAME

RT::Test::Playwright - Playwright-based browser testing for RT

SYNOPSIS

    use RT::Test tests => undef, playwright => 1;

    my ($url, $p) = RT::Test->started_ok;
    $p->login('root', 'password');
    $p->get_ok('/Ticket/Create.html?Queue=1');
    $p->text_contains('Create a new ticket');
    $p->logout();

DESCRIPTION

This module provides Playwright-based browser testing for RT, replacing the Selenium implementation with modern, reliable browser automation.

ENVIRONMENT VARIABLES

RT_TEST_PLAYWRIGHT_HEADLESS

Set to 0 to run browser in non-headless mode for debugging. Default: 1

When set to 0, you can see the browser window and watch tests execute, which is helpful for debugging test failures or understanding page interactions.

RT_TEST_PLAYWRIGHT_BROWSER

Browser type to use: 'firefox', 'chromium', or 'webkit'. Default: firefox

Firefox is the default as it has been tested most extensively with RT. Chromium and WebKit should also work but may require additional testing.

METHODS

new

Constructor. Creates new Playwright instance with browser, context, and page.

rt_base_url

Return the base URL for the RT test server.

get_ok

Navigate to URL with test assertion. Handles relative URLs and waits for HTMX to complete.

    $p->get_ok('/Ticket/Display.html?id=1');
    $p->get_ok($base_url . '/path');

wait_for_htmx

Wait for HTMX requests to complete. Called automatically by get_ok.

wait_for_element

Wait for the element to show up.

wait_for_notifications

Wait for jGrowl notifications to show up.

title_is

Assert page title matches expected value.

    $p->title_is('RT at a glance');

text_contains

Assert page contains text.

    $p->text_contains('Ticket created', 'Success message appears');

text_lacks

Assert page does not contain text.

    $p->text_lacks('Error', 'No errors on page');

get_body

Get page body content as text.

    my $text = $p->get_body();

content_like

Assert page content matches regex pattern. Provided for compatibility.

    $p->content_like(qr/some pattern/, 'Pattern found');

content_unlike

Assert page content does not match regex pattern. Provided for compatibility.

    $p->content_unlike(qr/some pattern/, 'Pattern not found');

login

Log in as user. Defaults to root/password.

    $p->login();
    $p->login('alice', 'password123');

logged_in_as

Perform login with given credentials. Used by login().

logout

Log out current user.

    $p->logout();

submit_form_ok

Submit a form with specified fields and button.

    $p->submit_form_ok(
        {
            form_name => 'BuildQuery',
            fields    => {
                ValueOfAttachment => 'ticket foo',
            },
            button => 'DoSearch',
        },
        'Search tickets'
    );

close_jgrowl

Close jGrowl notification messages.

    $p->close_jgrowl();

current_url_is

Assert current URL matches expected value.

    $p->current_url_is($url, 'On expected page');

current_url_isnt

Assert current URL does not match expected value.

    $p->current_url_isnt($url, 'Not on that page');

current_url_like

Assert current URL matches regex pattern.

    $p->current_url_like(qr/Ticket\/Display/, 'On ticket display page');

content_contains

Assert page content contains text. Alias for text_contains.

    $p->content_contains('Success message');

get

Navigate to URL without test assertion.

    $p->get($url);

text_like

Assert page text matches regex pattern.

    $p->text_like(qr/Ticket \d+ created/, 'Ticket created message found');

text_unlike

Assert page text does not match regex pattern.

    $p->text_unlike(qr/Error/, 'No error messages');

goto_create_ticket

Navigate to ticket create page for specified queue.

    $p->goto_create_ticket(1);              # Queue ID
    $p->goto_create_ticket($queue_obj);     # Queue object
    $p->goto_create_ticket('General');      # Queue name

goto_ticket

Navigate to a ticket display page.

    $p->goto_ticket($ticket_id);
    $p->goto_ticket($ticket_id, 'Update');  # Go to update page instead

find_element

Find element by XPath. Returns first matching locator or dies if not found.

    my $elem = $p->find_element('//div[@class="foo"]');

dom

Get Mojo::DOM object for HTML parsing. Provided for compatibility.

    my $dom = $p->dom();
    my $text = $dom->at('div.ticket-info')->text;
← Back to index