File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -1826,6 +1826,37 @@ public function clearField($field)
1826
1826
$ el ->clear ();
1827
1827
}
1828
1828
1829
+ /**
1830
+ * Type in characters on active element.
1831
+ * With a second parameter you can specify delay between key presses.
1832
+ *
1833
+ * ```php
1834
+ * <?php
1835
+ * // activate input element
1836
+ * $I->click('#input');
1837
+ *
1838
+ * // type text in active element
1839
+ * $I->type('Hello world');
1840
+ *
1841
+ * // type text with a 1sec delay between chars
1842
+ * $I->type('Hello World', 1);
1843
+ * ```
1844
+ *
1845
+ * This might be useful when you an input reacts to typing and you need to slow it down to emulate human behavior.
1846
+ * For instance, this is how Credit Card fields can be filled in.
1847
+ *
1848
+ * @param $text
1849
+ * @param $delay [sec]
1850
+ */
1851
+ public function type ($ text , $ delay = 0 ) {
1852
+ $ keys = str_split ($ text );
1853
+ foreach ($ keys as $ key ) {
1854
+ sleep ($ delay );
1855
+ $ this ->webDriver ->getKeyboard ()->pressKey ($ key );
1856
+ }
1857
+ sleep ($ delay );
1858
+ }
1859
+
1829
1860
public function attachFile ($ field , $ filename )
1830
1861
{
1831
1862
$ el = $ this ->findField ($ field );
Original file line number Diff line number Diff line change @@ -1289,7 +1289,7 @@ public function testLinkWithDocRelativeURLFromDefaultPage()
1289
1289
1290
1290
/*
1291
1291
* @env chrome
1292
- * https://github.com/Codeception/Codeception/issues/1507
1292
+ * @env headless
1293
1293
*/
1294
1294
public function testSubmitFormWithDefaultRadioAndCheckboxValues ()
1295
1295
{
Original file line number Diff line number Diff line change @@ -365,6 +365,16 @@ public function testAppendFieldTextarea()
365
365
$ this ->assertEquals ('eat code ' , $ form ['description ' ]);
366
366
}
367
367
368
+ public function testTypeOnTextarea ()
369
+ {
370
+ $ this ->module ->amOnPage ('/form/textarea ' );
371
+ $ this ->module ->fillField ('form #description ' , '' );
372
+ $ this ->module ->type ('Hello world ' );
373
+ $ this ->module ->click ('Submit ' );
374
+ $ form = data::get ('form ' );
375
+ $ this ->assertEquals ('Hello world ' , $ form ['description ' ]);
376
+ }
377
+
368
378
public function testAppendFieldTextareaFails ()
369
379
{
370
380
$ this ->shouldFail ();
@@ -381,6 +391,16 @@ public function testAppendFieldText()
381
391
$ this ->assertEquals ('OLD_VALUE code ' , $ form ['name ' ]);
382
392
}
383
393
394
+ public function testTypeOnTextField ()
395
+ {
396
+ $ this ->module ->amOnPage ('/form/field ' );
397
+ $ this ->module ->fillField ('form #name ' , '' );
398
+ $ this ->module ->type ('Hello world ' );
399
+ $ this ->module ->click ('Submit ' );
400
+ $ form = data::get ('form ' );
401
+ $ this ->assertEquals ('Hello world ' , $ form ['name ' ]);
402
+ }
403
+
384
404
public function testAppendFieldTextFails ()
385
405
{
386
406
$ this ->shouldFail ();
You can’t perform that action at this time.
0 commit comments