IEAutomation/WinClicker.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 126 CC 18 SCAR 26.9
CC
18
Cov
0%
new
20.0
push_security_alert_yes
20.0
push_button_yes
20.0
CRAP 14.7
1 package Win32::IEAutomation::WinClicker;
2
3 use strict;
4 use vars qw($VERSION $warn);
5 $VERSION = '0.5';
6
7 sub new {
8 my $class = shift;
9 my %options = @_;
10 if (exists $options{warnings}){
11 $warn = $options{warnings};
12 }
13 my $self = { };
14 $self->{autoit} = Win32::OLE->new("AutoItX3.Control");
15 unless ($self->{autoit}){
16 my $autoitx_dll = find_autoitx_dll();
17 if ($autoitx_dll){
18 register_autoitx_dll($autoitx_dll);
19 $self->{autoit} = Win32::OLE->new("AutoItX3.Control") || die "Could not start AutoItX3 Control through OLE\n";
20 }else{
21 print "ERROR: AutoItX3.dll is not present in the module\n";
22 exit;
23 }
24 }
25 $self = bless ($self, $class);
26 return $self;
27 }
28
29 sub find_autoitx_dll{
30 foreach my $libdir (@INC){
31 my $dllpath = "$libdir/Win32/IEAutomation/AutoItX3.dll";
32 if (-e $dllpath){
33 return $dllpath;
34 }
35 }
36 }
37
38 sub register_autoitx_dll{
39 my $dll = shift;
40 system ("regsvr32 /s $dll");
41 }
42
43 sub push_security_alert_yes{
44 my ($self, $wait) = @_;
45 $wait = 5 unless $wait;
46 my $window = $self->{autoit}->WinWait("Security Alert", "", $wait);
47 if ($window){
48 $self->{autoit}->WinActivate("Security Alert");
49 $self->{autoit}->Send('!y');
50 }else{
51 print "WARNING: No Security Alert dialog is present. Function push_security_alert_yes is timed out.\n" if $warn;
52 }
53 }
54
55 sub push_confirm_button_ok{
56 my ($self, $title, $wait) = @_;
57 $wait = 5 unless $wait;
58 my $window = $self->{autoit}->WinWait($title, "", $wait);
59 if ($window){
60 $self->{autoit}->WinActivate($title);
61 $self->{autoit}->Send('{ENTER}');
62 }
63 }
64
65 sub push_button_yes{
66 my ($self, $title, $wait) = @_;
67 $wait = 5 unless $wait;
68 my $window = $self->{autoit}->WinWait($title, "", $wait);
69 if ($window){
70 $self->{autoit}->WinActivate($title);
71 $self->{autoit}->Send('!y');
72 }else{
73 print "WARNING: No dialog is present with title: $title. Function push_button_yes is timed out.\n" if $warn;
74 }
75 }
76
77 sub push_confirm_button_cancle{
78 my ($self, $title, $wait) = @_;
79 $wait = 5 unless $wait;
80 my $window = $self->{autoit}->WinWait($title, "", $wait);
81 if ($window){
82 $self->{autoit}->WinActivate($title);
83 $self->{autoit}->Send('{ESCAPE}');
84 }
85 }
86
87 sub logon{
88 my ($self, $title, $user, $password, $wait) = @_;
89 $wait = 5 unless $wait;
90 my $window = $self->{autoit}->WinWait($title, "", $wait);
91 if ($window){
92 $self->{autoit}->WinActivate($title);
93 $self->{autoit}->Send($user);
94 $self->{autoit}->Send('{TAB}');
95 $self->{autoit}->Send($password);
96 $self->{autoit}->Send('{ENTER}');
97 }else{
98 print "WARNING: No logon dialog is present with title \'$title\'. Function logon is timed out.\n" if $warn;
99 }
100 }
101
102 sub maximize_ie{
103 my ($self, $title) = @_;
104 $self->{autoit}->AutoItSetOption("WinTitleMatchMode", 2);
105 $self->{autoit}->WinSetState("Microsoft Internet Explorer", "", $self->{autoit}->SW_MAXIMIZE);
106 $self->{autoit}->AutoItSetOption("WinTitleMatchMode", 1);
107 }
108
109
110 1;
111 __END__