Another Selenium (It’s Not Just for Testing) App

As some of you may have noticed from a post I did a couple weeks back or from my Lightning Talk at the December San Francisco Selenium Meet-Up, I’m fairly intrigued by the usefulness of Selenium for non-testing purposes.  Both of these aforementioned apps were for my day job as a QA engineer.  Both involved working around what a customer perceived as a “missing feature” in our web site.

Tonight’s post is on a Selenium app to work around what I perceive to be a missing feature, in one of my favorite web sites.  I have been a huge fan of Netflix for a long time, but one thing that has annoyed me is that there doesn’t appear to be an alert feature by which I can be notified if a particular DVD becomes available (or at least Save’able via Netflix’s UI).  After a particularly bad run of luck with my movie selections lately, I suddenly started thinking how nice it would be if another season of the original Hawaii Five-O TV series (on which I am embarrassed to admit I am hooked!) might now be available.  So, I did a quick search on Netflix.  I was alternately thrilled and disgusted that another season was indeed available. I say “disgusted” because I realized Season 10 had probably been available for some time without my knowing about it.

So!  I called up NetFlix Customer Service to confirm my suspicions.  Yes, Season 10 had been available for some time.  No, there wasn’t an alert feature similar to ebay’s for saved searches.  (Why not? I repeatedly asked!)

A short while later, I whipped up the following Selenium-RC/Perl app. I am now running this from a daily cron job on my MacBook.  Whenever Season 11 becomes visible on Netflix, I’ll be among the first to notice!

#! /usr/bin/perl

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

use constant TIMEOUT => 45000;

my $desiredTitle = "hawaii five-o: season 11";
my $hit = "Hawaii Five-O: Season 11";

my $sel = Test::WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*chrome",
browser_url => "http://www.netflix.com/" );

# As guest, select link to browse movies...
$sel->open("/BrowseSelection");
my $browseLink = "link=Browse Selection";
$sel->wait_for_element_present($browseLink);
$sel->click_ok($browseLink);

# Enter the string of the desired title...
$sel->wait_for_page_to_load(TIMEOUT);
my $searchField = "searchField2";
$sel->wait_for_element_present($searchField);
$sel->type($searchField,$desiredTitle);

# Start the search...
my $goButton = "//input[\@value='Go']";
$sel->wait_for_element_present($goButton);
$sel->click_ok($goButton);

# Check the results...
$sel->wait_for_page_to_load_ok(TIMEOUT);
my $found = $sel->is_text_present($hit);

 

if ($found) {
open MAIL, "| /usr/bin/mail mamp" or die "Cannot open pipe to MAIL: $!\n";
print MAIL "$hit is available at Netflix NOW!!!";
}

$desiredTitle‘s value is lower-case while $hit‘s is title-case so that if a hit is not found, is_text_present will return false.

There is nothing of note technically about this trivial little app. What continues to impress me is how useful Selenium is as a workaround for missing web app features!

Advertisements

About Mary Ann May-Pumphrey

I'm a software QA automation engineer, focusing primarily on Selenium/Webdriver automation of the front end of web apps. View all posts by Mary Ann May-Pumphrey

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: