1
1
"""
2
2
This module contains shared utility methods.
3
3
"""
4
- import fasteners
5
4
import subprocess
6
5
import sys
7
- import time
8
- from selenium .common .exceptions import ElementNotVisibleException
9
- from selenium .common .exceptions import NoAlertPresentException
10
- from selenium .common .exceptions import NoSuchAttributeException
11
- from selenium .common .exceptions import NoSuchElementException
12
- from selenium .common .exceptions import NoSuchFrameException
13
- from selenium .common .exceptions import NoSuchWindowException
14
- from seleniumbase .common .exceptions import TextNotVisibleException
15
6
from seleniumbase .fixtures import constants
16
7
from seleniumbase import config as sb_config
17
8
18
9
19
10
def pip_install (package , version = None ):
11
+ import fasteners
12
+
20
13
pip_install_lock = fasteners .InterProcessLock (
21
14
constants .PipInstall .LOCKFILE
22
15
)
@@ -32,11 +25,47 @@ def pip_install(package, version=None):
32
25
)
33
26
34
27
28
+ def is_windows ():
29
+ platform = sys .platform
30
+ if "win32" in platform or "win64" in platform or "x64" in platform :
31
+ return True
32
+ else :
33
+ return False
34
+
35
+
36
+ def get_terminal_width ():
37
+ import os
38
+
39
+ width = 80 # default
40
+ try :
41
+ width = os .get_terminal_size ().columns
42
+ except Exception :
43
+ try :
44
+ if is_windows ():
45
+ raise Exception ("Don't even try 'tput cols' on Windows!" )
46
+ width = int (subprocess .check_output (["tput" , "cols" ]))
47
+ except Exception :
48
+ try :
49
+ import shutil
50
+
51
+ width = shutil .get_terminal_size ((80 , 20 )).columns
52
+ except Exception :
53
+ pass
54
+ return width
55
+
56
+
35
57
def format_exc (exception , message ):
36
58
"""
37
59
Formats an exception message to make the output cleaner.
38
60
"""
61
+ from selenium .common .exceptions import ElementNotVisibleException
62
+ from selenium .common .exceptions import NoAlertPresentException
63
+ from selenium .common .exceptions import NoSuchAttributeException
64
+ from selenium .common .exceptions import NoSuchElementException
65
+ from selenium .common .exceptions import NoSuchFrameException
66
+ from selenium .common .exceptions import NoSuchWindowException
39
67
from seleniumbase .common .exceptions import NoSuchFileException
68
+ from seleniumbase .common .exceptions import TextNotVisibleException
40
69
41
70
if exception == Exception :
42
71
exc = Exception
@@ -101,6 +130,8 @@ def check_if_time_limit_exceeded():
101
130
and sb_config .time_limit
102
131
and not sb_config .recorder_mode
103
132
):
133
+ import time
134
+
104
135
time_limit = sb_config .time_limit
105
136
now_ms = int (time .time () * 1000 )
106
137
if now_ms > sb_config .start_time_ms + sb_config .time_limit_ms :
0 commit comments