17
17
Allows to spin up selenium containers for testing with browsers.
18
18
"""
19
19
20
+ from selenium import webdriver
20
21
from testcontainers .core .container import DockerContainer
21
22
from testcontainers .core .waiting_utils import wait_container_is_ready
23
+ from typing import Optional
22
24
import urllib3
23
25
24
26
28
30
}
29
31
30
32
31
- def get_image_name (capabilities ) :
33
+ def get_image_name (capabilities : str ) -> str :
32
34
return IMAGES [capabilities ['browserName' ]]
33
35
34
36
@@ -49,29 +51,28 @@ class BrowserWebDriverContainer(DockerContainer):
49
51
You can easily change browser by passing :code:`DesiredCapabilities.FIREFOX` instead.
50
52
"""
51
53
52
- def __init__ (self , capabilities , image = None , ** kwargs ):
54
+ def __init__ (self , capabilities : str , image : Optional [ str ] = None , ** kwargs ) -> None :
53
55
self .capabilities = capabilities
54
56
self .image = image or get_image_name (capabilities )
55
57
self .port_to_expose = 4444
56
58
self .vnc_port_to_expose = 5900
57
59
super (BrowserWebDriverContainer , self ).__init__ (image = self .image , ** kwargs )
58
60
self .with_exposed_ports (self .port_to_expose , self .vnc_port_to_expose )
59
61
60
- def _configure (self ):
62
+ def _configure (self ) -> None :
61
63
self .with_env ("no_proxy" , "localhost" )
62
64
self .with_env ("HUB_ENV_no_proxy" , "localhost" )
63
65
64
66
@wait_container_is_ready (urllib3 .exceptions .HTTPError )
65
- def _connect (self ):
66
- from selenium import webdriver
67
+ def _connect (self ) -> webdriver .Remote :
67
68
return webdriver .Remote (
68
69
command_executor = (self .get_connection_url ()),
69
70
desired_capabilities = self .capabilities )
70
71
71
- def get_driver (self ):
72
+ def get_driver (self ) -> webdriver . Remote :
72
73
return self ._connect ()
73
74
74
75
def get_connection_url (self ) -> str :
75
76
ip = self .get_container_host_ip ()
76
77
port = self .get_exposed_port (self .port_to_expose )
77
- return 'http://{}:{}/wd/hub' . format ( ip , port )
78
+ return f 'http://{ ip } :{ port } /wd/hub'
0 commit comments