Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 243 lines (147 sloc) 5.923 kB
6ecfe69 @kablamo Initial commit.
authored
1 =pod
2
3 =encoding utf-8
4
5 =head1 NAME
6
7 Test::WWW::Selenium::More - More tools for Selenium testing
8
9 =head1 SYNOPSIS
10
11 use Test::WWW::Selenium::More;
12
13 Test::WWW::Selenium::More->new()
14 ->note('this is a test. this is only a test.')
15 ->open_ok("/")
16 ->is_text_present_ok("Welcome to the internet")
17 ->download_file_ok('link=Download my file');
18
19 =head1 DESCRIPTION
20
21 This module provides method chaining and some useful tools for Selenium
22 testing.
23
574cee3 @kablamo v0.10
authored
24 If you are new to this module or Selenium testing in general, see the
25 L<Test::WWW::Selenium::More::Manual>.
26
27 This library extends L<Test::WWW::Selenium>. Method chaining is available for
28 all Test::WWW::Selenium::More methods and all Test::WWW::Selenium methods whose
29 names end in _ok, _is, _isnt or _like.
6ecfe69 @kablamo Initial commit.
authored
30
31 =head1 ATTRIBUTES
32
33 =head2 host
34
35 The hostname or ip address of the Selenium server. Defaults to 'localhost'.
36
37 =head2 port
38
39 The port of the Selenium server. Defaults to '4444'.
40
41 =head2 browser
42
43 The browser to run tests against on the Selenium server. Defaults to
44 '*chrome'.
45
46 =head2 browser_url
47
48 The Selenium server runs tests against this website.
49
50 =head2 autostop
51
52 When $selenium goes out of scope the browser will be automatically shut down if
53 this attribute is set to true. Otherwise stop() must be called explicitly.
54 Defaults to 1.
55
56 =head2 slow
57
58 The number of seconds to sleep after each call to any Test::WWW::Selenium
59 method. This is useful for slowing down tests if you are watching them run in
60 a browser. Defaults to 0.
61
62 =head2 stash
63
64 A HashRef of saved values. This behaves similar to the Catalyst stash.
65
66 =head1 METHODS
67
68 =head2 load_data( $file )
69
70 Returns a data structure from $file. $file must have valid Perl syntax.
71
72 This method is for use with data driven tests. It helps you to separate your
73 Perl code from your test data.
74
75 Here is an example of what the contents of $file could look like:
76
77 (
78 {
79 name => 'Name of my test',
80 link => 'Click me',
81 text => 'Ponies',
82 },
83 {
84 name => 'Test downloading stuff',
85 link => 'Download',
86 text => 'Download worked',
87 },
88 ...
89 );
90
91 =head2 follow_link_ok( $locator, $test_description )
92
93 Returns $self.
94
95 This method performs a click_ok on the page element specified by $locator and
96 then does a wait_for_page_to_load(). $test_description is optional. It will
97 be set to something appropriate if you don't set it.
98
99 =head2 fill_form_ok( $form )
100
101 Returns $self.
102
103 $form must be a hashref that looks like this:
104
105 $selenium->fill_form_ok(
106 { select => { locator => value, ... },
107 input => { locator => value, ... },
108 }
109 );
110
111 The 'select' key indicates dropdown menus that will be selected. The 'input'
112 key indicates text input, hidden input, checkboxes, and radio buttons.
113
114 The form is not submitted.
115
116 =head2 submit_form_ok( $form )
117
118 Returns $self.
119
120 $form must be a hashref that looks like this:
121
122 $selenium->submit_form_ok(
123 { select => { locator => value, ... },
124 input => { locator => value, ... },
125 click => 'locator', # or 'submit' instead of 'click'
126 }
127 );
128
129 $form is simply passed to fill_form_ok(). Afterwards submit_form_ok() looks
130 for 2 keys to process: 'click' and 'submit'. The form is submitted via
131 a click on page element indicated by 'locator' when 'click' is used. The form
132 is submitted without a click when 'submit' is used. This is useful for forms
133 without submit buttons.
134
135 =head2 wait_for_jquery_ok()
136
137 Returns $self.
138
a98608f @kablamo v0.11
authored
139 This blocks until jQuery.active returns false.
6ecfe69 @kablamo Initial commit.
authored
140
141 =head2 jquery_select_ok($locator, $menu_option)
142
143 Returns $self.
144
145 $locator should point to a dropdown menu on the page. This method will select
146 the $menu_option from the dropdown. Then it will call wait_for_jquery().
147
148 =head2 select_and_page_load_ok($locator, $menu_option)
149
150 Returns $self.
151
152 $locator should point to a dropdown menu on the page. This method will select
153 the $menu_option from the dropdown. Then it will call wait_for_page_to_load().
154
155 =head2 jquery_click_ok($locator, $menu_option)
156
157 Returns $self.
158
159 Click whatever is located at $locator. Then wait for jquery to finish by
160 calling wait_for_jquery().
161
162 =head2 stash_text( $locator => $key )
163
164 Returns $self.
165
166 Retrieves the value of $locator from selenium and stores it in the stash under
167 the name $key.
168
169 =head2 stash_location( $key )
170
171 Returns $self.
172
173 Retrieves the location from selenium and stores it in the stash under the name $key.
174
175 =head2 from_stash( $key )
176
177 Returns a value from the stash.
178
179 =head2 stash( $value => $key )
180
181 Returns $self.
182
183 Saves $value to the stash under the name $key.
184
185 =head2 note( $msg )
186
187 Returns $self.
188
189 calls Test::Most::note($msg);
190
191 =head2 is_text_not_present_ok( $text )
192
193 Returns $self.
194
195 The opposite of is_text_present_ok().
196
197 =head2 note_line( $msg )
198
199 Outputs an underlined message, useful for dividing up test output. If no
200 message specified, then just prints the separator line.
201
202 =head2 download_file_ok($locator)
203
204 Parses the href attribute from a link on the current page. Downloads that url
205 via javascript's XMLHttpRequest. Checks that response status is 200.
206
207 =head2 change_speed($seconds)
208
209 This just updates the slow() attribute. The only difference is that it
210 returns $self so that you can do method chaining.
211
212 =head1 ENVIRONMENT VARIABLES
213
214 The following is a list of environment variables that affect the behavior of
215 this library. Each corresponds to an attribute (see the ATTRIBUTES
216 section).
217
218 =head2 SELENIUM_HOST
219
220 =head2 SELENIUM_PORT
221
222 =head2 SELENIUM_BROWSER
223
224 =head2 SELENIUM_BROWSER_URL
225
226 =head2 SELENIUM_TIMEOUT
227
228 =head2 SELENIUM_AUTOSTOP
229
230 =head2 SELENIUM_SLOW
231
232 =head1 AUTHOR
233
234 Eric Johnson <kablamo at iijo dot nospamthanks dot org>
235
236 =head1 COPYRIGHT AND LICENSE
237
238 This software is copyright (c) 2012 by Eric Johnson.
239
240 This is free software; you can redistribute it and/or modify it under
241 the same terms as the Perl 5 programming language system itself.
242
Something went wrong with that request. Please try again.