Last active
September 17, 2025 16:03
-
-
Save clarmso/fff4f0dab013cd6708b2e247892de1e6 to your computer and use it in GitHub Desktop.
Command to re-run failed tests locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import re | |
| import argparse | |
| import requests | |
| import os | |
| # Default values of the arguments: | |
| # --testPlan: FullFunctionalTestPlan | |
| # --parallel: 2 | |
| # Mandatory: | |
| # --url: URL of the test report generated by xchtmlreport | |
| parser = argparse.ArgumentParser(description="Generate re-run xcodebuild command for failed tests") | |
| parser.add_argument("--testPlan", help="Test plan (Smoketest or FullFunctionalTests)", default="FullFunctionalTestPlan") | |
| parser.add_argument("--parallel", help="Number of parallel simulators", default="2") | |
| parser.add_argument("--url", required=True, help="URL of the test report") | |
| args = parser.parse_args() | |
| # URL must be defined | |
| # Download the file first | |
| response = requests.get(args.url) | |
| soup = BeautifulSoup(response.content, "html.parser") | |
| # Get values for the destination | |
| device_name = soup.find("h3", class_="device-name").get_text(strip=True) | |
| device_os = soup.find("li", class_="device-os").get_text(strip=True) | |
| device_os = re.sub(r"iOS ", "", device_os) | |
| # Construct the first part of the command | |
| test_plan = args.testPlan | |
| num_parallel = args.parallel | |
| cmd = "xcodebuild test-without-building -target Client -scheme Fennec -destination 'platform=iOS Simulator,name={0},OS={1}' -testPlan {2} -parallel-testing-enabled YES -parallel-testing-worker-count {3}".format(device_name, device_os, test_plan, num_parallel) | |
| # Construct individual "-only-testing" argument | |
| failed_groups = soup.find_all("div", class_="test-summary-group failed") | |
| print("# Failed Tests") | |
| for group in failed_groups: | |
| group_name = group.find("p").get_text(strip=True) | |
| group_name = re.sub(r"\s*\(\d+(\.\d+)?s\)", "", group_name) | |
| failed_divs = group.find_all("div", class_="test-summary failed") | |
| for div in failed_divs: | |
| test_name = div.find("p").get_text(strip=True) | |
| test_name = re.sub(r"\s*\(.*", "", test_name) | |
| cmd += " -only-testing:XCUITests/{0}/{1}".format(group_name, test_name) | |
| print("{0}/{1}".format(group_name, test_name)) | |
| print("\n# xcodebuild command for re-run") | |
| print(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment