diff --git a/launchable/test_runners/cypress.py b/launchable/test_runners/cypress.py index 53e90c955..1283dd2a0 100644 --- a/launchable/test_runners/cypress.py +++ b/launchable/test_runners/cypress.py @@ -15,8 +15,9 @@ def record_tests(client, reports): def parse_func(p: str) -> ET.Element: tree = ET.parse(p) for suites in tree.iter("testsuites"): - filepath = suites.find( - './/testsuite[@name="Root Suite"]').get("file") + if len(suites)==0: + continue + filepath = suites.find('./testsuite[@name="Root Suite"]').get("file") for suite in suites: suite.attrib.update({"filepath": filepath}) return tree diff --git a/tests/data/cypress/empty.json b/tests/data/cypress/empty.json new file mode 100644 index 000000000..b74057ed5 --- /dev/null +++ b/tests/data/cypress/empty.json @@ -0,0 +1 @@ +{"events": []} diff --git a/tests/data/cypress/empty.xml b/tests/data/cypress/empty.xml new file mode 100644 index 000000000..4e9422629 --- /dev/null +++ b/tests/data/cypress/empty.xml @@ -0,0 +1,3 @@ + + + diff --git a/tests/test_runners/test_cypress.py b/tests/test_runners/test_cypress.py index 2a991cf3c..8eedbadba 100644 --- a/tests/test_runners/test_cypress.py +++ b/tests/test_runners/test_cypress.py @@ -36,3 +36,17 @@ def test_subset_cypress(self, mock_post): expected = self.load_json_from_file( self.test_files_dir.joinpath('subset_result.json')) self.assert_json_orderless_equal(expected, payload) + + + @mock.patch('requests.request') + def test_empty_xml(self, mock_post): + # parse empty test report XML + result = self.cli('record', 'tests', '--session', self.session, + 'cypress', str(self.test_files_dir) + "/empty.xml") + self.assertEqual(result.exit_code, 0) + + payload = self.gzipped_json_payload(mock_post) + expected = self.load_json_from_file( + self.test_files_dir.joinpath('empty.json')) + + self.assert_json_orderless_equal(expected, payload)