def test_managed_protractor_with_invalid_sharding_instances(self): popen_calls = self.exit_stack.enter_context(self.swap_popen()) with self.assertRaisesRegex(ValueError, 'should be larger than 0'): self.exit_stack.enter_context( servers.managed_protractor_server(sharding_instances=0)) with self.assertRaisesRegex(ValueError, 'should be larger than 0'): self.exit_stack.enter_context( servers.managed_protractor_server(sharding_instances=-1)) self.exit_stack.close() self.assertEqual(len(popen_calls), 0)
def test_managed_protractor_with_explicit_args(self): popen_calls = self.exit_stack.enter_context(self.swap_popen()) self.exit_stack.enter_context( servers.managed_protractor_server(suite_name='abc', sharding_instances=3, debug_mode=True, dev_mode=False, stdout=subprocess.PIPE)) self.exit_stack.close() self.assertEqual(len(popen_calls), 1) self.assertEqual(popen_calls[0].kwargs, { 'shell': True, 'stdout': subprocess.PIPE }) program_args = popen_calls[0].program_args # From debug_mode=True. self.assertIn('--inspect-brk', program_args) # From sharding_instances=3. self.assertIn('--capabilities.shardTestFiles=True', program_args) self.assertIn('--capabilities.maxInstances=3', program_args) # From dev_mode=True. self.assertIn('--params.devMode=False', program_args) # From suite='full'. self.assertIn('--suite abc', program_args)
def test_managed_protractor(self): popen_calls = self.exit_stack.enter_context(self.swap_popen()) self.exit_stack.enter_context(servers.managed_protractor_server()) self.exit_stack.close() self.assertEqual(len(popen_calls), 1) self.assertEqual(popen_calls[0].kwargs, {'shell': True}) program_args = popen_calls[0].program_args self.assertIn( '%s --unhandled-rejections=strict %s %s' % (common.NODE_BIN_PATH, common.PROTRACTOR_BIN_PATH, common.PROTRACTOR_CONFIG_FILE_PATH), program_args) self.assertNotIn('--inspect-brk', program_args) self.assertIn('--params.devMode=True', program_args) self.assertIn('--suite full', program_args)
def run_tests(args): """Run the scripts to start end-to-end tests.""" if is_oppia_server_already_running(): sys.exit(1) install_third_party_libraries(args.skip_install) with contextlib.ExitStack() as stack: dev_mode = not args.prod_env if args.skip_build: build.modify_constants(prod_env=args.prod_env) else: build_js_files(dev_mode, source_maps=args.source_maps) stack.callback(build.set_constants_to_default) stack.enter_context(servers.managed_redis_server()) stack.enter_context(servers.managed_elasticsearch_dev_server()) if constants.EMULATOR_MODE: stack.enter_context(servers.managed_firebase_auth_emulator()) stack.enter_context( servers.managed_cloud_datastore_emulator(clear_datastore=True)) app_yaml_path = 'app.yaml' if args.prod_env else 'app_dev.yaml' stack.enter_context( servers.managed_dev_appserver( app_yaml_path, port=GOOGLE_APP_ENGINE_PORT, log_level=args.server_log_level, # Automatic restart can be disabled since we don't expect code # changes to happen while the e2e tests are running. automatic_restart=False, skip_sdk_update_check=True, env={ **os.environ, 'PORTSERVER_ADDRESS': common.PORTSERVER_SOCKET_FILEPATH, })) stack.enter_context( servers.managed_webdriver_server( chrome_version=args.chrome_driver_version)) proc = stack.enter_context( servers.managed_protractor_server( suite_name=args.suite, dev_mode=dev_mode, debug_mode=args.debug_mode, sharding_instances=args.sharding_instances, stdout=subprocess.PIPE)) print('Servers have come up.\n' 'Note: If ADD_SCREENSHOT_REPORTER is set to true in ' 'core/tests/protractor.conf.js, you can view screenshots of the ' 'failed tests in ../protractor-screenshots/') output_lines = [] while True: # Keep reading lines until an empty string is returned. Empty # strings signal that the process has ended. for line in iter(proc.stdout.readline, b''): if isinstance(line, str): # Although our unit tests always provide unicode strings, # the actual server needs this failsafe since it can output # non-unicode strings. line = line.encode('utf-8') # pragma: no cover output_lines.append(line.rstrip()) # Replaces non-ASCII characters with '?'. common.write_stdout_safe(line.decode('ascii', errors='replace')) # The poll() method returns None while the process is running, # otherwise it returns the return code of the process (an int). if proc.poll() is not None: break return output_lines, proc.returncode