2013-04-19 12:19:54 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2018-01-17 15:14:43 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2014-01-16 14:58:56 +00:00
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
import argparse
|
2013-04-19 12:19:54 +00:00
|
|
|
import os
|
2014-01-16 14:58:56 +00:00
|
|
|
import sys
|
2013-04-19 12:19:54 +00:00
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
2017-07-26 14:00:47 +00:00
|
|
|
SubCommand,
|
2013-04-19 12:19:54 +00:00
|
|
|
)
|
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MachCommandConditions as conditions,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-07-05 18:09:33 +00:00
|
|
|
def is_firefox_or_android(cls):
|
|
|
|
"""Must have Firefox build or Android build."""
|
|
|
|
return conditions.is_firefox(cls) or conditions.is_android(cls)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
|
|
|
|
def create_parser_tests():
|
2016-12-13 17:10:51 +00:00
|
|
|
from marionette_harness.runtests import MarionetteArguments
|
2016-07-27 04:52:42 +00:00
|
|
|
from mozlog.structured import commandline
|
|
|
|
parser = MarionetteArguments()
|
|
|
|
commandline.add_logging_group(parser)
|
|
|
|
return parser
|
2014-07-18 01:28:45 +00:00
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
|
2016-07-05 18:09:33 +00:00
|
|
|
def run_marionette(tests, binary=None, topsrcdir=None, **kwargs):
|
2015-09-02 22:57:25 +00:00
|
|
|
from mozlog.structured import commandline
|
2014-10-10 16:58:10 +00:00
|
|
|
|
2016-12-13 17:10:51 +00:00
|
|
|
from marionette_harness.runtests import (
|
2013-10-15 19:54:21 +00:00
|
|
|
MarionetteTestRunner,
|
2015-11-09 14:07:52 +00:00
|
|
|
MarionetteHarness
|
2013-10-15 19:54:21 +00:00
|
|
|
)
|
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
parser = create_parser_tests()
|
2013-10-15 19:54:21 +00:00
|
|
|
|
|
|
|
if not tests:
|
|
|
|
tests = [os.path.join(topsrcdir,
|
2017-07-26 14:00:47 +00:00
|
|
|
"testing/marionette/harness/marionette_harness/tests/unit-tests.ini")]
|
2016-02-29 17:39:28 +00:00
|
|
|
|
2016-06-29 16:55:32 +00:00
|
|
|
args = argparse.Namespace(tests=tests)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2016-05-19 21:38:38 +00:00
|
|
|
args.binary = binary
|
2018-03-13 13:49:09 +00:00
|
|
|
args.logger = kwargs.pop('log', None)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2014-10-20 12:55:28 +00:00
|
|
|
for k, v in kwargs.iteritems():
|
2015-08-18 20:27:04 +00:00
|
|
|
setattr(args, k, v)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2015-08-18 20:27:04 +00:00
|
|
|
parser.verify_usage(args)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2017-11-23 18:04:19 +00:00
|
|
|
if not args.logger:
|
|
|
|
args.logger = commandline.setup_logging("Marionette Unit Tests",
|
|
|
|
args,
|
|
|
|
{"mach": sys.stdout})
|
2016-03-19 02:33:08 +00:00
|
|
|
failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
|
2015-11-10 18:09:13 +00:00
|
|
|
if failed > 0:
|
2015-11-09 14:07:52 +00:00
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2013-04-19 12:19:54 +00:00
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
@CommandProvider
|
2018-01-24 19:13:34 +00:00
|
|
|
class MarionetteTest(MachCommandBase):
|
2017-07-26 14:00:47 +00:00
|
|
|
@Command("marionette-test",
|
|
|
|
category="testing",
|
|
|
|
description="Remote control protocol to Gecko, used for functional UI tests and browser automation.",
|
|
|
|
conditions=[is_firefox_or_android],
|
|
|
|
parser=create_parser_tests,
|
|
|
|
)
|
2018-01-24 19:13:34 +00:00
|
|
|
def marionette_test(self, tests, **kwargs):
|
2017-07-26 14:00:47 +00:00
|
|
|
if "test_objects" in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs["test_objects"]:
|
|
|
|
tests.append(obj["file_relpath"])
|
|
|
|
del kwargs["test_objects"]
|
|
|
|
|
|
|
|
if not kwargs.get("binary") and conditions.is_firefox(self):
|
|
|
|
kwargs["binary"] = self.get_binary_path("app")
|
|
|
|
return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
@CommandProvider
|
|
|
|
class Marionette(MachCommandBase):
|
|
|
|
|
|
|
|
@property
|
|
|
|
def srcdir(self):
|
|
|
|
return os.path.join(self.topsrcdir, "testing/marionette")
|
|
|
|
|
|
|
|
@Command("marionette",
|
|
|
|
category="misc",
|
|
|
|
description="Remote control protocol to Gecko, used for functional UI tests and browser automation.",
|
|
|
|
conditions=[is_firefox_or_android],
|
|
|
|
)
|
|
|
|
def marionette(self):
|
|
|
|
self.parser.print_usage()
|
|
|
|
return 1
|
|
|
|
|
|
|
|
@SubCommand("marionette", "test",
|
|
|
|
description="Run browser automation tests based on Marionette harness.",
|
|
|
|
parser=create_parser_tests,
|
|
|
|
)
|
|
|
|
def marionette_test(self, tests, **kwargs):
|
|
|
|
if "test_objects" in kwargs:
|
2015-09-18 13:53:37 +00:00
|
|
|
tests = []
|
2017-07-26 14:00:47 +00:00
|
|
|
for obj in kwargs["test_objects"]:
|
|
|
|
tests.append(obj["file_relpath"])
|
|
|
|
del kwargs["test_objects"]
|
2015-09-18 13:53:37 +00:00
|
|
|
|
2017-07-26 14:00:47 +00:00
|
|
|
if not kwargs.get("binary") and conditions.is_firefox(self):
|
|
|
|
kwargs["binary"] = self.get_binary_path("app")
|
2015-09-02 22:57:25 +00:00
|
|
|
return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
|