| 1 | package Test::WWW::Selenium::Sencha; | ||
| 2 | |||
| 3 | BEGIN { | ||
| 4 | $Test::WWW::Selenium::Sencha::AUTHORITY = 'cpan:PLYTLE'; | ||
| 5 | } | ||
| 6 | BEGIN { | ||
| 7 | $Test::WWW::Selenium::Sencha::VERSION = '0.001'; | ||
| 8 | } | ||
| 9 | |||
| 10 | use Moose; | ||
| 11 | use namespace::clean; | ||
| 12 | use MooseX::NonMoose; | ||
| 13 | use Test::More; | ||
| 14 | use Test::Exception; | ||
| 15 | use Test::WWW::Selenium::Sencha::Component; | ||
| 16 | use Data::Dumper; | ||
| 17 | |||
| 18 | extends 'Test::WWW::Selenium'; | ||
| 19 | |||
| 20 | =pod | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | Test::WWW::Selenium::Sencha - Selenium-based testing for Sencha apps | ||
| 25 | |||
| 26 | =head1 VERSION | ||
| 27 | |||
| 28 | version 0.001 | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | #!/usr/bin/perl | ||
| 33 | #(sometest.t) | ||
| 34 | |||
| 35 | use Test::WWW::Selenium::Sencha; | ||
| 36 | |||
| 37 | my $sel = Test::WWW::Selenium::Sencha->new( host => 'localhost', | ||
| 38 | port => 4444, | ||
| 39 | browser_url => 'http://127.0.0.1:3000/' ); | ||
| 40 | |||
| 41 | ... | ||
| 42 | |||
| 43 | $sel->click_grid_tbar('testname',0); | ||
| 44 | |||
| 45 | =head1 DESCRIPTION | ||
| 46 | |||
| 47 | Adds Sencha-specific testing methods to Test::WWW::Selenium | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | =head1 AUTHORS | ||
| 52 | |||
| 53 | Created by: Pete Lytle <plytle@cpan.org> | ||
| 54 | |||
| 55 | =head1 COPYRIGHT AND LICENSE | ||
| 56 | |||
| 57 | Copyright (c) 2011 Pete Lytle <plytle@cpan.org> | ||
| 58 | |||
| 59 | This program is free software; you can redistribute it and/or | ||
| 60 | modify it under the same terms as Perl itself. | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | ##Get first row | ||
| 65 | #my $rowid = $s->get_eval("window.Ext.getCmp('blogpostsgrid').getEl().down('td[class*=x-grid-cell-first]').id"); | ||
| 66 | #$s->double_click('id=' . $rowid); | ||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | sub check_store_count { | ||
| 71 | my ($self, $testname, $cmpid, $expected) = @_; | ||
| 72 | |||
| 73 | my $script = "window.Ext.getCmp('" . $cmpid . "').store.getCount();"; | ||
| 74 | my $val = $self->get_eval($script); | ||
| 75 | my $passfail = is($val,$expected,$testname); | ||
| 76 | } | ||
| 77 | |||
| 78 | sub click { | ||
| 79 | my ($self, $testname, $locator) = @_; | ||
| 80 | |||
| 81 | if (!eval { $self->is_element_present($locator) }) { | ||
| 82 | diag('Not present - ' . $locator); | ||
| 83 | diag(Dumper($self->is_element_present($locator))); | ||
| 84 | fail($testname); | ||
| 85 | } | ||
| 86 | |||
| 87 | else { | ||
| 88 | $self->SUPER::click($locator); | ||
| 89 | diag('Present - ' . $locator); | ||
| 90 | pass($testname); | ||
| 91 | } | ||
| 92 | |||
| 93 | sleep 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | sub click_delete_confirm { | ||
| 97 | my ($self, $testname) = @_; | ||
| 98 | |||
| 99 | my $id = $self->get_eval("var id = window.Ext.DomQuery.selectNode('*[role=alertdialog]').id;\n" . | ||
| 100 | "window.Ext.getCmp(id).down('button').id"); | ||
| 101 | $self->click($testname,$id); | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | sub click_waitfor { | ||
| 106 | my ($self, $testname, $id, $waitfor) = @_; | ||
| 107 | $self->click('id=' . $id); | ||
| 108 | $self->wait_for($testname, $waitfor); | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | sub fill_form { | ||
| 113 | my ($self, $testname, $formid, $vals) = @_; | ||
| 114 | |||
| 115 | my $text; | ||
| 116 | foreach my $key (keys %$vals) { | ||
| 117 | $text .= $key . ': ' . "'" . $vals->{$key} . "',"; | ||
| 118 | } | ||
| 119 | |||
| 120 | chop $text; | ||
| 121 | my $script = "Ext.getCmp('" . $formid . "').form.setValues({" . $text . "});"; | ||
| 122 | $self->run_script($script); | ||
| 123 | pass($testname); | ||
| 124 | sleep 1; | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | sub getCmp { | ||
| 129 | my ($self, $id) = @_; | ||
| 130 | |||
| 131 | return Test::WWW::Selenium::Sencha::Component->new({_sencha => $self, | ||
| 132 | id => $id | ||
| 133 | }); | ||
| 134 | } | ||
| 135 | |||
| 136 | sub grid_select_all { | ||
| 137 | my ($self, $testname, $cmpid) = @_; | ||
| 138 | |||
| 139 | $self->run_script("window.Ext.getCmp('" . $cmpid . "').getSelectionModel().selectRange(0,999)"); | ||
| 140 | pass($testname); | ||
| 141 | } | ||
| 142 | |||
| 143 | sub grid_select_top_row { | ||
| 144 | my ($self, $testname, $cmpid) = @_; | ||
| 145 | my $gridid; | ||
| 146 | |||
| 147 | $self->run_script("window.Ext.getCmp(" . $gridid . "').getSelectionModel().selectRange(0,0)"); | ||
| 148 | pass($testname); | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | sub js_waitfor { | ||
| 154 | my ($self, $testname, $js, $id) = @_; | ||
| 155 | |||
| 156 | $self->run_script($js); | ||
| 157 | $self->wait_for($testname, $id); | ||
| 158 | sleep 2; | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | sub nav_waitfor { | ||
| 163 | my ($self, $testname, $nav, $waitfor_id) = @_; | ||
| 164 | $self->run_script("document.app.Nav('" . $nav . "');"); | ||
| 165 | $self->wait_for($testname,$waitfor_id); | ||
| 166 | } | ||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | sub select_combo_item { | ||
| 171 | my ($self, $testname, $comboid, $val) = @_; | ||
| 172 | $self->run_script("window.Ext.getCmp('" . $comboid . "').expand();"); | ||
| 173 | sleep 1; | ||
| 174 | $self->click($testname,'css=li:contains(' . $val . ')'); | ||
| 175 | } | ||
| 176 | |||
| 177 | |||
| 178 | sub wait_for_download { | ||
| 179 | my ($self, $testname, $filename) = @_; | ||
| 180 | |||
| 181 | my $file = '/tmp/' . $filename; | ||
| 182 | unlink($file); | ||
| 183 | |||
| 184 | WAIT: { | ||
| 185 | for (1..20) { | ||
| 186 | if (-f $file) { | ||
| 187 | diag("Looking for file $file"); | ||
| 188 | pass($testname); | ||
| 189 | last WAIT | ||
| 190 | } | ||
| 191 | sleep(1); | ||
| 192 | } | ||
| 193 | |||
| 194 | fail($testname); | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | sub wait_for { | ||
| 199 | my ($self, $testname, $id) = @_; | ||
| 200 | |||
| 201 | # my $string; | ||
| 202 | # if ($id =~ /name=/) { | ||
| 203 | # $string = $id; | ||
| 204 | # } | ||
| 205 | |||
| 206 | # else { | ||
| 207 | # $string = ($id =~ /css=/ ? $id : 'id=' . $id); | ||
| 208 | # } | ||
| 209 | |||
| 210 | WAIT: { | ||
| 211 | for (1..60) { | ||
| 212 | diag("Looking for $id"); | ||
| 213 | if (eval { $self->is_element_present($id) }) { | ||
| 214 | pass($testname); | ||
| 215 | last WAIT | ||
| 216 | } | ||
| 217 | sleep(1); | ||
| 218 | } | ||
| 219 | |||
| 220 | fail($testname); | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | 1; |