Made a few pageoftext.com specific changes to allow for easier integration of potoss...
[potoss.git] / potoss_code / selenium.selt
blob449e624f507d79e9225bc14077d13d16286a3897
1 # run this file from within Cygwin (or on a 'real' Unix) using the\r
2 # prove command line tool.  prove is a script, and is part of\r
3 # the Test::Harness perl module.\r
4 \r
5 # I (Gordon) have added an alias to Cygwin to ease running this test\r
6 # alias potoss='export POT_TEST_DIR=oss ; prove /cygdrive/i/potoss_alias/potoss_code/selenium.selt'\r
7 \r
8 # you will also need to install the Selenium Remote Control application\r
9 \r
10 use strict;\r
11 use warnings;\r
13 # Don't set the number of tests in the Test::More definition\r
14 # rather, set them based on the number of browsers you'll be testing.\r
15 # This is done automatically with the "plan" function call below.\r
16 use Test::More;\r
17 use Test::WWW::Selenium;\r
19 my $NUM_TESTS_PER_BROWSER = 89;\r
20 my $SELENIUM_SERVER_DIR =\r
21     qq~"C:\\Program Files\\selenium-remote-control-0.9.1_nightly\\server"~;\r
23 my @BROWSERS = (\r
24     { name => 'firefox',  should_test => 1 },\r
25     { name => 'iexplore', should_test => 0 },\r
26     { name => 'opera', should_test => 0 }, # works, but gives a little popup error.\r
27 );\r
29 my @browsers_to_test = grep({$_->{should_test}} @BROWSERS);\r
31 # automatically set the number of Test::More tests based on the\r
32 # number of browsers you plan to test.\r
33 plan( tests => $NUM_TESTS_PER_BROWSER * scalar(@browsers_to_test) );\r
35 # start up the Selenium server in java\r
36 # send STDERR to /dev/null so no 'clutter' messages appear in the console\r
37 system qq~\r
38     cd $SELENIUM_SERVER_DIR ;\r
39     java -jar selenium-server.jar 2> /dev/null &\r
40 ~;\r
42 sleep 4;\r
44 my $sel = undef;\r
46 my $test_dir = $ENV{POT_TEST_DIR}\r
47     || die "needs POT_TEST_DIR environmental variable set";\r
49 my %test_for = (\r
50     potoss_dev => {\r
51         url   => 'www.potoss_dev.com', # you can set this in your HOSTS file\r
52         dir   => '/?',\r
53         texts => '/cygdrive/i/potoss_dev_alias/potoss_data/texts_8s73f9dv/',\r
54     },\r
55     #TEMPLATE_ADD_EXTRA_SELENIUM_TEST_DIRS\r
56 );\r
58 my $url = $test_for{$test_dir}->{url} || die "need url for test_dir";\r
59 my $dir = $test_for{$test_dir}->{dir}  || die "need dir for test_dir";\r
60 my $texts_dir = $test_for{$test_dir}->{texts} || die "need texts for test_dir";\r
62 BROWSER:\r
63 for my $browser (@browsers_to_test) {\r
65     $sel = Test::WWW::Selenium->new(\r
66         host        => "localhost",\r
67         port        => 4444,\r
68         browser     => "*$browser->{name}",\r
69         browser_url => "http://$url/",\r
70     );\r
73     $sel->open_ok("${dir}potoss_saved_test");\r
74     loads_ok();\r
75     $sel->is_text_present_ok("edit this page");\r
76     $sel->is_text_present_ok("this is change 11");\r
80     $sel->click_ok("link=advanced options");\r
81     loads_ok();\r
82     $sel->click_ok("link=show the page's revision history");\r
83     loads_ok();\r
84     $sel->click_ok("link=compare two revisions");\r
85     loads_ok();\r
86     $sel->click_ok("link=start at revision 9");\r
87     loads_ok();\r
88     $sel->click_ok("link=end at revision 10");\r
89     loads_ok();\r
90     $sel->is_text_present_ok("this is change 10");\r
94     $sel->open_ok("${dir}potoss_wow"); #read only alias for potoss_saved_test\r
95     loads_ok();\r
96     $sel->is_text_present_ok("read only");\r
97     $sel->is_text_present_ok("this is change 11");\r
99     $sel->open_ok("${dir}PH_edit&nm_page=potoss_wow");\r
100     loads_ok();\r
101     $sel->is_text_present_ok("You can't edit this page");\r
103     $sel->open_ok("${dir}PH_page_opts&nm_page=potoss_wow");\r
104     loads_ok();\r
105     $sel->is_text_present_ok("You can't view this page's options");\r
107     $sel->open_ok("${dir}potoss_tmp_test");\r
108     loads_ok();\r
109     $sel->is_text_present_ok("This page doesn't exist");\r
110     $sel->click_ok("link=create it as a new page");\r
111     loads_ok();\r
112     $sel->click_ok("id=myel_new_page");\r
113     loads_ok();\r
114     $sel->is_text_present_ok("edit this page");\r
115     $sel->click_ok("link=edit this page");\r
116     loads_ok();\r
117     $sel->is_text_present_ok("This message only appears the first time you edit a page");\r
118     $sel->type_ok("myel_text_area", "This is some text.");\r
119     $sel->click_ok("nm_submit");\r
120     loads_ok();\r
121     $sel->is_text_present_ok("This is some text");\r
122     $sel->click_ok("link=edit this page");\r
123     loads_ok();\r
124     $sel->type_ok("myel_text_area", "This is some text.\nThis is even more text.");\r
125     $sel->click_ok("nm_submit");\r
126     loads_ok();\r
127     $sel->is_text_present_ok("This is even more text");\r
128     $sel->click_ok("link=advanced options");\r
129     loads_ok();\r
130     $sel->click_ok("link=show the page's revision history");\r
131     loads_ok();\r
132     $sel->is_text_present_ok("view revision 2");\r
134     `cd $texts_dir ; rm -r potoss_tmp_test_REVS ; rm potoss_tmp_test*`;\r
136     #-------------------------------------------------------------------------\r
137     # Story:\r
138     # When there is only a single revision, a message appears when you try\r
139     # to look at the revisions.\r
141     $sel->open_ok("${dir}potoss_tmp_test");\r
142     loads_ok();\r
143     $sel->is_text_present_ok("This page doesn't exist");\r
144     $sel->click_ok("link=create it as a new page");\r
145     loads_ok();\r
146     $sel->click_ok("id=myel_new_page");\r
147     loads_ok();\r
148     $sel->is_text_present_ok("edit this page");\r
149     $sel->click_ok("link=edit this page");\r
150     loads_ok();\r
151     $sel->is_text_present_ok("This message only appears the first time you edit a page");\r
152     $sel->type_ok("myel_text_area", "This is some text.");\r
153     $sel->click_ok("nm_submit");\r
154     loads_ok();\r
155     $sel->click_ok("link=advanced options");\r
156     loads_ok();\r
157     $sel->click_ok("link=show the page's revision history");\r
158     loads_ok();\r
159     $sel->is_text_present_ok("There is currently only one revision");\r
161     `cd $texts_dir ; rm -r potoss_tmp_test_REVS ; rm potoss_tmp_test*`;\r
163     #-------------------------------------------------------------------------\r
164     # Story:\r
165     # Try to create a page name which is in the dictionary\r
166     $sel->open_ok("${dir}PH_create");\r
167     $sel->is_text_present_ok("like the page name");\r
168     $sel->type_ok("myel_page_name", "queen");\r
169     $sel->click_ok("nm_submit");\r
170     loads_ok();\r
171     $sel->is_text_present_ok("is in the dictionary");\r
173     #-------------------------------------------------------------------------\r
174     # Story:\r
175     # Try to create a page which already exists\r
176     $sel->open_ok("${dir}PH_create");\r
177     $sel->is_text_present_ok("like the page name");\r
178     $sel->type_ok("myel_page_name", "potoss_saved_test");\r
179     $sel->click_ok("nm_submit");\r
180     loads_ok();\r
181     $sel->is_text_present_ok("that one already exists");\r
183     #-------------------------------------------------------------------------\r
184     # Story:\r
185     # Try to create a wrong page name.  It will automatically suggest a\r
186     # better one.\r
187     $sel->open_ok("${dir}PH_create");\r
188     $sel->is_text_present_ok("like the page name");\r
189     $sel->type_ok("myel_page_name", "My dog is always hungry!");\r
190     $sel->click_ok("nm_submit");\r
191     loads_ok();\r
192     $sel->is_text_present_ok("changed the page name to");\r
193     $sel->is_text_present_ok("my_dog_is_always_hungry");\r
195     sleep 2; #see what happened in the browser window before you close it.\r
196     $sel->stop();\r
200 # If there is still an sel object, then send the Remote Control the command\r
201 # to shutDown, which will cause the Java process to end.  This is not\r
202 # documented directly in the Test::WWW::Selenium documentation, but the\r
203 # shutDown command is shown in the Selenium Remote Control documentation.\r
204 $sel && $sel->do_command("shutDown");\r
206 sub loads_ok {\r
207     # this is called so often that it should be a subroutine\r
208     # with a cleaner name and a variable you can change in one place.\r
209     $sel->wait_for_page_to_load_ok('30000', 'page loads in less than 30000');\r