本文整理汇总了Python中pyvirtualdisplay.smartdisplay.SmartDisplay.stop方法的典型用法代码示例。如果您正苦于以下问题:Python SmartDisplay.stop方法的具体用法?Python SmartDisplay.stop怎么用?Python SmartDisplay.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvirtualdisplay.smartdisplay.SmartDisplay
的用法示例。
在下文中一共展示了SmartDisplay.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
self.p = None
def tearDown(self):
self.p.stop()
self.screen.stop()
# def test_empty(self):
# self.p = EasyProcess('zenity --warning').start()
# wnd is not ready
# self.assertRaises(EmptyScreenException, tab_rectangles)
# def test_zenity(self):
# self.p = EasyProcess('zenity --warning').start()
# self.wait()
# ls = tab_rectangles()
# self.assertEquals(len(ls), 2)
def test_notab(self):
self.p = EasyProcess('xmessage hi').start()
self.wait()
ls = tab_rectangles()
self.assertEquals(len(ls), 0)
def test_gmessage(self):
self.p = EasyProcess('gmessage -buttons x,y,z hi').start()
self.wait()
ls = tab_rectangles()
self.assertEquals(len(ls), 4)
示例2: Test
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
def tearDown(self):
self.p.stop()
self.screen.stop()
# def test_empty(self):
# self.p = EasyProcess('zenity --warning').start()
# wnd is not ready
# time.sleep(0.2)
# self.assertRaises(EmptyScreenException, active_rectangles)
def test_zenity(self):
self.p = EasyProcess('zenity --warning').start()
self.wait()
ls = active_rectangles()
self.assertEquals(len(ls), 1)
def test_notab(self):
self.p = EasyProcess('xmessage -buttons x,y,z hi').start()
self.wait()
ls = active_rectangles(grid=10)
self.assertEquals(len(ls), 3)
def test_gmessage(self):
self.p = EasyProcess('gmessage -buttons x,y,z hi').start()
self.wait()
ls = active_rectangles()
self.assertEquals(len(ls), 3)
示例3: test_slowshot
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
def test_slowshot(self):
disp = SmartDisplay(visible=0).start()
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py).start()
img = disp.waitgrab()
proc.stop()
disp.stop()
eq_(img is not None, True)
示例4: cli_parse
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
def cli_parse():
'''Parse command-line arguments'''
options = {'title': None, 'desc': None, 'date': None,
'time': None, 'id': None}
parser = argparse.ArgumentParser()
parser.add_argument("action", help='''use "create" to create a new event\n
"update" to update an event\n"details" to get event info''') # noqa
parser.add_argument("--title", help="event title")
parser.add_argument("--date", help="event date")
parser.add_argument("--id", help="event id")
parser.add_argument("--desc", help="event description")
parser.add_argument("--filedesc", help="path to txt file w/ event description", # noqa
type=argparse.FileType('r'))
parser.add_argument("--otp", help="2-step verification code")
parser.add_argument("--show", help="1 to display the browser, 0 for invisible virtual display", # noqa
default=0, type=int)
try:
args = parser.parse_args()
except:
parser.print_help()
exit(1)
disp = None
if not args.show: # set up invisible virtual display
from pyvirtualdisplay.smartdisplay import SmartDisplay
try:
disp = SmartDisplay(visible=0, bgcolor='black').start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
raise
if args.title:
options['title'] = args.title
if args.desc:
options['desc'] = args.desc
elif args.filedesc:
options['desc'] = args.filedesc.read()
if args.date:
options['date'] = dtparser.parse(args.date).strftime('%Y-%m-%d')
options['time'] = dtparser.parse(args.date).strftime('%I:%M %p')
if args.id:
options['id'] = args.id
if args.otp:
options['otp'] = args.otp
options['action'] = args.action
return options
示例5: test_disp
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
def test_disp(self):
vd = SmartDisplay().start()
d = SmartDisplay(visible=1).start().sleep(2).stop()
self.assertEquals(d.return_code, 0)
d = SmartDisplay(visible=0).start().stop()
self.assertEquals(d.return_code, 0)
vd.stop()
示例6: VirtualDisplay
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class VirtualDisplay(Service, Singletone):
"""
Selenium executor
:type virtual_display: Display
"""
SHARED_VIRTUAL_DISPLAY = None
def __init__(self):
super(VirtualDisplay, self).__init__()
self.virtual_display = None
def get_virtual_display(self):
return self.virtual_display
def set_virtual_display(self):
if is_windows():
self.log.warning("Cannot have virtual display on Windows, ignoring")
return
if VirtualDisplay.SHARED_VIRTUAL_DISPLAY:
self.virtual_display = VirtualDisplay.SHARED_VIRTUAL_DISPLAY
else:
width = self.parameters.get("width", 1024)
height = self.parameters.get("height", 768)
self.virtual_display = Display(size=(width, height))
msg = "Starting virtual display[%s]: %s"
self.log.info(msg, self.virtual_display.size, self.virtual_display.new_display_var)
self.virtual_display.start()
VirtualDisplay.SHARED_VIRTUAL_DISPLAY = self.virtual_display
self.engine.shared_env.set({'DISPLAY': os.environ['DISPLAY']}) # backward compatibility
def free_virtual_display(self):
if self.virtual_display and self.virtual_display.is_alive():
self.virtual_display.stop()
if VirtualDisplay.SHARED_VIRTUAL_DISPLAY:
VirtualDisplay.SHARED_VIRTUAL_DISPLAY = None
def startup(self):
self.set_virtual_display()
def check_virtual_display(self):
if self.virtual_display:
if not self.virtual_display.is_alive():
self.log.info("Virtual display out: %s", self.virtual_display.stdout)
self.log.warning("Virtual display err: %s", self.virtual_display.stderr)
raise TaurusInternalException("Virtual display failed: %s" % self.virtual_display.return_code)
def check(self):
self.check_virtual_display()
return False
def shutdown(self):
self.free_virtual_display()
示例7: CuiJsTestCase
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class CuiJsTestCase(LiveServerTestCase):
def setUp(self):
# See https://code.djangoproject.com/ticket/10827
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)
def tearDown(self):
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()
def wait_until_expr(self, expr, timeout=60):
WebDriverWait(self.driver, timeout).until(
lambda driver: driver.execute_script('return (%s)' % expr))
def test(self):
sys.stderr.write('\n\nRunning candidate UI unit tests...\n')
sys.stderr.flush()
tests_url = self.live_server_url + reverse('cui_test')
jasmine_spec = os.environ.get('JASMINE_SPEC')
if jasmine_spec:
tests_url += "?spec={}".format(urlquote(jasmine_spec))
self.driver.get(tests_url)
self.wait_until_expr('window.seleniumReporter')
runner = SeleniumRunner(self.driver, sys.stderr)
success = runner.run()
self.assertTrue(success, 'JS tests failed. See full report on stderr')
示例8: Test
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay(visible=VISIBLE)
self.screen.start()
self.p = None
def tearDown(self):
self.p.stop()
self.screen.stop()
def test_zenity(self):
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key('\n')
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key_list(['\n'])
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key(' ')
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key('x')
self.assertTrue(getbbox(grab()))
def test_gcalctool1(self):
self.p = EasyProcess('gnome-calculator').start()
self.wait()
focus_wnd()
send_key('ctrl+q')
time.sleep(1)
# img_debug(grab(), 'ctrl+q')
self.assertFalse(getbbox(grab()))
示例9: RealBrowser
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class RealBrowser(webdriver.Firefox):
def __init__(self, timeout=30):
self._abstract_display = SmartDisplay(visible=0)
self._abstract_display.start()
super(RealBrowser, self).__init__()
self.implicitly_wait(timeout)
def quit(self):
super(RealBrowser, self).quit()
self._abstract_display.stop()
@timeout(REQUEST_TIMEOUT)
def _open(self, url):
self.get(url)
def open(self, url):
try:
self._open(url)
return True
except Exception, e:
logger.error('network error for %s: %s', url, str(e))
示例10: CuiJsTestCase
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class CuiJsTestCase(LiveServerTestCase):
def setUp(self):
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
self.driver = webdriver.Firefox()
def tearDown(self):
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()
def wait_until_expr(self, expr, timeout=60):
WebDriverWait(self.driver, timeout).until(
lambda driver: driver.execute_script('return (%s)' % expr))
def test(self):
sys.stderr.write('\n\nRunning candidate UI unit tests...\n')
sys.stderr.flush()
self.driver.get(self.live_server_url+reverse('cui_test'))
self.wait_until_expr('window.jsApiReporter !== undefined && window.jsApiReporter.finished')
specs = self.driver.execute_script('return window.jsApiReporter.specs()')
self.assertTrue(len(specs) > 0, 'No test results found! The tests probably contain syntax errors.')
passed = True
for spec in specs:
sys.stderr.write(' %s ... %s\n' % (spec['fullName'], spec['status']))
if spec['status'] != 'passed':
passed = False
for exp in spec['failedExpectations']:
sys.stderr.write(' %s\n' % exp['message'])
sys.stderr.write('Access full report at %s\n\n' % reverse('cui_test'))
sys.stderr.flush()
self.assertTrue(passed, 'JS tests failed. See full report on stderr')
示例11: SmartDisplay
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
if args.virtual:
try:
from pyvirtualdisplay.smartdisplay import SmartDisplay
except ImportError:
print "Please install the Python pyvirtualdisplay module."
print " sudo pip install pyvirtualdisplay"
sys.exit(-1)
disp = None
try:
disp = SmartDisplay(visible=0, bgcolor='black').start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
# Start up the web browser and run the tests.
# ----------------------------------------------------------------------------
try:
from selenium import webdriver
except ImportError:
print "Please install the Python selenium module."
print " sudo pip install selenium"
sys.exit(-1)
driver_arguments = {}
if args.browser == "Chrome":
import tempfile, shutil
示例12: Hangouts
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
#.........这里部分代码省略.........
URLS.hangout_session_base, '', 1).split('?', 1)[0]
# @retry(stop_max_attempt_number=3)
def connect(self, hangout_id):
"""
Connect to an existing hangout.
Takes id of targeted hangout as argument.
Also it sets hangout_id property:
.. doctest:: HangoutsBase
>>> hangout.connect('fnar4989hf9834h')
>>> hangout.hangout_id
'fnar4989hf9834h'
"""
self.hangout_id = hangout_id
self.browser.get(URLS.hangout_session_base + hangout_id)
# there may be a big delay before 'Join' button appears, so there is a
# need wait longer than usual
join_button = self.browser.xpath(
'//*[text()="Join" or text()="Okay, got it!"]',
timeout=TIMEOUTS.long)
button_text = names_cleaner(join_button.get_attribute('innerText'))
if button_text == 'Okay, got it!':
# to join hangout we need to set agreement checkbox
self.browser.xpath('//*[@role="presentation"]').click(
timeout=TIMEOUTS.fast)
join_button.click(timeout=TIMEOUTS.average)
self.browser.by_text('Join', timeout=TIMEOUTS.long).click(
timeout=TIMEOUTS.fast)
@retry(stop_max_attempt_number=3)
def login(self, username, password, otp=None):
"""
Log in to google plus.
*otp* argument is one time password and it's optional,
set it only if you're using 2-factor authorization.
.. doctest:: HangoutsBase
>>> hangout.login('[email protected]', 'password')
>>> hangout.login('[email protected]', 'password', otp='123456')
"""
# Open login form and sing in with credentials
self.browser.get(URLS.service_login)
self.browser.by_id('Email').send_keys(username)
self.browser.by_id('Passwd').send_keys(password)
self.browser.by_id('signIn').click(timeout=TIMEOUTS.fast)
# filling up one time password if provides
if otp:
self.browser.by_id('smsUserPin').send_keys(otp)
self.browser.by_id('smsVerifyPin').click(timeout=TIMEOUTS.fast)
# checking if log in was successful
if not self.utils.is_logged_in:
raise LoginError(
'Wasn\'t able to login. Check if credentials are correct'
'and make sure that you have G+ account activated')
@retry(stop_max_attempt_number=3)
示例13: SeleniumExecutor
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class SeleniumExecutor(ScenarioExecutor, WidgetProvider, FileLister):
"""
Selenium executor
:type virtual_display: Display
:type runner: AbstractTestRunner
"""
SELENIUM_DOWNLOAD_LINK = "http://selenium-release.storage.googleapis.com/{version}/" \
"selenium-server-standalone-{version}.0.jar"
SELENIUM_VERSION = "2.53"
JUNIT_DOWNLOAD_LINK = "http://search.maven.org/remotecontent?filepath=junit/junit/{version}/junit-{version}.jar"
JUNIT_VERSION = "4.12"
JUNIT_MIRRORS_SOURCE = "http://search.maven.org/solrsearch/select?q=g%3A%22junit%22%20AND%20a%3A%22junit%22%20" \
"AND%20v%3A%22{version}%22&rows=20&wt=json".format(version=JUNIT_VERSION)
HAMCREST_DOWNLOAD_LINK = "https://hamcrest.googlecode.com/files/hamcrest-core-1.3.jar"
SUPPORTED_TYPES = [".py", ".jar", ".java"]
SHARED_VIRTUAL_DISPLAY = {}
def __init__(self):
super(SeleniumExecutor, self).__init__()
self.additional_env = {}
self.virtual_display = None
self.start_time = None
self.end_time = None
self.runner = None
self.widget = None
self.reader = None
self.kpi_file = None
self.err_jtl = None
self.runner_working_dir = None
self.scenario = None
def set_virtual_display(self):
display_conf = self.settings.get("virtual-display")
if display_conf:
if is_windows():
self.log.warning("Cannot have virtual display on Windows, ignoring")
else:
if self.engine in SeleniumExecutor.SHARED_VIRTUAL_DISPLAY:
self.virtual_display = SeleniumExecutor.SHARED_VIRTUAL_DISPLAY[self.engine]
else:
width = display_conf.get("width", 1024)
height = display_conf.get("height", 768)
self.virtual_display = Display(size=(width, height))
msg = "Starting virtual display[%s]: %s"
self.log.info(msg, self.virtual_display.size, self.virtual_display.new_display_var)
self.virtual_display.start()
SeleniumExecutor.SHARED_VIRTUAL_DISPLAY[self.engine] = self.virtual_display
def free_virtual_display(self):
if self.virtual_display and self.virtual_display.is_alive():
self.virtual_display.stop()
if self.engine in SeleniumExecutor.SHARED_VIRTUAL_DISPLAY:
del SeleniumExecutor.SHARED_VIRTUAL_DISPLAY[self.engine]
def _get_script_path(self):
script = self.scenario.get(Scenario.SCRIPT)
if not script:
return None
return self.engine.find_file(script)
def prepare(self):
self.set_virtual_display()
self.scenario = self.get_scenario()
self._verify_script()
self.kpi_file = self.engine.create_artifact("selenium_tests_report", ".csv")
self.err_jtl = self.engine.create_artifact("selenium_tests_err", ".xml")
script_path = self._get_script_path()
script_type = self.detect_script_type(script_path)
runner_config = BetterDict()
if script_type == ".py":
runner_class = NoseTester
runner_config.merge(self.settings.get("selenium-tools").get("nose"))
else: # script_type == ".jar" or script_type == ".java":
runner_class = JUnitTester
runner_config.merge(self.settings.get("selenium-tools").get("junit"))
runner_config['props-file'] = self.engine.create_artifact("customrunner", ".properties")
runner_config["script-type"] = script_type
if self.runner_working_dir is None:
self.runner_working_dir = self.engine.create_artifact(runner_config.get("working-dir", "classes"), "")
runner_config["working-dir"] = self.runner_working_dir
runner_config.get("artifacts-dir", self.engine.artifacts_dir)
runner_config.get("working-dir", self.runner_working_dir)
runner_config.get("report-file", self.kpi_file)
runner_config.get("err-file", self.err_jtl)
runner_config.get("stdout", self.engine.create_artifact("junit", ".out"))
runner_config.get("stderr", self.engine.create_artifact("junit", ".err"))
self._cp_resource_files(self.runner_working_dir)
self.runner = runner_class(runner_config, self)
self.runner.prepare()
self.reader = JTLReader(self.kpi_file, self.log, self.err_jtl)
if isinstance(self.engine.aggregator, ConsolidatingAggregator):
#.........这里部分代码省略.........
示例14: SeleniumExecutor
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
class SeleniumExecutor(ScenarioExecutor, WidgetProvider, FileLister):
"""
Selenium executor
:type virtual_display: Display
:type runner: AbstractTestRunner
"""
SELENIUM_DOWNLOAD_LINK = "http://selenium-release.storage.googleapis.com/{version}/" \
"selenium-server-standalone-{version}.0.jar"
SELENIUM_VERSION = "2.53"
JUNIT_DOWNLOAD_LINK = "http://search.maven.org/remotecontent?filepath=junit/junit/" \
"{version}/junit-{version}.jar"
JUNIT_VERSION = "4.12"
JUNIT_MIRRORS_SOURCE = "http://search.maven.org/solrsearch/select?q=g%3A%22junit%22%20AND%20a%3A%22" \
"junit%22%20AND%20v%3A%22{version}%22&rows=20&wt=json".format(version=JUNIT_VERSION)
HAMCREST_DOWNLOAD_LINK = "http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core" \
"/1.3/hamcrest-core-1.3.jar"
JSON_JAR_DOWNLOAD_LINK = "http://search.maven.org/remotecontent?filepath=org/json/json/20160810/json-20160810.jar"
SUPPORTED_TYPES = ["python-nose", "java-junit", "ruby-rspec"]
SHARED_VIRTUAL_DISPLAY = {}
def __init__(self):
super(SeleniumExecutor, self).__init__()
self.additional_env = {}
self.virtual_display = None
self.end_time = None
self.runner = None
self.report_file = None
self.scenario = None
self.script = None
self.self_generated_script = False
self.generated_methods = BetterDict()
self.runner_working_dir = None
def set_virtual_display(self):
display_conf = self.settings.get("virtual-display")
if display_conf:
if is_windows():
self.log.warning("Cannot have virtual display on Windows, ignoring")
else:
if self.engine in SeleniumExecutor.SHARED_VIRTUAL_DISPLAY:
self.virtual_display = SeleniumExecutor.SHARED_VIRTUAL_DISPLAY[self.engine]
else:
width = display_conf.get("width", 1024)
height = display_conf.get("height", 768)
self.virtual_display = Display(size=(width, height))
msg = "Starting virtual display[%s]: %s"
self.log.info(msg, self.virtual_display.size, self.virtual_display.new_display_var)
self.virtual_display.start()
SeleniumExecutor.SHARED_VIRTUAL_DISPLAY[self.engine] = self.virtual_display
def free_virtual_display(self):
if self.virtual_display and self.virtual_display.is_alive():
self.virtual_display.stop()
if self.engine in SeleniumExecutor.SHARED_VIRTUAL_DISPLAY:
del SeleniumExecutor.SHARED_VIRTUAL_DISPLAY[self.engine]
def get_script_path(self, scenario=None):
if scenario:
return super(SeleniumExecutor, self).get_script_path(scenario)
else:
return self.engine.find_file(self.script)
def get_runner_working_dir(self):
if self.runner_working_dir is None:
self.runner_working_dir = self.engine.create_artifact("classes", "")
return self.runner_working_dir
def _create_runner(self, report_file):
script_path = self.get_script_path()
script_type = self.detect_script_type(script_path)
runner_config = BetterDict()
if script_type == "python-nose":
runner_class = NoseTester
runner_config.merge(self.settings.get("selenium-tools").get("nose"))
elif script_type == "java-junit":
runner_class = JUnitTester
runner_config.merge(self.settings.get("selenium-tools").get("junit"))
runner_config['working-dir'] = self.get_runner_working_dir()
runner_config['props-file'] = self.engine.create_artifact("customrunner", ".properties")
elif script_type == "ruby-rspec":
runner_class = RSpecTester
elif script_type == "js-mocha":
runner_class = MochaTester
else:
raise ValueError("Unsupported script type: %s" % script_type)
runner_config["script"] = script_path
runner_config["script-type"] = script_type
runner_config["artifacts-dir"] = self.engine.artifacts_dir
runner_config["report-file"] = report_file
runner_config["stdout"] = self.engine.create_artifact("selenium", ".out")
runner_config["stderr"] = self.engine.create_artifact("selenium", ".err")
return runner_class(runner_config, self)
#.........这里部分代码省略.........
示例15: SeleniumExecutor
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import stop [as 别名]
#.........这里部分代码省略.........
for dir_entry in os.walk(script_path):
if dir_entry[2]:
for test_file in dir_entry[2]:
if os.path.splitext(test_file)[1].lower() in SeleniumExecutor.SUPPORTED_TYPES:
test_files.append(test_file)
if os.path.isdir(script_path):
file_ext = os.path.splitext(test_files[0])[1].lower()
else:
file_ext = os.path.splitext(script_path)[1]
if file_ext not in SeleniumExecutor.SUPPORTED_TYPES:
raise RuntimeError("Supported tests types %s was not found" % SeleniumExecutor.SUPPORTED_TYPES)
return file_ext
def startup(self):
"""
Start runner
:return:
"""
self.start_time = time.time()
if self.virtual_display:
msg = "Starting virtual display[%s]: %s"
self.log.info(msg, self.virtual_display.size, self.virtual_display.new_display_var)
self.virtual_display.start()
self.runner.run_tests()
def check(self):
"""
check if test completed
:return:
"""
if self.widget:
self.widget.update()
if self.virtual_display:
if not self.virtual_display.is_alive():
self.log.info("Virtual display out: %s", self.virtual_display.stdout)
self.log.warning("Virtual display err: %s", self.virtual_display.stderr)
raise RuntimeError("Virtual display failed: %s" % self.virtual_display.return_code)
return self.runner.is_finished()
def shutdown(self):
"""
shutdown test_runner
:return:
"""
try:
self.runner.shutdown()
finally:
if self.virtual_display and self.virtual_display.is_alive():
self.virtual_display.stop()
if self.start_time:
self.end_time = time.time()
self.log.debug("Selenium tests ran for %s seconds", self.end_time - self.start_time)
def post_process(self):
if self.reader and not self.reader.read_records:
raise RuntimeWarning("Empty results, most likely Selenium failed")
def get_widget(self):
if not self.widget:
self.widget = SeleniumWidget(self.scenario.get("script"), self.runner.settings.get("stdout"))
return self.widget
def resource_files(self):
if not self.scenario:
self.scenario = self.get_scenario()
if "script" not in self.scenario:
return []
script = self.scenario.get("script")
script_type = self.detect_script_type(script)
if script_type == ".py":
runner_config = self.settings.get("selenium-tools").get("nose")
elif script_type == ".jar" or script_type == ".java":
runner_config = self.settings.get("selenium-tools").get("junit")
else:
raise ValueError("Unsupported script type: %s" % script_type)
if self.runner_working_dir is None:
self.runner_working_dir = self.engine.create_artifact(runner_config.get("working-dir", "classes"), "")
self._cp_resource_files(self.runner_working_dir)
return [os.path.basename(self.runner_working_dir)]
def __tests_from_requests(self):
filename = self.engine.create_artifact("test_requests", ".py")
nose_test = SeleniumScriptBuilder(self.scenario, self.log)
if self.virtual_display:
nose_test.window_size=self.virtual_display.size
nose_test.scenario = self.scenario
nose_test.gen_test_case()
nose_test.save(filename)
return filename