1#!/usr/bin/env python3 2# Copyright (C) 2021 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import argparse 17import os 18import sys 19 20UI_DIR = os.path.dirname(__file__) 21 22 23def main(): 24 parser = argparse.ArgumentParser() 25 parser.add_argument( 26 '--interactive', 27 '-i', 28 action='store_true', 29 help='Run in interactive mode') 30 parser.add_argument( 31 '--rebaseline', '-r', action='store_true', help='Rebaseline screenshots') 32 parser.add_argument('--out', help='out directory') 33 parser.add_argument('--no-build', action='store_true') 34 parser.add_argument('filters', nargs='*') 35 args = parser.parse_args() 36 37 cmd = ['./pnpm', 'exec', 'playwright', 'test'] 38 if args.interactive: 39 if args.rebaseline: 40 print('--interactive and --rebaseline are mutually exclusive') 41 return 1 42 cmd += ['--ui'] 43 elif args.rebaseline: 44 cmd += ['--update-snapshots'] 45 cmd += args.filters 46 47 env = dict(os.environ.items()) 48 dev_server_args = [] 49 if args.out: 50 out_rel_path = os.path.relpath(args.out, UI_DIR) 51 env['OUT_DIR'] = out_rel_path 52 dev_server_args += ['--out', out_rel_path] 53 if args.no_build: 54 dev_server_args += ['--no-build'] 55 env['DEV_SERVER_ARGS'] = ' '.join(dev_server_args) 56 os.chdir(UI_DIR) 57 os.execve(cmd[0], cmd, env) 58 59 60if __name__ == '__main__': 61 sys.exit(main()) 62