Skip to content

Commit 610a92d

Browse files
committed
Refactor seleniumbase imports
1 parent e8be9f6 commit 610a92d

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

seleniumbase/core/log_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# -*- coding: utf-8 -*-
22
import codecs
3-
import datetime
43
import os
54
import shutil
65
import sys
76
import time
8-
import traceback
97
from seleniumbase.config import settings
108

119

@@ -29,6 +27,7 @@ def log_screenshot(test_logpath, driver, screenshot=None, get=False):
2927

3028
def get_master_time():
3129
""" Returns (timestamp, the_date, the_time) """
30+
import datetime
3231
timestamp = str(int(time.time())) + " (Unix Timestamp)"
3332
now = datetime.datetime.now()
3433
utc_offset = -time.timezone / 3600.0
@@ -61,6 +60,7 @@ def get_master_time():
6160

6261

6362
def log_test_failure_data(test, test_logpath, driver, browser, url=None):
63+
import traceback
6464
basic_info_name = settings.BASIC_INFO_NAME
6565
basic_file_path = "%s/%s" % (test_logpath, basic_info_name)
6666
log_file = codecs.open(basic_file_path, "w+", "utf-8")

seleniumbase/fixtures/base_case.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def test_anything(self):
2525
import codecs
2626
import json
2727
import logging
28-
import math
2928
import os
3029
import re
3130
import sys
@@ -43,7 +42,6 @@ def test_anything(self):
4342
from seleniumbase.common import decorators
4443
from seleniumbase.config import settings
4544
from seleniumbase.core import log_helper
46-
from seleniumbase.core import tour_helper
4745
from seleniumbase.fixtures import constants
4846
from seleniumbase.fixtures import css_to_xpath
4947
from seleniumbase.fixtures import js_utils
@@ -5491,6 +5489,8 @@ def play_tour(self, name=None, interval=0):
54915489
interval - The delay time between autoplaying tour steps. (Seconds)
54925490
If set to 0 (default), the tour is fully manual control.
54935491
"""
5492+
from seleniumbase.core import tour_helper
5493+
54945494
if self.headless:
54955495
return # Tours should not run in headless mode.
54965496

@@ -5542,6 +5542,7 @@ def export_tour(self, name=None, filename="my_tour.js", url=None):
55425542
save the tour to.
55435543
url - The URL where the tour starts. If not specified, the URL
55445544
of the current page will be used. """
5545+
from seleniumbase.core import tour_helper
55455546
if not url:
55465547
url = self.get_current_url()
55475548
tour_helper.export_tour(
@@ -6470,6 +6471,7 @@ def check_window(self, name="default", level=0, baseline=False):
64706471

64716472
def __get_new_timeout(self, timeout):
64726473
""" When using --timeout_multiplier=#.# """
6474+
import math
64736475
self.__check_scope()
64746476
try:
64756477
timeout_multiplier = float(self.timeout_multiplier)

seleniumbase/fixtures/css_to_xpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
Convert CSS selectors into XPath selectors
33
"""
4-
5-
from cssselect.xpath import GenericTranslator, is_non_whitespace
4+
from cssselect.xpath import GenericTranslator
65

76

87
class ConvertibleToCssTranslator(GenericTranslator):
@@ -20,6 +19,7 @@ def xpath_attrib_equals(self, xpath, name, value):
2019
return xpath
2120

2221
def xpath_attrib_includes(self, xpath, name, value):
22+
from cssselect.xpath import is_non_whitespace
2323
if is_non_whitespace(value):
2424
xpath.add_condition(
2525
"contains(%s, %s)"

seleniumbase/fixtures/page_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
from selenium.webdriver.remote.errorhandler import NoSuchFrameException
3434
from selenium.webdriver.remote.errorhandler import NoSuchWindowException
3535
from seleniumbase.config import settings
36-
from seleniumbase.core import log_helper
37-
from seleniumbase.fixtures import page_utils
3836
from seleniumbase.fixtures import shared_utils as s_utils
3937
ENI_Exception = selenium_exceptions.ElementNotInteractableException
4038

@@ -598,6 +596,7 @@ def save_page_source(driver, name, folder=None):
598596
name - The file name to save the current page's HTML to.
599597
folder - The folder to save the file to. (Default = current folder)
600598
"""
599+
from seleniumbase.core import log_helper
601600
if not name.endswith(".html"):
602601
name = name + ".html"
603602
if folder:
@@ -716,6 +715,7 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
716715
frame - the frame element, name, id, index, or selector
717716
timeout - the time to wait for the alert in seconds
718717
"""
718+
from seleniumbase.fixtures import page_utils
719719
start_ms = time.time() * 1000.0
720720
stop_ms = start_ms + (timeout * 1000.0)
721721
for x in range(int(timeout * 10)):

seleniumbase/fixtures/xpath_to_css.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Convert XPath selectors into CSS selectors
33
"""
4-
54
import re
65

76
_sub_regexes = {

seleniumbase/plugins/base_plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import sys
55
import time
66
from nose.plugins import Plugin
7-
from nose.exc import SkipTest
87
from seleniumbase.config import settings
98
from seleniumbase.core import download_helper
109
from seleniumbase.core import log_helper
1110
from seleniumbase.core import report_helper
12-
from seleniumbase.fixtures import constants, errors
11+
from seleniumbase.fixtures import constants
1312

1413

1514
class Base(Plugin):
@@ -227,6 +226,7 @@ def addError(self, test, err, capt=None):
227226
error states, we want to make sure that they don't show up in
228227
the nose output as errors.
229228
"""
229+
from seleniumbase.fixtures import errors
230230
if (err[0] == errors.BlockedTest or (
231231
err[0] == errors.SkipTest) or (
232232
err[0] == errors.DeprecatedTest)):
@@ -243,6 +243,8 @@ def handleError(self, test, err, capt=None):
243243
If the database plugin is not present, we have to handle capturing
244244
"errors" that shouldn't be reported as such in base.
245245
"""
246+
from nose.exc import SkipTest
247+
from seleniumbase.fixtures import errors
246248
if not hasattr(test.test, "testcase_guid"):
247249
if err[0] == errors.BlockedTest:
248250
raise SkipTest(err[1])

0 commit comments

Comments
 (0)