diff --git a/integration/stick/phpunittest.py b/integration/stick/phpunittest.py index 365435e..82f30c8 100644 --- a/integration/stick/phpunittest.py +++ b/integration/stick/phpunittest.py @@ -1,129 +1,126 @@ import time import subprocess -import sys from . import conf from integrationtest import KolabIntegrationTest class KolabPhpunitTest(KolabIntegrationTest): """ Base class for running Roundcube Selenium tests through phpunit This assumes Roundcube being installed with dev dependencies that include the phpunit/phpunit-selenium package. """ server = None env = {} @classmethod def setUpClass(self, *args, **kw): super(KolabPhpunitTest, self).setUpClass(*args, **kw) def tearDown(self, *args, **kw): self._stop_server() super(KolabPhpunitTest, self).tearDown(*args, **kw) def stop(self): self._stop_server() def _start_server(self): # only start once if self.server is None: server_jar = self.get_conf('testing', 'selenium_server_jar', 'selenium-server-standalone-2.45.0.jar') self.log("Starting Selenium server %r" % (server_jar)) self.server = subprocess.Popen(['java', '-jar', server_jar], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) ready = False while not ready and not self.server.stdout.closed and self.server.poll() is None: line = self.server.stdout.readline() self.log("* " + line.strip()) if line is None: break elif "Started SocketListener" in line: ready = True elif "Failed" in line or "Error" in line: break if ready: self.log("Selenium server started.") - self.server.stdout = sys.stdout - self.server.stderr = sys.stderr else: raise Exception("Failed to start Selenium server") self.env['ROUNDCUBE_TESTS_BROWSER'] = 'phantomjs' def _stop_server(self): if self.server: self.server.terminate() self.server = None self.log("Selenium server stopped") def set_env(self, var, value): """ Set Roundcube config variable through env variables """ self.env['ROUNDCUBE_' + var.upper()] = value def set_login(self, username, password): """ Set Roundcube login username and password for subsequent phpunit runs """ self.set_env('tests_username', username) self.set_env('tests_password', password) def execute(self, testfile=None, testsuite=None, testfilter=None, selenium=False, groups=None, excludes=None, message=None): """ Execute phpunit on a Roundcube test instance """ cwd = self.get_conf('testing', 'roundcube_dir', '/usr/share/roundcubemail') pbin = self.get_conf('testing', 'phpunit_bin', 'phpunit') cxml = 'tests/Selenium/phpunit.xml' if selenium else 'tests/phpunit.xml' args = [ pbin, '--configuration', cxml ] if self.verbose: args.append('--verbose') if testfile: args.append(testfile) else: if testsuite: args.append('--testsuite') args.append(testsuite) if testfilter: args.append('--filter') args.append(testfilter) if groups: if not isinstance(groups, list): groups = [groups] for group in groups: args.append('--group') args.append(group) if excludes: if not isinstance(excludes, list): excludes = [excludes] for group in excludes: args.append('--exclude-group') args.append(group) if not conf.cli_keywords.todo: args.append('--disallow-todo-tests') if selenium: self._start_server() self.log("Executing %r with %r" % (args, self.env)) p = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.env) for line in iter(p.stdout.readline, ''): self.log(line.strip()) retval = p.wait() self.assertEqual(retval, 0, message)