Teamcity Python Runner

For this document, we provide example tests located in our TeamCity plugin GitHub Repository.

Jul 08, 2021 Python. The Python build runner automatically detects Python on agents and allows running Python scripts on Windows, Linux, and macOS. Since TeamCity 2020.2, this bundled runner replaces the obsolete Python Runner plugin. The new runner offers support for virtual environments, Docker, Kotlin DSL, and provides extra features like full test coverage. Oct 27, 2020 TeamCity Python Runner. This project is a TeamCity Python runner. I've authored this plugin in 2011 in spite of the day for running python scripts without problems of locating Python binaries on different platforms. However, that times have changed, and now I don't support this plugin.

TeamCity is a powerful continuous integration tool. In this guide we will use TeamCity along with our TeamCity Plugin for testing using the Selenium WebDriver and the Python programming language.

Set up TeamCity

0:14 Projects and Build Configurations Overview1:34 Creating your first project and build configuration2:28 Adding a build step to your configuration4:48 Run. Jul 08, 2021 Build Runner. Build runner is a part of TeamCity that allows integration with a specific build tool (Ant, MSBuild, Command Line, and so on). In a build configuration, a build runner defines how to run a build and report its results. Technically, build runners are implemented as plugins. Each runner has two parts. I've authored this plugin in 2011 in spite of the day for running python scripts without problems of locating Python binaries on different platforms. However, that times have changed, and now I don't support this plugin. TeamCity since the version 2020.2 has a new bundled Python Runner that supports also virtual env, test reporting, etc.

  1. Visit the TeamCity download page and select the appropriate file version based on your Operating System.

  2. After the TeamCity Application is installed, run the following command from the terminal/command prompt:

    runAll.sh start/runAll.bat start

  3. Navigate to http://localhost:8111 or http://localhost (Windows) and finish set up by creating a user.

Install our TeamCity plugin

  1. Download the CBT TeamCity plugin zip file.

  2. From the Administration page, click the Plugins List link.

  3. Click the Upload plugin zip button.

  4. Add the zip file of the CrossBrowserTesting Plugin. Click Save.

  5. Restart the TeamCity server.

  1. Download CBT TeamCity plugin zip file.

  2. Save the downloaded zip file into your <TeamCity Data Directory>/plugins directory.

  3. Restart the TeamCity server.

Run a test

Note:You will need to use your Username and Authkey to run your tests on CrossBrowserTesting. To get yours, sign up for a free trial or purchase a plan.
  1. Start a new project.

  2. Download and install the Python Runner plugin for TeamCity.

  3. Select Add build step from the Build Steps page.

  4. Select Python from the Runner type list and paste the following python script in the Python script source box:

    Python

    import unittest
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import requests, time
    import os
    class SeleniumCBT(unittest.TestCase):
    def setUp(self):
    self.username = os.environ.get('CBT_USERNAME')
    self.authkey = os.environ.get('CBT_APIKEY')
    self.api_session = requests.Session()
    self.api_session.auth = (self.username,self.authkey)
    self.test_result = None
    caps = {}
    caps['name'] = os.environ.get('CBT_BUILD_NAME')
    caps['os_api_name'] = os.environ.get('CBT_OPERATING_SYSTEM')
    caps['browser_api_name'] =os.environ.get('CBT_BROWSER')
    caps['screen_resolution'] = os.environ.get('CBT_RESOLUTION')
    caps['record_video'] = 'true'
    try:
    self.driver = webdriver.Remote(
    desired_capabilities=caps,
    command_executor='http://%s:%s@hub.crossbrowsertesting.com:80/wd/hub'%(self.username, self.authkey))
    except Exception as e:
    raise e
    def test_CBT(self):
    try:
    self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html')
    time.sleep(10)
    self.assertEqual(self.driver.title, 'Selenium Test Example Page')
    self.test_result = 'pass'
    except AssertionError as e:
    self.drvier.quit()
    # log the error message, and set the score
    self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id + '/snapshots/' + snapshot_hash,
    data={'description':'AssertionError: ' + str(e)})
    self.test_result = 'fail'
    raise
    self.driver.quit()
    # Here we make the api call to set the test's score
    # Pass if it passes, fail if an assertion fails, unset if the test didn't finish
    ifself.test_result isnot None:
    self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id,
    data={'action':'set_score', 'score':self.test_result})
    if __name__ '__main__':
    unittest.main()

  5. Select Add build feature from the Build Features page.

  6. Select CrossBrowserTesting from the Build feature list and configure.

  7. Click the Run button and view your results.

Environment variables

The CrossBrowserTesting TeamCity Plugin passes your build step information to your Selenium scripts as environment variables. The exact syntax will vary depending on your scripting language.

VariableDescription
CBT_USERNAMEThe username used on CrossBrowserTesting for Selenium Testing.
CBT_APIKEYThe API key used on CrossBrowserTesting for Selenium Testing.
CBT_BUILD_NAMEThe TeamCity Project's name.
CBT_BUILD_NUMBERThe TeamCity Project’s current build number.
CBT_OPERATING_SYSTEMThe apiname of the selected Operating System.
CBT_BROWSERThe apiname of the selected Browser.
CBT_BROWSERSAn array of JSON objects containing the 'operating_system', 'browser', 'resolution', and 'browserName' of each configuration specified.
CBT_RESOLUTIONThe name of the selected Screen Resolution.

Use a local connection

See all results for this question

If you would like to test behind your firewall or access non-public sites, you can use our local connection tool directly through our TeamCity plugin. Simply check Use Local Tunnel check box. (The CrossBrowserTesting Node.js Tunnel must be installed globally).

Teamcity Python Runner

Www.jetbrains.com › Help › TeamcityBuild Runner | TeamCity On-Premises

Conclusions

Cached

By following the steps outlined in this guide, you are now able to seamlessly integrate TeamCity and CrossBrowserTesting. If you have any questions or concerns, please feel free to reach out to our support team.

Teamcity Python Test Runner

See Also