-
Notifications
You must be signed in to change notification settings - Fork 2
/
WebBrowser.scala
4764 lines (4492 loc) · 188 KB
/
WebBrowser.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatestplus.selenium
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.{FirefoxDriver, FirefoxProfile}
import org.openqa.selenium.safari.SafariDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.ie.InternetExplorerDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import java.util.concurrent.TimeUnit
import scala.collection.JavaConverters._
import org.openqa.selenium.Cookie
import java.util.Date
import org.scalatest.time.Span
import org.openqa.selenium.TakesScreenshot
import org.openqa.selenium.OutputType
import java.io.File
import java.io.FileOutputStream
import java.io.FileInputStream
import org.openqa.selenium.Alert
import org.openqa.selenium.support.ui.Select
import org.scalatest.exceptions.TestFailedException
import org.scalatest.exceptions.StackDepthException
import org.openqa.selenium.JavascriptExecutor
import org.scalactic.source
import org.openqa.selenium.firefox.FirefoxOptions
import java.io.Closeable
/**
* Trait that provides a domain specific language (DSL) for writing browser-based tests using <a href="http://seleniumhq.org">Selenium</a>.
*
* To use ScalaTest's Selenium DSL, mix trait <code>WebBrowser</code> into your test class. This trait provides the DSL in its
* entirety except for one missing piece: an implicit <code>org.openqa.selenium.WebDriver</code>. One way to provide the missing
* implicit driver is to declare one as a member of your test class, like this:
*
* <pre class="stHighlighted">
* <span class="stReserved">import</span> org.scalatest._
* <span class="stReserved">import</span> selenium._
* <span class="stReserved">import</span> org.openqa.selenium._
* <span class="stReserved">import</span> htmlunit._
* <br/><span class="stReserved">class</span> <span class="stType">BlogSpec</span> <span class="stReserved">extends</span> <span class="stType">FlatSpec</span> <span class="stReserved">with</span> <span class="stType">Matchers</span> <span class="stReserved">with</span> <span class="stType">WebBrowser</span> {
* <br/> <span class="stReserved">implicit</span> <span class="stReserved">val</span> webDriver: <span class="stType">WebDriver</span> = <span class="stReserved">new</span> <span class="stType">HtmlUnitDriver</span>
* <br/> <span class="stReserved">val</span> host = <span class="stQuotedString">"http://localhost:9000/"</span>
* <br/> <span class="stQuotedString">"The blog app home page"</span> should <span class="stQuotedString">"have the correct title"</span> in {
* go to (host + <span class="stQuotedString">"index.html"</span>)
* pageTitle should be (<span class="stQuotedString">"Awesome Blog"</span>)
* }
* }
* </pre>
*
* <p>
* For convenience, however, ScalaTest provides a <code>WebBrowser</code> subtrait containing an implicit <code>WebDriver</code> for each
* driver provided by Selenium.
* Thus a simpler way to use the <code>HtmlUnit</code> driver, for example, is to extend
* ScalaTest's <a href="HtmlUnit.html"><code>HtmlUnit</code></a> trait, like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stReserved">import</span> org.scalatest._
* <span class="stReserved">import</span> selenium._
* <br/><span class="stReserved">class</span> <span class="stType">BlogSpec</span> <span class="stReserved">extends</span> <span class="stType">FlatSpec</span> <span class="stReserved">with</span> <span class="stType">Matchers</span> <span class="stReserved">with</span> <span class="stType">HtmlUnit</span> {
* <br/> <span class="stReserved">val</span> host = <span class="stQuotedString">"http://localhost:9000/"</span>
* <br/> <span class="stQuotedString">"The blog app home page"</span> should <span class="stQuotedString">"have the correct title"</span> in {
* go to (host + <span class="stQuotedString">"index.html"</span>)
* pageTitle should be (<span class="stQuotedString">"Awesome Blog"</span>)
* }
* }
* </pre>
*
* <p>
* The web driver traits provided by ScalaTest are:
* </p>
*
* <table style="border-collapse: collapse; border: 1px solid black">
* <tr><th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black"><strong>Driver</strong></th><th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black"><strong><code>WebBrowser</code> subtrait</strong></th></tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* Google Chrome
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <a href="Chrome.html"><code>Chrome</code></a>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* Mozilla Firefox
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <a href="Firefox.html"><code>Firefox</code></a>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* HtmlUnit
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <a href="HtmlUnit.html"><code>HtmlUnit</code></a>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* Microsoft Internet Explorer
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <a href="InternetExplorer.html"><code>InternetExplorer</code></a>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* Apple Safari
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <a href="Safari.html"><code>Safari</code></a>
* </td>
* </tr>
* </table>
*
* <h2>Navigation</h2>
*
* <p>
* You can ask the browser to retrieve a page (go to a URL) like this:
* </p>
*
* <pre class="stHighlighted">
* go to <span class="stQuotedString">"http://www.artima.com"</span>
* </pre>
*
* <p>
* Note: If you are using the <em>page object pattern</em>, you can also go to a page using the <code>Page</code> instance, as
* illustrated in the section on <a href="#pageObjects">page objects</a> below.
* </p>
*
* <p>
* Once you have retrieved a page, you can fill in and submit forms, query for the values of page elements, and make assertions.
* In the following example, selenium will go to <code>http://www.google.com</code>, fill in the text box with
* <code>Cheese!</code>, press the submit button, and wait for result returned from an AJAX call:
* </p>
*
* <pre class="stHighlighted">
* go to <span class="stQuotedString">"http://www.google.com"</span>
* click on <span class="stQuotedString">"q"</span>
* enter(<span class="stQuotedString">"Cheese!"</span>)
* submit()
* <span class="stLineComment">// Google's search is rendered dynamically with JavaScript.</span>
* eventually { pageTitle should be (<span class="stQuotedString">"Cheese! - Google Search"</span>) }
* </pre>
*
* <p>
* In the above example, the <code>"q"</code> used in “<code>click on "q"</code>”
* can be either the id or name of an element. ScalaTest's Selenium DSL will try to lookup by id first. If it cannot find
* any element with an id equal to <code>"q"</code>, it will then try lookup by name <code>"q"</code>.
* </p>
*
* <p>
* Alternatively, you can be more specific:
* </p>
*
* <pre class="stHighlighted">
* click on id(<span class="stQuotedString">"q"</span>) <span class="stLineComment">// to lookup by id "q" </span>
* click on name(<span class="stQuotedString">"q"</span>) <span class="stLineComment">// to lookup by name "q" </span>
* </pre>
*
* <p>
* In addition to <code>id</code> and <code>name</code>, you can use the following approaches to lookup elements, just as you can do with
* Selenium's <code>org.openqa.selenium.By</code> class:
* </p>
*
* <ul>
* <li><code>xpath</code></li>
* <li><code>className</code></li>
* <li><code>cssSelector</code></li>
* <li><code>linkText</code></li>
* <li><code>partialLinkText</code></li>
* <li><code>tagName</code></li>
* </ul>
*
* <p>
* For example, you can select by link text with:
* </p>
*
* <pre class="stHighlighted">
* click on linkText(<span class="stQuotedString">"click here!"</span>)
* </pre>
*
* <p>
* If an element is not found via any form of lookup, evaluation will complete abruptly with a <code>TestFailedException</code>.
* <p>
*
* <h2>Getting and setting input element values</h2>
*
* <p>
* ScalaTest's Selenium DSL provides a clear, simple syntax for accessing and updating the values of input elements such as
* text fields, radio buttons, checkboxes, selection lists, and the input types introduced in HTML5. If a requested element is not found, or if it is found but is
* not of the requested type, an exception will immediately result causing the test to fail.
* <p>
*
* <p>
* The most common way to access field value is through the <code>value</code> property, which is supported by the following
* input types:
* </p>
*
* <table style="border-collapse: collapse; border: 1px solid black">
* <tr>
* <th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black">
* <strong>Tag Name</strong>
* </th>
* <th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black">
* <strong>Input Type</strong>
* </th>
* <th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black">
* <strong>Lookup Method</strong>
* </th>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>text</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>textField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>textarea</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>-</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>textArea</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>password</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>pwdField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>email</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>emailField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>color</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>colorField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>date</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>dateField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>datetime</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>dateTimeField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>datetime-local</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>dateTimeLocalField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>month</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>monthField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>number</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>numberField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>range</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>rangeField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>search</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>searchField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>tel</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>telField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>time</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>timeField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>url</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>urlField</code>
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>input</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>week</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: center">
* <code>weekField</code>
* </td>
* </tr>
* </table>
*
* <p>
* You can change a input field's value by assigning it via the <code>=</code> operator, like this:
* </p>
*
* <pre class="stHighlighted">
* textField(<span class="stQuotedString">"q"</span>).value = <span class="stQuotedString">"Cheese!"</span>
* </pre>
*
* <p>
* And you can access a input field's value by simply invoking <code>value</code> on it:
* </p>
*
* <pre class="stHighlighted">
* textField(<span class="stQuotedString">"q"</span>).value should be (<span class="stQuotedString">"Cheese!"</span>)
* </pre>
*
* <p>
* If the text field is empty, <code>value</code> will return an empty string (<code>""</code>).
* </p>
*
* <p>
* You can use the same syntax with other type of input fields by replacing <code>textField</code> with <code>Lookup Method</code> listed in table above,
* for example to use text area:
* </p>
*
* <pre class="stHighlighted">
* textArea(<span class="stQuotedString">"body"</span>).value = <span class="stQuotedString">"I saw something cool today!"</span>
* textArea(<span class="stQuotedString">"body"</span>).value should be (<span class="stQuotedString">"I saw something cool today!"</span>)
* </pre>
*
* <p>
* or with a password field:
* </p>
*
* <pre class="stHighlighted">
* pwdField(<span class="stQuotedString">"secret"</span>).value = <span class="stQuotedString">"Don't tell anybody!"</span>
* pwdField(<span class="stQuotedString">"secret"</span>).value should be (<span class="stQuotedString">"Don't tell anybody!"</span>)
* </pre>
*
* <h3>Alternate Way for Data Entry</h3>
*
* <p>
* An alternate way to enter data into a input fields is to use <code>enter</code> or <code>pressKeys</code>.
* Although both of <code>enter</code> and <code>pressKeys</code> send characters to the active element, <code>pressKeys</code> can be used on any kind of
* element, whereas <code>enter</code> can only be used on text entry fields, which include:
* </p>
*
* <ul>
* <li><code>textField</code></li>
* <li><code>textArea</code></li>
* <li><code>pwdField</code></li>
* <li><code>emailField</code></li>
* <li><code>searchField</code></li>
* <li><code>telField</code></li>
* <li><code>urlField</code></li>
* </ul>
*
* <p>
* Another difference is that <code>enter</code> will clear the text field or area before sending the characters,
* effectively replacing any currently existing text with the new text passed to <code>enter</code>. By contrast,
* <code>pressKeys</code> does not do any clearing—it just appends more characters to any existing text.
* You can backup with <code>pressKeys</code>, however, by sending explicit backspace characters, <code>"\u0008"</code>.
* </p>
*
* <p>
* To use these commands, you must first click on the input field you are interested in
* to give it the focus. Here's an example:
* </p>
*
* <pre class="stHighlighted">
* click on <span class="stQuotedString">"q"</span>
* enter(<span class="stQuotedString">"Cheese!"</span>)
* </pre>
*
* <p>
* Here's a (contrived) example of using <code>pressKeys</code> with backspace to fix a typo:
* </p>
*
* <pre class="stHighlighted">
* click on <span class="stQuotedString">"q"</span> <span class="stLineComment">// q is the name or id of a text field or text area</span>
* enter(<span class="stQuotedString">"Cheesey!"</span>) <span class="stLineComment">// Oops, meant to say Cheese!</span>
* pressKeys(<span class="stQuotedString">"\u0008\u0008"</span>) <span class="stLineComment">// Send two backspaces; now the value is Cheese</span>
* pressKeys(<span class="stQuotedString">"!"</span>) <span class="stLineComment">// Send the missing exclamation point; now the value is Cheese!</span>
* </pre>
*
* <h3>Radio buttons</h3>
*
* <p>
* Radio buttons work together in groups. For example, you could have a group of radio buttons, like this:
* </p>
*
* <pre>
* <input type="radio" id="opt1" name="group1" value="Option 1"> Option 1</input>
* <input type="radio" id="opt2" name="group1" value="Option 2"> Option 2</input>
* <input type="radio" id="opt3" name="group1" value="Option 3"> Option 3</input>
* </pre>
*
* <p>
* You can select an option in either of two ways:
* </p>
*
* <pre class="stHighlighted">
* radioButtonGroup(<span class="stQuotedString">"group1"</span>).value = <span class="stQuotedString">"Option 2"</span>
* radioButtonGroup(<span class="stQuotedString">"group1"</span>).selection = <span class="stType">Some</span>(<span class="stQuotedString">"Option 2"</span>)
* </pre>
*
* <p>
* Likewise, you can read the currently selected value of a group of radio buttons in two ways:
* </p>
*
* <pre class="stHighlighted">
* radioButtonGroup(<span class="stQuotedString">"group1"</span>).value should be (<span class="stQuotedString">"Option 2"</span>)
* radioButtonGroup(<span class="stQuotedString">"group1"</span>).selection should be (<span class="stType">Some</span>(<span class="stQuotedString">"Option 2"</span>))
* </pre>
*
* <p>
* If the radio button has no selection at all, <code>selection</code> will return <code>None</code> whereas <code>value</code>
* will throw a <code>TestFailedException</code>. By using <code>value</code>, you are indicating you expect a selection, and if there
* isn't a selection that should result in a failed test.
* </p>
*
* <p>
* If you would like to work with <code>RadioButton</code> element directly, you can select it by calling <code>radioButton</code>:
* </p>
*
* <pre class="stHighlighted">
* click on radioButton(<span class="stQuotedString">"opt1"</span>)
* </pre>
*
* <p>
* you can check if an option is selected by calling <code>isSelected</code>:
* </p>
*
* <pre class="stHighlighted">
* radioButton(<span class="stQuotedString">"opt1"</span>).isSelected should be (<span class="stReserved">true</span>)
* </pre>
*
* <p>
* to get the value of radio button, you can call <code>value</code>:
* </p>
*
* <pre class="stHighlighted">
* radioButton(<span class="stQuotedString">"opt1"</span>).value should be (<span class="stQuotedString">"Option 1"</span>)
* </pre>
*
* <h3>Checkboxes</h3>
*
* <p>
* A checkbox in one of two states: selected or cleared. Here's how you select a checkbox:
* </p>
*
* <pre class="stHighlighted">
* checkbox(<span class="stQuotedString">"cbx1"</span>).select()
* </pre>
*
* <p>
* And here's how you'd clear one:
* </p>
*
* <pre class="stHighlighted">
* checkbox(<span class="stQuotedString">"cbx1"</span>).clear()
* </pre>
*
* <p>
* You can access the current state of a checkbox with <code>isSelected</code>:
* </p>
*
* <pre class="stHighlighted">
* checkbox(<span class="stQuotedString">"cbx1"</span>).isSelected should be (<span class="stReserved">true</span>)
* </pre>
*
* <h3>Single-selection dropdown lists</h3>
*
* <p>
* Given the following single-selection dropdown list:
* </p>
*
* <pre>
* <select id="select1">
* <option value="option1">Option 1</option>
* <option value="option2">Option 2</option>
* <option value="option3">Option 3</option>
* </select>
* </pre>
*
* <p>
* You could select <code>Option 2</code> in either of two ways:
* </p>
*
* <pre class="stHighlighted">
* singleSel(<span class="stQuotedString">"select1"</span>).value = <span class="stQuotedString">"option2"</span>
* singleSel(<span class="stQuotedString">"select1"</span>).selection = <span class="stType">Some</span>(<span class="stQuotedString">"option2"</span>)
* </pre>
*
* <p>
* To clear the selection, either invoke <code>clear</code> or set <code>selection</code> to <code>None</code>:
* </p>
*
* <pre class="stHighlighted">
* singleSel(<span class="stQuotedString">"select1"</span>).clear()
* singleSel(<span class="stQuotedString">"select1"</span>).selection = <span class="stType">None</span>
* </pre>
*
* <p>
* You can read the currently selected value of a single-selection list in the same manner as radio buttons:
* </p>
*
* <pre class="stHighlighted">
* singleSel(<span class="stQuotedString">"select1"</span>).value should be (<span class="stQuotedString">"option2"</span>)
* singleSel(<span class="stQuotedString">"select1"</span>).selection should be (<span class="stType">Some</span>(<span class="stQuotedString">"option2"</span>))
* </pre>
*
* <p>
* If the single-selection list has no selection at all, <code>selection</code> will return <code>None</code> whereas <code>value</code>
* will throw a <code>TestFailedException</code>. By using <code>value</code>, you are indicating you expect a selection, and if there
* isn't a selection that should result in a failed test.
* </p>
*
* <h3>Multiple-selection lists</h3>
*
* <p>
* Given the following multiple-selection list:
* </p>
*
* <pre>
* <select name="select2" multiple="multiple">
* <option value="option4">Option 4</option>
* <option value="option5">Option 5</option>
* <option value="option6">Option 6</option>
* </select>
* </pre>
*
* <p>
* You could select <code>Option 5</code> and <code>Option 6</code> like this:
* </p>
*
* <pre class="stHighlighted">
* multiSel(<span class="stQuotedString">"select2"</span>).values = <span class="stType">Seq</span>(<span class="stQuotedString">"option5"</span>, <span class="stQuotedString">"option6"</span>)
* </pre>
*
* <p>
* The previous command would essentially clear all selections first, then select <code>Option 5</code> and <code>Option 6</code>.
* If instead you want to <em>not</em> clear any existing selection, just additionally select <code>Option 5</code> and <code>Option 6</code>,
* you can use the <code>+=</code> operator, like this.
* </p>
*
* <pre class="stHighlighted">
* multiSel(<span class="stQuotedString">"select2"</span>).values += <span class="stQuotedString">"option5"</span>
* multiSel(<span class="stQuotedString">"select2"</span>).values += <span class="stQuotedString">"option6"</span>
* </pre>
*
* <p>
* To clear a specific option, pass its name to <code>clear</code>:
* </p>
*
* <pre class="stHighlighted">
* multiSel(<span class="stQuotedString">"select2"</span>).clear(<span class="stQuotedString">"option5"</span>)
* </pre>
*
* <p>
* To clear all selections, call <code>clearAll</code>:
* </p>
*
* <pre class="stHighlighted">
* multiSel(<span class="stQuotedString">"select2"</span>).clearAll()
* </pre>
*
* <p>
* You can access the current selections with <code>values</code>, which returns an immutable <code>IndexedSeq[String]</code>:
* </p>
*
* <pre class="stHighlighted">
* multiSel(<span class="stQuotedString">"select2"</span>).values should have size <span class="stLiteral">2</span>
* multiSel(<span class="stQuotedString">"select2"</span>).values(<span class="stLiteral">0</span>) should be (<span class="stQuotedString">"option5"</span>)
* multiSel(<span class="stQuotedString">"select2"</span>).values(<span class="stLiteral">1</span>) should be (<span class="stQuotedString">"option6"</span>)
* </pre>
*
* <h3>Clicking and submitting</h3>
*
* <p>
* You can click on any element with “<code>click on</code>” as shown previously:
* </p>
*
* <pre class="stHighlighted">
* click on <span class="stQuotedString">"aButton"</span>
* click on name(<span class="stQuotedString">"aTextField"</span>)
* </pre>
*
* <p>
* If the requested element is not found, <code>click on</code> will throw an exception, failing the test.
* </p>
*
* <p>
* Clicking on a input element will give it the focus. If current focus is in on an input element within a form, you can submit the form by
* calling <code>submit</code>:
* </p>
*
* <pre class="stHighlighted">
* submit()
* </pre>
*
* <h2>Switching</h2>
*
* <p>
* You can switch to a popup alert bo using the following code:
* </p>
*
* <pre class="stHighlighted">
* switch to alertBox
* </pre>
*
* <p>
* to switch to a frame, you could:
* </p>
*
* <pre class="stHighlighted">
* switch to frame(<span class="stLiteral">0</span>) <span class="stLineComment">// switch by index</span>
* switch to frame(<span class="stQuotedString">"name"</span>) <span class="stLineComment">// switch by name</span>
* </pre>
*
* <p>
* If you have reference to a window handle (can be obtained from calling windowHandle/windowHandles), you can switch to a particular
* window by:
* </p>
*
* <pre class="stHighlighted">
* switch to window(windowHandle)
* </pre>
*
* <p>
* You can also switch to active element and default content:
* </p>
*
* <pre class="stHighlighted">
* switch to activeElement
* switch to defaultContent
* </pre>
*
* <h2>Navigation history</h2>
*
* <p>
* In real web browser, you can press the 'Back' button to go back to previous page. To emulate that action in your test, you can call <code>goBack</code>:
* </p>
*
* <pre class="stHighlighted">
* goBack()
* </pre>
*
* <p>
* To emulate the 'Forward' button, you can call:
* </p>
*
* <pre class="stHighlighted">
* goForward()
* </pre>
*
* And to refresh or reload the current page, you can call:
*
* <pre class="stHighlighted">
* reloadPage()
* </pre>
*
* <h2>Cookies!</h2>
*
* <p>To create a new cookie, you'll say:</p>
*
* <pre class="stHighlighted">
* add cookie (<span class="stQuotedString">"cookie_name"</span>, <span class="stQuotedString">"cookie_value"</span>)
* </pre>
*
* <p>
* to read a cookie value, you do:
* </p>
*
* <pre class="stHighlighted">
* cookie(<span class="stQuotedString">"cookie_name"</span>).value should be (<span class="stQuotedString">"cookie_value"</span>) <span class="stLineComment">// If value is undefined, throws TFE right then and there. Never returns null.</span>
* </pre>
*
* <p>
* In addition to the common use of name-value cookie, you can pass these extra fields when creating the cookie, available ways are:
* </p>
*
* <pre class="stHighlighted">
* cookie(name: <span class="stType">String</span>, value: <span class="stType">String</span>)
* cookie(name: <span class="stType">String</span>, value: <span class="stType">String</span>, path: <span class="stType">String</span>)
* cookie(name: <span class="stType">String</span>, value: <span class="stType">String</span>, path: <span class="stType">String</span>, expiry: <span class="stType">Date</span>)
* cookie(name: <span class="stType">String</span>, value: <span class="stType">String</span>, path: <span class="stType">String</span>, expiry: <span class="stType">Date</span>, domain: <span class="stType">String</span>)
* cookie(name: <span class="stType">String</span>, value: <span class="stType">String</span>, path: <span class="stType">String</span>, expiry: <span class="stType">Date</span>, domain: <span class="stType">String</span>, secure: <span class="stType">Boolean</span>)
* </pre>
*
* and to read those extra fields:
*
* <pre class="stHighlighted">
* cookie(<span class="stQuotedString">"cookie_name"</span>).value <span class="stLineComment">// Read cookie's value</span>
* cookie(<span class="stQuotedString">"cookie_name"</span>).path <span class="stLineComment">// Read cookie's path</span>
* cookie(<span class="stQuotedString">"cookie_name"</span>).expiry <span class="stLineComment">// Read cookie's expiry</span>
* cookie(<span class="stQuotedString">"cookie_name"</span>).domain <span class="stLineComment">// Read cookie's domain</span>
* cookie(<span class="stQuotedString">"cookie_name"</span>).isSecure <span class="stLineComment">// Read cookie's isSecure flag</span>
* </pre>
*
* <p>
* In order to delete a cookie, you could use the following code:
* </p>
*
* <pre class="stHighlighted">
* delete cookie <span class="stQuotedString">"cookie_name"</span>
* </pre>
*
* <p>
* or to delete all cookies in the same domain:-
* </p>
*
* <pre class="stHighlighted">
* delete all cookies
* </pre>
*
* To get the underlying Selenium cookie, you can use <code>underlying</code>:
*
* <pre class="stHighlighted">
* cookie(<span class="stQuotedString">"cookie_name"</span>).underlying.validate() <span class="stLineComment">// call the validate() method on underlying Selenium cookie</span>
* </pre>
*
* <h2>Other useful element properties</h2>
*
* <p>
* All element types (<code>textField</code>, <code>textArea</code>, <code>radioButton</code>, <code>checkbox</code>, <code>singleSel</code>, <code>multiSel</code>)
* support the following useful properties:
* </p>
*
* <table style="border-collapse: collapse; border: 1px solid black">
* <tr><th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black"><strong>Method</strong></th><th style="background-color: #CCCCCC; border-width: 1px; padding: 3px; text-align: center; border: 1px solid black"><strong>Description</strong></th></tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>location</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* The XY location of the top-left corner of this <code>Element</code>.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>size</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* The width/height size of this <code>Element</code>.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>isDisplayed</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* Indicates whether this <code>Element</code> is displayed.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>isEnabled</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* Indicates whether this <code>Element</code> is enabled.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>isSelected</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* Indicates whether this <code>Element</code> is selected.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>tagName</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* The tag name of this element.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>underlying</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* The underlying <code>WebElement</code> wrapped by this <code>Element</code>.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>attribute(name: String)</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* The attribute value of the given attribute name of this element, wrapped in a <code>Some</code>, or <code>None</code> if no
* such attribute exists on this <code>Element</code>.
* </td>
* </tr>
* <tr>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* <code>text</code>
* </td>
* <td style="border-width: 1px; padding: 3px; border: 1px solid black; text-align: left">
* Returns the visible (<em>i.e.</em>, not hidden by CSS) text of this element, including sub-elements, without any leading or trailing whitespace.
* </td>
* </tr>
* </table>
*
* <h2>Implicit wait</h2>
*
* <p>
* To set Selenium's implicit wait timeout, you can call the <code>implicitlyWait</code> method:
* </p>
*
* <pre class="stHighlighted">
* implicitlyWait(<span class="stType">Span</span>(<span class="stLiteral">10</span>, <span class="stType">Seconds</span>))
* </pre>
*
* <p>
* Invoking this method sets the amount of time the driver will wait when searching for an element that is not immediately present. For
* more information, see the documentation for method <code>implicitlyWait</code>.
* </p>
*
* <h2>Page source and current URL</h2>
*
* <p>
* It is possible to get the html source of currently loaded page, using:
* </p>
*
* <pre class="stHighlighted">
* pageSource
* </pre>
*
* <p>
* and if needed, get the current URL of currently loaded page:
* </p>
*
* <pre class="stHighlighted">
* currentUrl
* </pre>
*
* <h2>Screen capture</h2>
*
* <p>
* You can capture screen using the following code:
* </p>
*
* <pre class="stHighlighted">
* <span class="stReserved">val</span> file = capture
* </pre>
*
* <p>
* By default, the captured image file will be saved in temporary folder (returned by java.io.tmpdir property), with random file name
* ends with .png extension. You can specify a fixed file name:
* </p>
*
* <pre class="stHighlighted">
* capture to <span class="stQuotedString">"MyScreenShot.png"</span>
* </pre>
*
* <p>
* or
* </p>
*
* <pre class="stHighlighted">
* capture to <span class="stQuotedString">"MyScreenShot"</span>
* </pre>
*
* <p>
* Both will result in a same file name <code>MyScreenShot.png</code>.
* </p>
*
* <p>
* You can also change the target folder screenshot file is written to, by saying:
* </p>
*
* <pre class="stHighlighted">
* setCaptureDir(<span class="stQuotedString">"/home/your_name/screenshots"</span>)
* </pre>
*
* <p>
* If you want to capture a screenshot when something goes wrong (e.g. test failed), you can use <code>withScreenshot</code>:
* </p>
*
* <pre class="stHighlighted">
* withScreenshot {
* assert(<span class="stQuotedString">"Gold"</span> == <span class="stQuotedString">"Silver"</span>, <span class="stQuotedString">"Expected gold, but got silver"</span>)
* }
* </pre>
*
* <p>
* In case the test code fails, you'll see the screenshot location appended to the error message, for example: