[Python] self.driver.session_id provides incorrect Sauce Labs Session ID

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to get the session_id to post a message to Telegram after the test is done so that I can simply click the link and view the test run report.

    I am running a single test where I attempt to retrieve the real session_id.

    Here is my code:

    def test_sauce_link(self):
    main_page_1 = MainPage(self.driver)
    session_id = self.driver.session_id
    clean_session_id = re.sub(r"-", "", session_id)
    report_url = f"https://app.eu-central-1.saucelabs.com/tests/{clean_session_id}"
    TelegramReport.send_tg(f"{report_url}")


    The resulting ID from the run log: Message sent to Telegram:

    https://app.eu-central-1.saucelabs.com/tests/c0ae13588ae14629bb18b2e237e42ebe

    Meanwhile, the actual link from Sauce Labs is:

    https://app.eu-central-1.saucelabs.com/tests/50f2c409f87c471b973a24ed389562d2

    They are different, and the link from the test does not even work—it returns a 404 error when I try to open it.

    What am I doing wrong here? Please help.

    my Base class with caps:

    class BaseTest(unittest.TestCase):
    SAUCE_URL = "https://ondemand.eu-central-1.saucelabs.com:443/wd/hub"

    def setUp(self):
    """Set up Appium driver for each test case"""
    platform = os.getenv("TEST_PLATFORM", "android").lower()
    app_filename = "app-rc-v.1.9.4-807d51a3.apk"

    if not app_filename:
    raise ValueError("TEST_APP_FILENAME not provided!")

    if platform == "android":
    caps = UiAutomator2Options()
    caps.set_capability("platformName", "Android")
    caps.set_capability("appium:platformVersion", "15")
    caps.set_capability("appium:deviceName", "Google Pixel 9")
    caps.set_capability("appium:automationName", "UiAutomator2")
    caps.set_capability("appium:app", f"storage:filename={app_filename}")
    caps.set_capability("autoGrantPermissions", True)
    caps.set_capability("hideKeyboard", True)
    caps.set_capability("autoHideKeyboard", True)

    else:
    raise ValueError(f"Unsupported platform: {platform}")

    # Sauce Labs options
    sauce_options = {
    "username": os.getenv("SAUCE_USERNAME", "USERNAME"),
    "accessKey": os.getenv("SAUCE_ACCESS_KEY", "SAUCE_ACCESS_KEY"),
    "build": f"appium-build-{platform.upper()}",
    "name": self.__class__.__name__,
    "deviceOrientation": "PORTRAIT",
    "appiumVersion": "2.0.0"
    }
    caps.set_capability("sauce:eek:ptions", sauce_options)


    self.driver = webdriver.Remote(self.SAUCE_URL, options=caps)
    self.wait = WebDriverWait(self.driver, 10)

    def tearDown(self):
    """Close driver and update job status in Sauce Labs"""
    if hasattr(self, "driver") and self.driver:
    job_status = "passed" if sys.exc_info()[0] is None else "failed"
    try:
    self.driver.execute_script(f"sauce:job-result={job_status}")
    except Exception as e:
    print(f"Failed to update Sauce Labs job status: {e}")

    try:
    self.driver.quit()
    except Exception as e:
    print(f"Failed to quit the driver: {e}")

    Continue reading...

Compartilhe esta Página