本文整理汇总了Python中pyvirtualdisplay.smartdisplay.SmartDisplay.start方法的典型用法代码示例。如果您正苦于以下问题:Python SmartDisplay.start方法的具体用法?Python SmartDisplay.start怎么用?Python SmartDisplay.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvirtualdisplay.smartdisplay.SmartDisplay
的用法示例。
在下文中一共展示了SmartDisplay.start方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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 start [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: VirtualDisplay
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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()
示例4: CuiJsTestCase
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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')
示例5: Test
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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()))
示例6: RealBrowser
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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))
示例7: CuiJsTestCase
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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')
示例8: Hangouts
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [as 别名]
class Hangouts(object):
"""
Main class for controlling hangout calls.
Initialization does two things:
1. Makes sure that there is active X session.
2. Starts the browser.
If 'DISPLAY' can't be found in os.environ than new X session starts.
Starting new session handels `PyVirtualDisplay`_.
.. _PyVirtualDisplay: http://ponty.github.io/PyVirtualDisplay/
For handling browser used seleniumwrapper library.
.. testsetup:: HangoutsBase
import os
os.environ['DISPLAY'] = '1'
from hangout_api import Hangouts
from hangout_api.tests.doctests_utils import DummySelenium
import seleniumwrapper
def get_attribute(self, name):
if name == 'aria-label':
return ' John Doe '
elif name == 'data-userid':
return '108775712935'
else:
return 'hello'
DummySelenium.get_attribute = get_attribute
seleniumwrapper.create = DummySelenium
.. testsetup:: HangoutsBase2
import os
os.environ['DISPLAY'] = '1'
from hangout_api import Hangouts
from hangout_api.tests.doctests_utils import DummySelenium
import seleniumwrapper
DummySelenium.location = {'x': 1}
seleniumwrapper.create = DummySelenium
hangout = Hangouts()
.. doctest:: HangoutsBase
>>> hangout = Hangouts()
"""
def __init__(self, executable_path=None, chrome_options=None):
self.hangout_id = None
self.on_air = None
# lets start display in case if no is available
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {'executable_path': executable_path or CHROMEDRV_PATH}
if chrome_options is not None:
kwargs['chrome_options'] = chrome_options
self.browser = selwrap.create('chrome', **kwargs)
self.utils = Utils(self.browser)
for name, instance in getUtilitiesFor(IModule):
setattr(self, name, instance(self.utils))
def start(self, on_air=None):
"""
Start a new hangout.
After new hangout is created its id is stored in 'hangout_id' attribure
.. doctest:: HangoutsBase
>>> hangout.start()
>>> hangout.hangout_id
'gs4pp6g62w65moctfqsvihzq2qa'
To start OnAir just pass on_air argument to 'start' method.
.. doctest:: HangoutsBase
>>> hangout.start(
... on_air={'name':'My OnAir', 'attendees':['Friends']})
>>> hangout.start(on_air='https://plus.google.com/events/df34...')
"""
# onair
if on_air is not None:
self.on_air = on_air
#.........这里部分代码省略.........
示例9: SeleniumExecutor
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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):
#.........这里部分代码省略.........
示例10: SeleniumExecutor
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [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)
#.........这里部分代码省略.........
示例11: SeleniumExecutor
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [as 别名]
class SeleniumExecutor(ScenarioExecutor, WidgetProvider, FileLister):
"""
Selenium executor
:type virtual_display: Display
"""
SELENIUM_DOWNLOAD_LINK = "http://selenium-release.storage.googleapis.com/{version}/" \
"selenium-server-standalone-{version}.0.jar"
SELENIUM_VERSION = "2.48"
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"]
def __init__(self):
super(SeleniumExecutor, self).__init__()
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 prepare(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:
width = display_conf.get("width", 1024)
height = display_conf.get("height", 768)
self.virtual_display = Display(size=(width, height))
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_type = self.detect_script_type(self.scenario.get(Scenario.SCRIPT))
if script_type == ".py":
runner_class = NoseTester
runner_config = self.settings.get("selenium-tools").get("nose")
elif script_type == ".jar" or script_type == ".java":
runner_class = JUnitTester
runner_config = self.settings.get("selenium-tools").get("junit")
runner_config['props-file'] = self.engine.create_artifact("customrunner", ".properties")
else:
raise ValueError("Unsupported script type: %s" % script_type)
runner_config["script-type"] = script_type
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.scenario, self.get_load(), self.log)
self.runner.prepare()
self.reader = JTLReader(self.kpi_file, self.log, self.err_jtl)
if isinstance(self.engine.aggregator, ConsolidatingAggregator):
self.engine.aggregator.add_underling(self.reader)
def _verify_script(self):
if not self.scenario.get("script"):
if self.scenario.get("requests"):
self.scenario["script"] = self.__tests_from_requests()
else:
raise RuntimeError("Nothing to test, no requests were provided in scenario")
def _cp_resource_files(self, runner_working_dir):
"""
:return:
"""
script = self.scenario.get("script")
if Scenario.SCRIPT in self.scenario:
if os.path.isdir(script):
shutil.copytree(script, runner_working_dir)
else:
os.makedirs(runner_working_dir)
shutil.copy2(script, runner_working_dir)
def detect_script_type(self, script_path):
"""
checks if script is java or python
if it's folder or single script
:return:
#.........这里部分代码省略.........
示例12: Hangouts
# 需要导入模块: from pyvirtualdisplay.smartdisplay import SmartDisplay [as 别名]
# 或者: from pyvirtualdisplay.smartdisplay.SmartDisplay import start [as 别名]
class Hangouts(NavigationHelpers):
"""
Base class that provide all bunch of options.
"""
# TODO: how to show self.display, self.browser and self.hangout_id in
# docs?
def __init__(self, browser="chrome", executable_path=None):
"""
Initialization does two things:
1. Makes sure that there is active X session.
2. Starts browser.
On initialization it stats X session if can't find 'DISPLAY' in
os.environ. For this purposes used *pyvirtualdisplay* package.
For handling browser used seleniumwrapper library.
"""
# lets start display in case if no is available
self.hangout_id = None
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {}
if browser == "chrome":
kwargs['executable_path'] = executable_path or CHROMEDRV_PATH
self.browser = selwrap.create(browser, **kwargs)
self.video = VideoSettings(self)
self.microphone = MicrophoneSettings(self)
self.audio = AudioSettings(self)
self.bandwidth = BandwidthSettings(self)
def start(self, onair=False):
"""
Start new hangout.
"""
if not self.browser.current_url.startswith(URLS.hangouts_active_list):
self.browser.get(URLS.hangouts_active_list)
self.browser.by_class('opd').click(timeout=0.5)
# G+ opens new window for new hangout, so we need to switch selenium to
# it
# waiting until new window appears
while len(self.browser.window_handles) <= 1:
sleep(0.2) # XXX: add waiting for second window to open
self.browser.close() # closing old window
# TODO: 'Google+' title
self.browser.switch_to_window(self.browser.window_handles[0])
self.click_cancel_button_if_there_is_one(timeout=30)
# setting hangout id property
self.hangout_id = self.browser.current_url.replace(
URLS.hangout_session_base, '', 1).split('?', 1)[0]
def connect(self, hangout_id):
"""
Connect to an existing hangout.
Takes id of targeted hangout as argument
"""
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 we need
# to add longer timeout for this
self.browser.by_text('Join', timeout=60).click(timeout=0.5)
def login(self, username=None, password=None, otp=None):
"""
Log into google plus account.
*opt* argument is one time password and is optional,
set it only if you're 2-factor authorization
"""
# 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=0.5)
# filling up one time password if provides
if otp:
self.browser.by_id('smsUserPin').send_keys(otp)
self.browser.by_id('smsVerifyPin').click(timeout=0.5)
# checking if log in was successful
if not self.is_logged_in:
raise LoginError(
'Wasn\'t able to login. Check if credentials are correct'
'and make sure that you have G+ account activated')
#.........这里部分代码省略.........