def testLaunchCommand_make_cmd_list_for_failed_tests( self, fill_xctest_run_mock): fill_xctest_run_mock.side_effect = ['/var/folders/tmpfile1'] egtest_app = 'module_1_egtests.app' egtest_app_path = '%s/%s' % (_ROOT_FOLDER_PATH, egtest_app) failed_tests = { egtest_app: [ 'TestCase1_1/TestMethod1', 'TestCase1_1/TestMethod2', 'TestCase1_2/TestMethod1', ] } expected_egtests = xcodebuild_runner.EgtestsApp( egtest_app_path, filtered_tests=failed_tests[egtest_app]) mock_egtest = mock.MagicMock(spec=xcodebuild_runner.EgtestsApp) type(mock_egtest).egtests_path = mock.PropertyMock( return_value=egtest_app_path) cmd = xcodebuild_runner.LaunchCommand( egtests_app=mock_egtest, destination=_DESTINATION, out_dir='out/dir/attempt_2/iPhone X 12.0', shards=1, retries=1) cmd._make_cmd_list_for_failed_tests( failed_tests, os.path.join(_OUT_DIR, 'attempt_2')) self.assertEqual(1, len(fill_xctest_run_mock.mock_calls)) self.assertItemsEqual( expected_egtests.__dict__, fill_xctest_run_mock.mock_calls[0][1][1].__dict__)
def get_wpr_test_command(self, recipe_path, test_name): """Creates xcodebuild commands for running a wpr test per recipe_path. Args: recipe_path: (str) Path to wpr recipe file. test_name: (str) Test name(format: ios_website) of this wpr test. Returns: Xcodebuild command to run in the format of a list of str. """ wpr_test_args = [ '--enable-features=AutofillShowTypePredictions', '-autofillautomation=%s' % recipe_path, ] wpr_egtests_app = xcodebuild_runner.EgtestsApp( self.app_path, included_tests=["AutofillAutomationTestCase"], env_vars=self.env_vars, test_args=wpr_test_args, host_app_path=self.host_app_path) self.test_attempt_count[test_name] = self.test_attempt_count.get( test_name, 0) + 1 destination = 'platform=iOS Simulator,OS=%s,name=%s' % (self.version, self.platform) destination_folder = '%s %s %s attempt#%s' % ( self.version, self.platform, test_name, self.test_attempt_count[test_name]) out_dir = os.path.join(self.out_dir, destination_folder) launch_command = xcodebuild_runner.LaunchCommand( wpr_egtests_app, destination, self.shards, self.retries) return launch_command.command(wpr_egtests_app, out_dir, destination, self.shards)
def testEgtests_xctestRunNode_with_filter_skip_identifiers(self): skipped_tests = ['TestCase1/testMethod1', 'TestCase1/testMethod2', 'TestCase2/testMethod1', 'TestCase1/testMethod2'] egtest_node = xcodebuild_runner.EgtestsApp( _EGTESTS_APP_PATH, excluded_tests=skipped_tests ).xctestrun_node()['any_egtests_module'] self.assertEqual(skipped_tests, egtest_node['SkipTestIdentifiers']) self.assertNotIn('OnlyTestIdentifiers', egtest_node)
def testEgtests_xctestRunNode_without_filter(self, mock_path_exists, mock_listdir): mock_path_exists.return_value = True mock_listdir.return_value = ['any_egtests.xctest'] egtest_node = xcodebuild_runner.EgtestsApp( _EGTESTS_APP_PATH).xctestrun_node()['any_egtests_module'] self.assertNotIn('OnlyTestIdentifiers', egtest_node) self.assertNotIn('SkipTestIdentifiers', egtest_node)
def testEgtests_xctestRunNode_with_filter_only_identifiers(self, mock_listdir): mock_listdir.return_value = ['any_egtests.xctest'] filtered_tests = ['TestCase1/testMethod1', 'TestCase1/testMethod2', 'TestCase2/testMethod1', 'TestCase1/testMethod2'] egtest_node = xcodebuild_runner.EgtestsApp( _EGTESTS_APP_PATH, included_tests=filtered_tests).xctestrun_node()[ 'any_egtests_module'] self.assertEqual(filtered_tests, egtest_node['OnlyTestIdentifiers']) self.assertNotIn('SkipTestIdentifiers', egtest_node)
def testLaunchCommand_restartFailed1stAttempt(self, mock_listdir): mock_listdir.return_value = ['any_egtests.xctest'] egtests = xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH) launch_command = xcodebuild_runner.LaunchCommand(egtests, _DESTINATION, shards=1, retries=3, out_dir=self.tmpdir) self.fake_launch_attempt(launch_command, ['not_started', 'pass']) launch_command.launch() self.assertEqual(2, len(launch_command.test_results))
def testEgtests_xctestRunNode_with_filter_skip_identifiers( self, mock_path_exists, mock_listdir): mock_path_exists.return_value = True mock_listdir.return_value = ['any_egtests.xctest'] skipped_tests = [ 'TestCase1/testMethod1', 'TestCase1/testMethod2', 'TestCase2/testMethod1', 'TestCase1/testMethod2' ] egtest_node = xcodebuild_runner.EgtestsApp( _EGTESTS_APP_PATH, filtered_tests=skipped_tests, invert=True).xctestrun_node()['any_egtests_module'] self.assertEqual(skipped_tests, egtest_node['SkipTestIdentifiers']) self.assertNotIn('OnlyTestIdentifiers', egtest_node)
def testLaunchCommand_restartFailed1stAttempt(self, mock_collect_results, xcode_version): egtests = xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH) xcode_version.return_value = {'version': '10.2.1'} mock_collect_results.side_effect = [ {'failed': {'TESTS_DID_NOT_START': ['not started']}, 'passed': []}, {'failed': {}, 'passed': ['Class1/passedTest1', 'Class1/passedTest2']} ] launch_command = xcodebuild_runner.LaunchCommand(egtests, _DESTINATION, shards=1, retries=3, out_dir=self.tmpdir) self.fake_launch_attempt(launch_command, ['not_started', 'pass']) launch_command.launch() self.assertEqual(2, len(launch_command.test_results))
def testLaunchCommand_notRestartPassedTest(self, mock_collect_results, xcode_version): egtests = xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH) xcode_version.return_value = {'version': '10.2.1'} mock_collect_results.side_effect = [ {'failed': {'BUILD_INTERRUPTED': 'BUILD_INTERRUPTED: attempt # 0'}, 'passed': ['Class1/passedTest1', 'Class1/passedTest2']} ] launch_command = xcodebuild_runner.LaunchCommand(egtests, _DESTINATION, shards=1, retries=3, out_dir=self.tmpdir) self.fake_launch_attempt(launch_command, ['pass']) launch_command.launch() self.assertEqual(2, len(launch_command.test_results))
def testEgtests_xctestRunNode_without_filter(self): egtest_node = xcodebuild_runner.EgtestsApp( _EGTESTS_APP_PATH).xctestrun_node()['any_egtests_module'] self.assertNotIn('OnlyTestIdentifiers', egtest_node) self.assertNotIn('SkipTestIdentifiers', egtest_node)
def testEgtests_not_found_xctest(self, mock_listdir): mock_listdir.return_value = ['random_file'] egtest = xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH) with self.assertRaises(test_runner.XCTestPlugInNotFoundError): egtest._xctest_path()
def testEgtests_found_xctest(self): self.assertEqual('/PlugIns/any_egtests.xctest', xcodebuild_runner.EgtestsApp( _EGTESTS_APP_PATH)._xctest_path())
def testEgtests_not_found_plugins(self): egtests = xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH) self.mock(os.path, 'exists', lambda _: False) with self.assertRaises(test_runner.PlugInsNotFoundError): egtests._xctest_path()
def testEgtests_not_found_egtests_app(self): with self.assertRaises(test_runner.AppNotFoundError): xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH)
def testEgtests_found_xctest(self, mock_listdir): mock_listdir.return_value = ['any_egtests.xctest'] self.assertEqual( '/PlugIns/any_egtests.xctest', xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH)._xctest_path())
def testEgtests_not_found_plugins(self, mock_path_exists): mock_path_exists.return_value = True egtests = xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH) mock_path_exists.return_value = False with self.assertRaises(test_runner.PlugInsNotFoundError): egtests._xctest_path()
host_app = os.path.join(args.build_dir, 'ios_cwt_chromedriver_tests.app') destination = 'platform=iOS Simulator,OS=%s,name=%s' % (args.os, args.device) # Shutdown running simulators. This is needed since a running simulator may # be in a hung state. # TODO(crbug.com/673423): Change this logic to only shut down the simulator that # will be used for this run, when adding support for running multiple instances # of CWTChromeDriver. subprocess.check_call(['xcrun', 'simctl', 'shutdown', 'booted']) if not os.path.exists(args.out_dir): os.mkdir(args.out_dir) # Make sure each run produces a unique output directory, since reusing an # existing directory will cause CWTChromeDriver's dummy test case to get # skipped, meaning that CWTChromeDriver's http server won't get launched. output_directory = os.path.join(args.out_dir, 'run%d' % int(time.time())) egtests_app = xcodebuild_runner.EgtestsApp(egtests_app=test_app, test_args=['--port %s' % args.port], host_app_path=host_app, invert=True) launch_command = xcodebuild_runner.LaunchCommand(egtests_app, destination, shards=1, retries=1, out_dir=output_directory) launch_command.launch()
def testEgtests_not_found_egtests_app(self): self.mock(os.path, 'exists', lambda _: False) with self.assertRaises(test_runner.AppNotFoundError): xcodebuild_runner.EgtestsApp(_EGTESTS_APP_PATH)