File Coverage

blib/lib/Appium/Ios/CanPage.pm
Criterion Covered Total %
statement 6 37 16.2
branch 0 8 0.0
condition 0 7 0.0
subroutine 2 5 40.0
pod 1 1 100.0
total 9 58 15.5


line stmt bran cond sub pod time code
1             package Appium::Ios::CanPage;
2             $Appium::Ios::CanPage::VERSION = '0.0804';
3             # ABSTRACT: Display all interesting elements for iOS, useful during test authoring
4 3     3   2059 use Moo::Role;
  3         7  
  3         22  
5 3     3   1212 use feature qw/state/;
  3         16  
  3         1715  
6              
7              
8             sub page {
9 0     0 1   my ($self) = @_;
10              
11 0           return $self->_get_page;
12             }
13              
14             sub _get_page {
15 0     0     my ($self, $element, $level) = @_;
16              
17 0   0       $element //= $self->_source_window_with_children;
18 0   0       $level //= 0;
19 0           my $indent = ' ' x $level;
20              
21             # App strings are found in an actual file in the app package
22             # somewhere, so I'm assuming we don't have to worry about them
23             # changing in the middle of our app execution. This may very well
24             # turn out to be a false assumption.
25 0           state $strings = $self->app_strings;
26              
27 0           my @details = qw/name label value hint/;
28 0 0         if ($element->{visible}) {
29 0           print $indent . $element->{type} . "\n";
30 0           foreach (@details) {
31 0           my $detail = $element->{$_};
32 0 0         if ($detail) {
33 0           print $indent . ' ' . $_ . "\t: " . $detail . "\n" ;
34              
35 0           foreach my $key (keys %{ $strings }) {
  0            
36 0           my $val = $strings->{$key};
37 0 0         if ($val =~ /$detail/) {
38 0           print $indent . ' id ' . "\t: " . $key . ' => ' . $val . "\n";
39             }
40             }
41             }
42             }
43             }
44              
45 0           $level++;
46 0           my @children = @{ $element->{children} };
  0            
47 0           foreach (@children) {
48 0           $self->_get_page($_, $level);
49             }
50             }
51              
52             sub _source_window_with_children {
53 0     0     my ($self, $index) = @_;
54 0   0       $index //= 0;
55              
56 0           my $window = $self->execute_script('UIATarget.localTarget().frontMostApp().windows()[' . $index . '].getTree()');
57 0 0         if (scalar @{ $window->{children} }) {
  0            
58 0           return $window;
59             }
60             else {
61 0           return $self->_source_window_with_children(++$index);
62             }
63             }
64              
65              
66             1;
67              
68             __END__