IEAutomation/Table.pm untested

filter: Statementstmt 0.0% 0 / 112 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 185 CC 18 SCAR 27.8
CC
18
Cov
0%
tableCells
30.0
getRowHavingText
30.0
rows
20.0
CRAP 16.2
1 package Win32::IEAutomation::Table;
2
3 use strict;
4 use vars qw($VERSION $warn);
5 $VERSION = '0.5';
6
7 sub new {
8 my $class = shift;
9 my $self = { };
10 $self->{element} = undef;
11 $self->{parent} = undef;
12 $self->{table} = undef;
13 $self->{row} = undef;
14 $self->{cell} = undef;
15 $self = bless ($self, $class);
16 return $self;
17 }
18
19 sub rows{
20 my ($self, $row_num) = @_;
21 my @rows;
22 if ($row_num){
23 my $table_object = Win32::IEAutomation::Table->new();
24 $table_object->{parent} = $self->{parent};
25 $table_object->{row} = $self->{table}->rows($row_num - 1);
26 return $table_object if $table_object->{row};
27 }else{
28 my $rows_coll = $self->{table}->rows;
29 foreach (my $n = 0; $n < $rows_coll->length; $n++){
30 my $table_object = Win32::IEAutomation::Table->new();
31 $table_object->{parent} = $self->{parent};
32 $table_object->{row} = $rows_coll->item($n);
33 push (@rows, $table_object) if $table_object->{row};
34 }
35 return @rows;
36 }
37 }
38
39 sub cells{
40 my ($self, $cell_num) = @_;
41 my @cells;
42 if ($cell_num){
43 my $table_object = Win32::IEAutomation::Table->new();
44 $table_object->{parent} = $self->{parent};
45 $table_object->{cell} = $self->{row}->cells($cell_num - 1);
46 return $table_object if $table_object->{cell};
47 }else{
48 my $cells_coll = $self->{row}->cells;
49 foreach (my $n = 0; $n < $cells_coll->length; $n++){
50 my $table_object = Win32::IEAutomation::Table->new();
51 $table_object->{parent} = $self->{parent};
52 $table_object->{cell} = $cells_coll->item($n);
53 push (@cells, $table_object) if $table_object->{cell};
54 }
55 return @cells;
56 }
57 }
58
59 sub tableCells{
60 my ($self, $row_num, $col_num) = @_;
61 my @cells;
62 if ($row_num && $col_num){
63 my $row = $self->rows($row_num);
64 my $cell = $row->cells($col_num) if $row;
65 return $cell if $cell;
66 }else{
67 my $cells_coll = $self->{table}->cells;
68 foreach (my $n = 0; $n < $cells_coll->length; $n++){
69 my $table_object = Win32::IEAutomation::Table->new();
70 $table_object->{parent} = $self->{parent};
71 $table_object->{cell} = $cells_coll->item($n);
72 push (@cells, $table_object) if $table_object->{cell};
73 }
74 return @cells;
75 }
76 }
77
78
79 sub getRowHavingText{
80 my ($self, $string) = @_;
81 my $regex_flag = 1 if ($string =~ /^?-xism:/);
82 my @rows = $self->rows;
83 foreach my $row (@rows){
84 my @cells = $row->cells;
85 foreach my $cell (@cells){
86 if ($regex_flag){
87 return $row if ($cell->cellText =~ $string);
88 }else{
89 return $row if ($cell->cellText eq $string);
90 }
91 }
92 }
93 return undef;
94 }
95
96 sub cellText{
97 my $self = shift;
98 my $text = $self->{cell}->outertext;
99 return trim_white_spaces($text);
100 }
101
102 sub getLink{
103 my ($self, $how, $what) = @_;
104 return __getElement($self, $how, $what, "a");
105 }
106
107 sub getImage{
108 my ($self, $how, $what) = @_;
109 return __getElement($self, $how, $what, "img");
110 }
111
112 sub getButton{
113 my ($self, $how, $what) = @_;
114 return __getElement($self, $how, $what, "input", "button");
115 }
116
117 sub getRadio{
118 my ($self, $how, $what) = @_;
119 return __getElement($self, $how, $what, "input", "radio");
120 }
121
122 sub getCheckbox{
123 my ($self, $how, $what) = @_;
124 return __getElement($self, $how, $what, "input", "checkbox");
125 }
126
127 sub getSelectList{
128 my ($self, $how, $what) = @_;
129 return __getElement($self, $how, $what, "select", "select-one|select-multiple");
130 }
131
132 sub getTextBox{
133 my ($self, $how, $what) = @_;
134 return __getElement($self, $how, $what, "input", "text|password");
135 }
136
137 sub getTextArea{
138 my ($self, $how, $what) = @_;
139 return __getElement($self, $how, $what, "textarea", "textarea");
140 }
141
142 sub __getElement{
143 my ($self, $how, $what, $tag, $type) = @_;
144 my $cell = $self->{cell};
145 my $collection = $cell->all->tags($tag);
146 my $target_element = Win32::IEAutomation::__getObject($collection, $how, $what, $type) if ($collection);
147 my $element_object;
148 if ($target_element){
149 $element_object = Win32::IEAutomation::Element->new();
150 $element_object->{element} = $target_element;
151 $element_object->{parent} = $self->{parent};
152 }else{
153 $element_object = undef;
154 print "WARNING: No element is present in the document with your specified option $how $what\n" if $warn;
155 }
156 return $element_object;
157 }
158
159 sub trim_white_spaces{
160 my $string = shift;
161 $string =~ s/^\s+//;
162 $string =~ s/\s+$//;
163 return $string;
164 }
165
166 1;
167 __END__