| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
######### |
|
2
|
|
|
|
|
|
|
# Author: Andy Brown (setitesuk@gmail.com) |
|
3
|
|
|
|
|
|
|
package Test::WWW::Selenium::Conversion::IDE; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
997
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
43
|
|
|
6
|
1
|
|
|
1
|
|
24
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
84
|
|
|
8
|
1
|
|
|
1
|
|
1565
|
use English q{-no_match_vars}; |
|
|
1
|
|
|
|
|
2371
|
|
|
|
1
|
|
|
|
|
8
|
|
|
9
|
1
|
|
|
1
|
|
598
|
use Test::More; # this is designed to be a helper for tests, OK |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
11
|
|
|
10
|
1
|
|
|
1
|
|
288
|
use Test::WWW::Selenium; # we are going to run the tests in this |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
24
|
|
|
11
|
1
|
|
|
1
|
|
508
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use base q{Exporter}; |
|
13
|
|
|
|
|
|
|
use Readonly; Readonly::Scalar our $VERSION => 0.5; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw{ ide_to_TWS_run_from_suite_file ide_to_TWS_run_from_test_file }; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar our $DEFAULT_TIMEOUT => 50_000; |
|
18
|
|
|
|
|
|
|
Readonly::Scalar our $DEFAULT_SELENIUM_LOCATION => q{t/selenium_tests}; |
|
19
|
|
|
|
|
|
|
Readonly::Scalar our $MAX_TIMES_TO_LOOP => 20; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub ide_to_TWS_run_from_suite_file { |
|
22
|
|
|
|
|
|
|
my ( $sel, $suite_file, $sel_test_root ) = @_; |
|
23
|
|
|
|
|
|
|
$sel_test_root ||= $DEFAULT_SELENIUM_LOCATION; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $parser = XML::LibXML->new(); |
|
26
|
|
|
|
|
|
|
my $suite = $parser->parse_html_file( qq{$sel_test_root/$suite_file} ); |
|
27
|
|
|
|
|
|
|
my @tests = $suite->getElementsByTagName( q{a} ); |
|
28
|
|
|
|
|
|
|
foreach my $test ( @tests ) { |
|
29
|
|
|
|
|
|
|
my $test_file = $test->getAttribute( q{href} ); |
|
30
|
|
|
|
|
|
|
$test_file =~ s{[.]/}{}xms; |
|
31
|
|
|
|
|
|
|
ide_to_TWS_run_from_test_file( $sel, { |
|
32
|
|
|
|
|
|
|
test_file => $test_file, |
|
33
|
|
|
|
|
|
|
sel_test_root => $sel_test_root, |
|
34
|
|
|
|
|
|
|
parser => $parser, |
|
35
|
|
|
|
|
|
|
} ); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
return 1; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub ide_to_TWS_run_from_test_file { |
|
41
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
42
|
|
|
|
|
|
|
my $test_file = $args->{test_file}; |
|
43
|
|
|
|
|
|
|
my $sel_test_root = $args->{sel_test_root} || $DEFAULT_SELENIUM_LOCATION; |
|
44
|
|
|
|
|
|
|
my $parser = $args->{parser} || XML::LibXML->new(); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $test_dom = $parser->parse_html_file( qq{$sel_test_root/$test_file} ); |
|
47
|
|
|
|
|
|
|
my @title_tags = $test_dom->getElementsByTagName( q{title} ); |
|
48
|
|
|
|
|
|
|
my $title = $title_tags[0]->firstChild->nodeValue(); |
|
49
|
|
|
|
|
|
|
note qq{Running Selenium Test: '$title'}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my ($tbody) = $test_dom->getElementsByTagName( q{tbody} ); |
|
52
|
|
|
|
|
|
|
foreach my $action_set ( $tbody->getElementsByTagName( q{tr} ) ) { |
|
53
|
|
|
|
|
|
|
my ( $action, $operand_1, $operand_2 ) = $action_set->getElementsByTagName( q{td} ); |
|
54
|
|
|
|
|
|
|
foreach my $node ( $action, $operand_1, $operand_2 ) { |
|
55
|
|
|
|
|
|
|
if ( defined $node && defined $node->firstChild ) { |
|
56
|
|
|
|
|
|
|
$node = $node->firstChild->nodeValue(); |
|
57
|
|
|
|
|
|
|
} else { |
|
58
|
|
|
|
|
|
|
$node = q{}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
if ( $operand_1 =~ m{\A[(]?//}xms ) { |
|
62
|
|
|
|
|
|
|
$operand_1 = q{xpath=} . $operand_1; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
my $test_args = { |
|
65
|
|
|
|
|
|
|
action => $action, |
|
66
|
|
|
|
|
|
|
operand_1 => $operand_1, |
|
67
|
|
|
|
|
|
|
operand_2 => $operand_2, |
|
68
|
|
|
|
|
|
|
}; |
|
69
|
|
|
|
|
|
|
_ide_to_TWS_convert_to_method_and_test( $sel, $test_args); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
return 1; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _ide_to_TWS_convert_to_method_and_test { |
|
75
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my %actions = ( |
|
78
|
|
|
|
|
|
|
open => \&_ide_to_TWS_open_test, |
|
79
|
|
|
|
|
|
|
verifyTitle => \&_ide_to_TWS_verifyTitle_test, |
|
80
|
|
|
|
|
|
|
verifyText => \&_ide_to_TWS_verifyTextPresent_test, |
|
81
|
|
|
|
|
|
|
verifyTextPresent => \&_ide_to_TWS_verifyTextPresent_test, |
|
82
|
|
|
|
|
|
|
assertText => \&_ide_to_TWS_verifyTextPresent_test, |
|
83
|
|
|
|
|
|
|
assertTextPresent => \&_ide_to_TWS_verifyTextPresent_test, |
|
84
|
|
|
|
|
|
|
waitForElementPresent => \&_ide_to_TWS_waitForText, |
|
85
|
|
|
|
|
|
|
assertElementPresent => \&_ide_to_TWS_verifyTextPresent_test, |
|
86
|
|
|
|
|
|
|
clickAndWait => \&_ide_to_TWS_clickAndWait, |
|
87
|
|
|
|
|
|
|
click => \&_ide_to_TWS_clickAndWait, |
|
88
|
|
|
|
|
|
|
type => \&_ide_to_TWS_type, |
|
89
|
|
|
|
|
|
|
waitForText => \&_ide_to_TWS_waitForText, |
|
90
|
|
|
|
|
|
|
select => \&_ide_to_TWS_select, |
|
91
|
|
|
|
|
|
|
selectAndWait => \&_ide_to_TWS_select, |
|
92
|
|
|
|
|
|
|
random_alert => \&_ide_to_TWS_random_alert, |
|
93
|
|
|
|
|
|
|
); |
|
94
|
|
|
|
|
|
|
eval { |
|
95
|
|
|
|
|
|
|
$actions{$args->{action}}( $sel, $args ); |
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
} or do { |
|
98
|
|
|
|
|
|
|
diag explain $args; |
|
99
|
|
|
|
|
|
|
diag qq{\t$EVAL_ERROR}; |
|
100
|
|
|
|
|
|
|
}; |
|
101
|
|
|
|
|
|
|
return; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _ide_to_TWS_random_alert { |
|
105
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
106
|
|
|
|
|
|
|
my $alert_present = $sel->is_alert_present; |
|
107
|
|
|
|
|
|
|
my $msg = q{Random alert } . ( $alert_present ? q{} : q{not } ) . q{found} . ( $alert_present ? q{ } . $sel->get_alert : q{} ); |
|
108
|
|
|
|
|
|
|
pass($msg); |
|
109
|
|
|
|
|
|
|
return; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _ide_to_TWS_select { |
|
113
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
114
|
|
|
|
|
|
|
ok( $sel->select($args->{operand_1}, $args->{operand_2}), , qq{select $args->{operand_2} from $args->{operand_1}} ); |
|
115
|
|
|
|
|
|
|
return; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _ide_to_TWS_verifyTitle_test { |
|
119
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
120
|
|
|
|
|
|
|
is( $sel->get_title(), $args->{operand_1}, qq{Title is $args->{operand_1}} ); |
|
121
|
|
|
|
|
|
|
return; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _ide_to_TWS_waitForText { |
|
125
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
126
|
|
|
|
|
|
|
my $op1 = $args->{operand_1}; |
|
127
|
|
|
|
|
|
|
my $op2 = $args->{operand_2}; |
|
128
|
|
|
|
|
|
|
if ( $op1 && $op2 ) { |
|
129
|
|
|
|
|
|
|
note qq{waiting for text $op2 in $op1}; |
|
130
|
|
|
|
|
|
|
my $found = 0; |
|
131
|
|
|
|
|
|
|
my $count = 1; |
|
132
|
|
|
|
|
|
|
while ( ! $found && $count < $MAX_TIMES_TO_LOOP ) { |
|
133
|
|
|
|
|
|
|
$count++; |
|
134
|
|
|
|
|
|
|
eval { |
|
135
|
|
|
|
|
|
|
my $text = $sel->get_text( $op1 ); |
|
136
|
|
|
|
|
|
|
if ( $op2 =~ m/regexp/ixms ) { |
|
137
|
|
|
|
|
|
|
my ( $type, $expression ) = $op2 =~ m/(regexp[i]?):(.*)/ixms; |
|
138
|
|
|
|
|
|
|
if ( $type =~ /i/ixms ) { |
|
139
|
|
|
|
|
|
|
if ( $text =~ m/$expression/ixms ) { |
|
140
|
|
|
|
|
|
|
$found++; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
} else { |
|
143
|
|
|
|
|
|
|
if ( $text =~ m/$expression/xms ) { |
|
144
|
|
|
|
|
|
|
$found++; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
} else { |
|
148
|
|
|
|
|
|
|
if ( $text eq $op2 ) { |
|
149
|
|
|
|
|
|
|
$found++; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
} or do {}; |
|
153
|
|
|
|
|
|
|
if ( ! $found ) { |
|
154
|
|
|
|
|
|
|
sleep 1; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
$count = $count < $MAX_TIMES_TO_LOOP ? $count : $MAX_TIMES_TO_LOOP; |
|
158
|
|
|
|
|
|
|
ok( $found, qq{waiting for text $op2 in $op1 - tried $count times} ); |
|
159
|
|
|
|
|
|
|
} else { |
|
160
|
|
|
|
|
|
|
note qq{waiting for text $op1}; |
|
161
|
|
|
|
|
|
|
if ( $op1 =~ m/[id|identifier|css]=/xms ) { |
|
162
|
|
|
|
|
|
|
ok( $sel->wait_for_element_present( $op1, $DEFAULT_TIMEOUT ), qq{waiting for text $op1} ); |
|
163
|
|
|
|
|
|
|
} else { |
|
164
|
|
|
|
|
|
|
ok( $sel->wait_for_text_present( $op1, $DEFAULT_TIMEOUT ), qq{waiting for text $op1} ); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
return; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub _ide_to_TWS_type { |
|
171
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
172
|
|
|
|
|
|
|
note qq{typing $args->{operand_2} into $args->{operand_1}}; |
|
173
|
|
|
|
|
|
|
$sel->type( $args->{operand_1}, $args->{operand_2} ); |
|
174
|
|
|
|
|
|
|
return; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub _ide_to_TWS_clickAndWait { |
|
178
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
179
|
|
|
|
|
|
|
my $msg = qq{clicking $args->{operand_1}}; |
|
180
|
|
|
|
|
|
|
note $msg; |
|
181
|
|
|
|
|
|
|
my $result; |
|
182
|
|
|
|
|
|
|
my $payload; |
|
183
|
|
|
|
|
|
|
eval { $sel->click($args->{operand_1}); $result = 1; } or do { $result = 0; $payload = $EVAL_ERROR; }; |
|
184
|
|
|
|
|
|
|
ok( $result, $msg ); |
|
185
|
|
|
|
|
|
|
if ( ! $result ) { |
|
186
|
|
|
|
|
|
|
diag $payload; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
if ( $args->{action} ne q{click} ) { |
|
189
|
|
|
|
|
|
|
$msg = q{waiting for page to load}; |
|
190
|
|
|
|
|
|
|
note $msg; |
|
191
|
|
|
|
|
|
|
if ( ! $result ) { |
|
192
|
|
|
|
|
|
|
ok( 0, $msg ); # auto fail if click failed |
|
193
|
|
|
|
|
|
|
} else { |
|
194
|
|
|
|
|
|
|
ok( $sel->wait_for_page_to_load( $DEFAULT_TIMEOUT ), $msg ); |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
return; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub _ide_to_TWS_verifyTextPresent_test { |
|
201
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
202
|
|
|
|
|
|
|
my $text1 = $args->{operand_1}; |
|
203
|
|
|
|
|
|
|
my $text2 = $args->{operand_2}; |
|
204
|
|
|
|
|
|
|
if ( $text2 ) { |
|
205
|
|
|
|
|
|
|
if ( $text1) { |
|
206
|
|
|
|
|
|
|
ok( $sel->is_element_present($text1), qq{element $text1 present on page} ); |
|
207
|
|
|
|
|
|
|
if ( $text2 !~ m/\A[[:lower:]]+:/ixms || $text2 =~ m/\Aexact:/ixms ) { |
|
208
|
|
|
|
|
|
|
$text2 =~ s/exact://ixms; |
|
209
|
|
|
|
|
|
|
is( $sel->get_text($text1), $text2, qq{element $text1 has text of $text2} ); |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
} else { |
|
213
|
|
|
|
|
|
|
if ( $text1 =~ m/=/xms ) { |
|
214
|
|
|
|
|
|
|
ok( $sel->is_element_present($text1), qq{element $text1 present on page} ); |
|
215
|
|
|
|
|
|
|
} else { |
|
216
|
|
|
|
|
|
|
like( $sel->get_body_text, qr{$text1}, qq{body text contains $text1} ); ## no critic (RegularExpressions::RequireDotMatchAnything RegularExpressions::RequireExtendedFormatting RegularExpressions::RequireLineBoundaryMatching) |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
return; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub _ide_to_TWS_open_test { |
|
223
|
|
|
|
|
|
|
my ( $sel, $args ) = @_; |
|
224
|
|
|
|
|
|
|
my $page = $args->{operand_1}; |
|
225
|
|
|
|
|
|
|
$sel->open_ok( $page, undef, qq{open page $page} ); |
|
226
|
|
|
|
|
|
|
return |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1; |
|
230
|
|
|
|
|
|
|
__END__ |