Changeset 1674

Show
Ignore:
Timestamp:
07/08/08 17:17:35 (5 months ago)
Author:
kindlund
Message:

Initial support for selenium.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-selenium/etc/honeyclient.xml

    r1649 r1674  
    8686                20 
    8787            </timeout> 
     88            <selenium_enable description="If set to 1, then the Agent will attempt to drive the application using Selenium. Otherwise, Win32::Job will be used." default="1"> 
     89                1 
     90            </selenium_enable> 
    8891            <Browser> 
    8992                <IE> 
     
    9598                        iexplore.exe 
    9699                    </process_name> 
     100                    <selenium_driver description="The corresponding Selenium browser name to use for this driver." default="*iehta"> 
     101                        *iehta 
     102                    </selenium_driver> 
    97103                </IE> 
    98104                <FF> 
     
    104110                        firefox.exe 
    105111                    </process_name> 
     112                    <selenium_driver description="The corresponding Selenium browser name to use for this driver." default="*chrome"> 
     113                        *chrome 
     114                    </selenium_driver> 
    106115                </FF> 
    107116            </Browser> 
  • honeyclient/branches/exp/kindlund-selenium/lib/HoneyClient/Agent.pm

    r1499 r1674  
    278278use Data::Dumper; 
    279279 
     280# Make sure WWW::Selenium loads. 
     281BEGIN { use_ok('WWW::Selenium') or diag("Can't load WWW::Selenium package.  Check to make sure the package library is correctly listed within the path."); } 
     282require_ok('WWW::Selenium'); 
     283use WWW::Selenium; 
     284 
    280285BEGIN { 
    281286 
     
    321326use HoneyClient::Util::Config qw(getVar); 
    322327 
     328# Include Selenium Library 
     329use WWW::Selenium; 
     330 
    323331# Include Dumper Library 
    324332use Data::Dumper; 
     
    345353 
    346354# Complete URL of SOAP server, when initialized. 
    347 our $URL_BASE       = undef; 
    348 our $URL            = undef; 
     355our $URL_BASE        = undef; 
     356our $URL            = undef; 
    349357 
    350358# The process ID of the SOAP server daemon, once created. 
    351 our $DAEMON_PID     = undef; 
     359our $DAEMON_PID      = undef; 
     360 
     361# Global handle to the Selenium server. 
     362our $SELENIUM        = undef; 
     363 
     364# Global reference to the driver of the Selenium handle. 
     365our $SELENIUM_DRIVER = undef; 
    352366 
    353367####################################################################### 
     
    465479        } 
    466480 
     481        # Initialize SOAP Server. 
    467482        our $daemon = getServerHandle(address => $args{'address'}, 
    468483                                      port    => $args{'port'}); 
     
    603618 
    604619 { 
    605      # Status information about the Win32::Job
     620     # Status information about the Win32::Job, if used
    606621     'status' => { 
    607622         # The PID of the job, when it was ran. 
     
    13861401    }; 
    13871402 
     1403    if (getVar(name => "selenium_enable", 
     1404               namespace => "HoneyClient::Agent::Driver")) { 
     1405        
     1406        # Destroy the existing Selenium handle, if our driver changes.      
     1407        if (defined($SELENIUM) && 
     1408            ($SELENIUM_DRIVER ne $args{'driver_name'})) { 
     1409            $SELENIUM->stop(); 
     1410            $SELENIUM = undef; 
     1411        } 
     1412 
     1413        # Create a new Selenium handle, if need be. 
     1414        if (!defined($SELENIUM)) { 
     1415 
     1416            $SELENIUM = WWW::Selenium->new( 
     1417                host => "localhost", 
     1418                port => 4444, 
     1419                browser => getVar(name => "selenium_driver", 
     1420                                  namespace => $args{'driver_name'}), 
     1421                browser_url => "http://localhost", 
     1422            ); 
     1423            $SELENIUM_DRIVER = $args{'driver_name'}; 
     1424         
     1425            $SELENIUM->start(); 
     1426            $SELENIUM->set_timeout($args{'timeout'} * 1000); 
     1427            $SELENIUM->open("/"); 
     1428            $SELENIUM->window_maximize(); 
     1429            $SELENIUM->window_focus(); 
     1430        } 
     1431 
     1432        $LOG->info($args{'driver_name'} . " - Driving To Resource: " . $args{'parameters'}); 
     1433        eval { 
     1434            $SELENIUM->open($args{'parameters'}); 
     1435        }; 
     1436        if ($@) { 
     1437            # TODO: This may occur when timeouts hit -- which isn't fatal. 
     1438            $LOG->error("Error: Unable to drive application. " . $@); 
     1439            # TODO: Is this needed? 
     1440            $SELENIUM->stop(); 
     1441            die SOAP::Fault->faultcode(__PACKAGE__ . "->drive()") 
     1442                           ->faultstring("Error: Unable to drive application. " . $@); 
     1443        } 
     1444 
     1445    } else { 
     1446### TODO: START 
     1447 
    13881448    # Create a new Job. 
    13891449    my $job = Win32::Job->new(); 
     
    14441504    if ($status->{$processID}->{'exitcode'} != 293) { 
    14451505        $LOG->warn("Unexpected: '" . $processName . "' process (ID = " . $processID . ") terminated early!"); 
     1506    } 
     1507 
     1508### TODO: END 
    14461509    } 
    14471510