16
16
17
17
import time
18
18
import types
19
+ from typing import Optional , Union , Any , List
19
20
20
21
from selenium import webdriver
21
22
from selenium .webdriver .support .event_firing_webdriver import EventFiringWebDriver
@@ -56,16 +57,16 @@ def close_browser(self):
56
57
@keyword
57
58
def open_browser (
58
59
self ,
59
- url = None ,
60
- browser = "firefox" ,
61
- alias = None ,
62
- remote_url = False ,
63
- desired_capabilities = None ,
64
- ff_profile_dir = None ,
65
- options = None ,
66
- service_log_path = None ,
67
- executable_path = None ,
68
- ):
60
+ url : Optional [ str ] = None ,
61
+ browser : str = "firefox" ,
62
+ alias : Optional [ str ] = None ,
63
+ remote_url : Optional [ str ] = False ,
64
+ desired_capabilities : Union [ str , dict , None ] = None ,
65
+ ff_profile_dir : Optional [ str ] = None ,
66
+ options : Any = None ,
67
+ service_log_path : Optional [ str ] = None ,
68
+ executable_path : Optional [ str ] = None ,
69
+ ) -> str :
69
70
"""Opens a new browser instance to the optional ``url``.
70
71
71
72
The ``browser`` argument specifies which browser to use. The
@@ -341,7 +342,7 @@ def _make_new_browser(
341
342
return index
342
343
343
344
@keyword
344
- def create_webdriver (self , driver_name , alias = None , kwargs = {}, ** init_kwargs ):
345
+ def create_webdriver (self , driver_name : str , alias : Optional [ str ] = None , kwargs = {}, ** init_kwargs ) -> str :
345
346
"""Creates an instance of Selenium WebDriver.
346
347
347
348
Like `Open Browser`, but allows passing arguments to the created
@@ -397,7 +398,7 @@ def _wrap_event_firing_webdriver(self, driver):
397
398
return EventFiringWebDriver (driver , self .ctx .event_firing_webdriver ())
398
399
399
400
@keyword
400
- def switch_browser (self , index_or_alias ):
401
+ def switch_browser (self , index_or_alias : str ):
401
402
"""Switches between active browsers using ``index_or_alias``.
402
403
403
404
Indices are returned by the `Open Browser` keyword and aliases can
@@ -434,7 +435,7 @@ def switch_browser(self, index_or_alias):
434
435
)
435
436
436
437
@keyword
437
- def get_browser_ids (self ):
438
+ def get_browser_ids (self ) -> List [ str ] :
438
439
"""Returns index of all active browser as list.
439
440
440
441
Example:
@@ -451,7 +452,7 @@ def get_browser_ids(self):
451
452
return self .drivers .active_driver_ids
452
453
453
454
@keyword
454
- def get_browser_aliases (self ):
455
+ def get_browser_aliases (self ) -> List [ str ] :
455
456
"""Returns aliases of all active browser that has an alias as NormalizedDict.
456
457
The dictionary contains the aliases as keys and the index as value.
457
458
This can be accessed as dictionary ``${aliases.key}`` or as list ``@{aliases}[0]``.
@@ -472,30 +473,30 @@ def get_browser_aliases(self):
472
473
return self .drivers .active_aliases
473
474
474
475
@keyword
475
- def get_session_id (self ):
476
+ def get_session_id (self ) -> str :
476
477
"""Returns the currently active browser session id.
477
478
478
479
New in SeleniumLibrary 3.2
479
480
"""
480
481
return self .driver .session_id
481
482
482
483
@keyword
483
- def get_source (self ):
484
+ def get_source (self ) -> str :
484
485
"""Returns the entire HTML source of the current page or frame."""
485
486
return self .driver .page_source
486
487
487
488
@keyword
488
- def get_title (self ):
489
+ def get_title (self ) -> str :
489
490
"""Returns the title of the current page."""
490
491
return self .driver .title
491
492
492
493
@keyword
493
- def get_location (self ):
494
+ def get_location (self ) -> str :
494
495
"""Returns the current browser window URL."""
495
496
return self .driver .current_url
496
497
497
498
@keyword
498
- def location_should_be (self , url , message = None ):
499
+ def location_should_be (self , url : str , message : Optional [ str ] = None ):
499
500
"""Verifies that the current URL is exactly ``url``.
500
501
501
502
The ``url`` argument contains the exact url that should exist in browser.
@@ -513,7 +514,7 @@ def location_should_be(self, url, message=None):
513
514
self .info (f"Current location is '{ url } '." )
514
515
515
516
@keyword
516
- def location_should_contain (self , expected , message = None ):
517
+ def location_should_contain (self , expected : str , message : Optional [ str ] = None ):
517
518
"""Verifies that the current URL contains ``expected``.
518
519
519
520
The ``expected`` argument contains the expected value in url.
@@ -534,14 +535,14 @@ def location_should_contain(self, expected, message=None):
534
535
self .info (f"Current location contains '{ expected } '." )
535
536
536
537
@keyword
537
- def log_location (self ):
538
+ def log_location (self ) -> str :
538
539
"""Logs and returns the current browser window URL."""
539
540
url = self .get_location ()
540
541
self .info (url )
541
542
return url
542
543
543
544
@keyword
544
- def log_source (self , loglevel = "INFO" ):
545
+ def log_source (self , loglevel : str = "INFO" ) -> str :
545
546
"""Logs and returns the HTML source of the current page or frame.
546
547
547
548
The ``loglevel`` argument defines the used log level. Valid log
@@ -553,14 +554,14 @@ def log_source(self, loglevel="INFO"):
553
554
return source
554
555
555
556
@keyword
556
- def log_title (self ):
557
+ def log_title (self ) -> str :
557
558
"""Logs and returns the title of the current page."""
558
559
title = self .get_title ()
559
560
self .info (title )
560
561
return title
561
562
562
563
@keyword
563
- def title_should_be (self , title , message = None ):
564
+ def title_should_be (self , title : str , message : Optional [ str ] = None ):
564
565
"""Verifies that the current page title equals ``title``.
565
566
566
567
The ``message`` argument can be used to override the default error
@@ -592,7 +593,7 @@ def reload_page(self):
592
593
self .driver .refresh ()
593
594
594
595
@keyword
595
- def get_selenium_speed (self ):
596
+ def get_selenium_speed (self ) -> str :
596
597
"""Gets the delay that is waited after each Selenium command.
597
598
598
599
The value is returned as a human-readable string like ``1 second``.
@@ -602,7 +603,7 @@ def get_selenium_speed(self):
602
603
return secs_to_timestr (self .ctx .speed )
603
604
604
605
@keyword
605
- def get_selenium_timeout (self ):
606
+ def get_selenium_timeout (self ) -> str :
606
607
"""Gets the timeout that is used by various keywords.
607
608
608
609
The value is returned as a human-readable string like ``1 second``.
@@ -612,7 +613,7 @@ def get_selenium_timeout(self):
612
613
return secs_to_timestr (self .ctx .timeout )
613
614
614
615
@keyword
615
- def get_selenium_implicit_wait (self ):
616
+ def get_selenium_implicit_wait (self ) -> str :
616
617
"""Gets the implicit wait value used by Selenium.
617
618
618
619
The value is returned as a human-readable string like ``1 second``.
@@ -622,7 +623,7 @@ def get_selenium_implicit_wait(self):
622
623
return secs_to_timestr (self .ctx .implicit_wait )
623
624
624
625
@keyword
625
- def set_selenium_speed (self , value ) :
626
+ def set_selenium_speed (self , value : str ) -> str :
626
627
"""Sets the delay that is waited after each Selenium command.
627
628
628
629
The value can be given as a number that is considered to be
@@ -642,7 +643,7 @@ def set_selenium_speed(self, value):
642
643
return old_speed
643
644
644
645
@keyword
645
- def set_selenium_timeout (self , value ) :
646
+ def set_selenium_timeout (self , value : str ) -> str :
646
647
"""Sets the timeout that is used by various keywords.
647
648
648
649
The value can be given as a number that is considered to be
@@ -664,7 +665,7 @@ def set_selenium_timeout(self, value):
664
665
return old_timeout
665
666
666
667
@keyword
667
- def set_selenium_implicit_wait (self , value ) :
668
+ def set_selenium_implicit_wait (self , value : str ) -> str :
668
669
"""Sets the implicit wait value used by Selenium.
669
670
670
671
The value can be given as a number that is considered to be
@@ -690,7 +691,7 @@ def set_selenium_implicit_wait(self, value):
690
691
return old_wait
691
692
692
693
@keyword
693
- def set_browser_implicit_wait (self , value ):
694
+ def set_browser_implicit_wait (self , value : str ):
694
695
"""Sets the implicit wait value used by Selenium.
695
696
696
697
Same as `Set Selenium Implicit Wait` but only affects the current
0 commit comments