Appium
Example test with debugging try/except flow: https://gist.github.com/maxdobeck/043815b9f93d942cc87a2983d3ffb74d
This print line would use the information sent back to the driver object from the Appium server.
print(f"test {driver.capabilities['testobject_test_report_url']} {driver.capabilities['deviceName'], desired_caps['appium:platformVersion']}started in {t_end - t_start:0.2f} seconds")
test https://app.eu-central-1.saucelabs.com/tests/bffcc8fa3c604732a20d01a128286cf0 ('some-string', 'some-int')started in 20.45 seconds
It would print out the test hyperlink, the deviceName, platformVersion (the OS version) and the time to start.
The available information sent back by the Appium Server should let you gather all the details you need to structure your logs or STDOUT output. Here's some example output found in the print(driver.capabilities) method.
{'webStorageEnabled': False,
'locationContextEnabled': False,
'browserName': 'safari',
'platform': 'MAC',
'javascriptEnabled': True,
'databaseEnabled': False,
'takesScreenshot': True,
'networkConnectionEnabled': False,
'platformName': 'iOS',
'sauce:options': {
'name': 'device allocation duration',
'realDevice': True,
'build': 'from my laptop',
'commandTimeouts': '60000'
},
'platformVersion': '13.7',
'webDriverAgentUrl': 'http://127.0.0.1:5700',
'orientation': 'PORTRAIT',
'deviceName': '00008030-',
'automationName': 'XCUITest',
'testobject_user_id': 'username',
'deviceContextId': '-ff83-409c-bc3e-',
'testobject_test_report_api_url': 'https://api.eu-central-1.saucelabs.com/v1/rdc/jobs/bffcc8fa3c604732a20d01a128286cf0',
'jobUuid': 'bffcc8fa3c604732a20d01a128286cf0',
'testobject_test_report_url': 'https://app.eu-central-1.saucelabs.com/tests/bffcc8fa3c604732a20d01a128286cf0',
'appiumData': { 'automationName': 'XCUITest', 'appiumVersion': '1.22.2'},
'testobject_device_name': 'iPhone SE 2020',
'testobject_device': 'iPhone_SE_2020_13_real',
'testobject_device_session_id': '5ec02ba2-e492-4f94-a808-42ba412488c7',
'usedCachedDevice': False}
Some useful bits are the testobject_device, appiumVersion, testobject_test_report_url, jobUuid. These are all exceptional bits of information to capture for debugging. Or for long term logging & reporting.
Selenium
The same is true for selenium but you have to print driver.session_id for the Job ID. You can re-construct the URL by adding the appropriate datacenter like so print(https://app.saucelabs.com/{driver.session_id}).
Selenium: Increase Logging Level
Requires Selenium 4.0+ https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/
Anatomy of the Session Link
https://app.eu-central-1.saucelabs.com/tests/bffcc8fa3c604732a20d01a128286cf0
bffcc8fa3c604732a20d01a128286cf0 is also the Session ID inside Sauce Labs. So even if you only have the session ID you can find the job link or provide that to the Support team.
You can retrieve this with driver.capabilities['jobUuid']. Or you can print the full hyperlink with testobject_test_report_url.