A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label record. Show all posts
Showing posts with label record. Show all posts

Recording HTTP responses with Perl

There are two main ways. If your HTTP requests are being done in a different way, you will need to build your own solution.

The LWP way:

use LWP::UserAgent::Mockable;

BEGIN {
    # Options: record|playback|passthrough
    $ENV{LWP_UA_MOCK}      ||= 'playback';
    $ENV{LWP_UA_MOCK_FILE} ||= "$0-lwp-mock.out";
}

END {
    LWP::UserAgent::Mockable->finished();
}

# You might be able to normalise the requests using the callbacks

The Mojo way:

use Mojo::UserAgent::Mockable;

my $mock_ua = Mojo::UserAgent::Mockable->new(
    mode        => $ENV{MOJO_UA_MOCK},
    file        => "$0-mojo-ua-mock.out",
#    ignore_body => 1,
# or:
    request_normalizer => sub {
        my ( $req, $recorded_req ) = @_; 

        my ($time) = $recorded_req->body =~ m{};
        my ($hash) = $recorded_req->body =~ m{(.*)};

        my $body = $req->body;
        $body =~ s{}{};
        $body =~ s{.*}{$hash};

        $req->body($body);
    },  

);

END {
    $mock_ua->save if $ENV{MOJO_UA_MOCK} eq 'record';
}

ok my $t = Test::Mojo->new("My::App");

$t->app->mock( useragent => sub { $mock_ua } );

# Configure the proxy in record/passthrough mode only
if ( $MODE =~ /record|passthrough/ ) { 
    local $ENV{HTTPS_PROXY} = $t->app->config->{http_proxy};
    local $ENV{HTTP_PROXY}  = $t->app->config->{http_proxy};
    my $proxy = Mojo::UserAgent::Proxy->new;
    $proxy->detect;
    $mock_ua->proxy( $proxy );
}

Macro recorders for Windows 7

Testing on Windows 7 Pro (SP1), in a Virtual Box (VM) window, running under Ubuntu 11.04.
  • AutoHotKey - scripting only, but users have built a recorder too.
    • Overall good. Free.
    • Steep learning curve, but users on IRC channel are very helpful
    • Note: Trying running program in "Administrator mode" if it doesn't seem to work.
    • How to develop scripts:
      • Use Recorder to get basic outline
      • Use included Window Spy to get precise coords (set "CoordMode, Mouse, Screen")
      • May need to fiddle with WinActivate parameters
      • Put sections of functionality into subroutines and test them individually
      • Use TrayTips as debug output
      • Make sure you make the script Sleep for at least 300ms between each action
  • Quick Macro - Couldn't get it to work. Shareware.
  • Auto Macro Recorder - Couldn't get it to work, either. Shareware.
  • PC Anywhere - Couldn't even download it.

Record and playback macros in vi

qN - start recording, where N is a-z
@N - play back your recording, where N is a-z
@@ play back the same recording again