For this document, we provide example tests located in our TeamCity plugin GitHub Repository.
Assuming we are using command line runner (as I do for running the Python scripts), TeamCity will check the exit code of the command executed and set the build status accordingly. The first step is then to make sure that any failure during the execution of. Apr 24, 2013 Experiments performing continuous integration testing in Python with TeamCity. At Bazaarvoice, we use TeamCity for continuous integration testing. This has proved immensely useful for most of our Java projects, however as I am developing a Python application, I wanted to see if I could get TeamCity to run testing on my program. This package integrates Python with the TeamCity Continuous Integration (CI) server. It allows sending 'service messages' from Python code. Additionally, it provides integration with the following testing frameworks and tools: See examples/simple.py for a full example. If you are used to running.
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. 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.
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
Visit the TeamCity download page and select the appropriate file version based on your Operating System.
After the TeamCity Application is installed, run the following command from the terminal/command prompt:
runAll.sh start/runAll.bat start
Navigate to http://localhost:8111 or http://localhost (Windows) and finish set up by creating a user.
Install our TeamCity plugin
Download the CBT TeamCity plugin zip file.
From the Administration page, click the Plugins List link.
Click the Upload plugin zip button.
Add the zip file of the CrossBrowserTesting Plugin. Click Save.
Restart the TeamCity server.
Download CBT TeamCity plugin zip file.
Save the downloaded zip file into your <TeamCity Data Directory>/plugins directory.
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. |
Start a new project.
Download and install the Python Runner plugin for TeamCity.
Select Add build step from the Build Steps page.
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()Select Add build feature from the Build Features page.
Select CrossBrowserTesting from the Build feature list and configure.
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.
Variable | Description |
---|---|
CBT_USERNAME | The username used on CrossBrowserTesting for Selenium Testing. |
CBT_APIKEY | The API key used on CrossBrowserTesting for Selenium Testing. |
CBT_BUILD_NAME | The TeamCity Project's name. |
CBT_BUILD_NUMBER | The TeamCity Project’s current build number. |
CBT_OPERATING_SYSTEM | The apiname of the selected Operating System. |
CBT_BROWSER | The apiname of the selected Browser. |
CBT_BROWSERS | An array of JSON objects containing the 'operating_system', 'browser', 'resolution', and 'browserName' of each configuration specified. |
CBT_RESOLUTION | The name of the selected Screen Resolution. |
Use a local connection
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).
Conclusions
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.
See Also
Latest versionReleased:
Use the TeamCity REST API from Python
Project description
PyTeamCity
Python interface to the RESTAPI ofTeamCity
Stackoverflow.com › Questions › 46319282how To Setup A Build Step In Teamcity To Run A Standalone ...
New API work-in-progress
Note that I am working on a new API currently calledpyteamcity.future(initially added in#37).
Goal here is to create a brand new API that is much more flexible and tohave nicer code that is easier to work with. The old code encouragesadding a zillion methods for different ways of filtering. The new codehas an API with a smaller number of methods that are more consistent andmore flexible in terms of filtering. It is modeled after the Django ORMAPI.
There’s no formal docs for this API yet, but you should be able tofigure out how to use it by looking at the unittests.
I am probably not going to merge PRs that add things to the old API,because I see the new API as the future. I of course am very interestedin PRs that add things to the new API!
Examples
Connect to server
or specify no parameters and it will read settings from environmentvariables:
- TEAMCITY_USER
- TEAMCITY_PASSWORD
- TEAMCITY_HOST
- TEAMCITY_PORT (Defaults to 80 if not set)
Getting data
You can also look atsample.pyortest_legacy.py
Acknowledgements
This is a heavily-modified fork ofhttps://github.com/yotamoron/teamcity-python-rest-client so many thanksare due to Yotam Oron
Changes
Teamcity Python Runners
0.1.1 (2016-11-09)
Project details
Release historyRelease notifications | RSS feed
0.1.1
0.1.0
0.0.1
Github.com › Leo-from-spb › Teamcity-pythonGitHub - Leo-from-spb/teamcity-python: TeamCity Python Runner 2.0
0.0.0
Download files
How To Setup A Build Step In Teamcity To Run A Standalone ...
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pyteamcity-0.1.1-py2-none-any.whl (12.5 kB) | File type Wheel | Python version 2.7 | Upload date | Hashes |
Filename, size pyteamcity-0.1.1.tar.gz (35.0 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for pyteamcity-0.1.1-py2-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 43a5c91e62590259321dec37cfd0dc297905e92d9d2026030a016acf3d0e8cf7 |
MD5 | df1d124c1bbddb3af017cbae5ae657bd |
BLAKE2-256 | f3ccc4e598e5c1a9250ec7088c239732bb4ac195f0439336f6b55389286f179e |
Hashes for pyteamcity-0.1.1.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | 3d9f97fff7f397f2c2484acd5acda7bb48681ec1ff9ed80443a7c374613b0fe1 |
MD5 | 7aa97fd86a151d3243ed1e31f79852cd |
BLAKE2-256 | 075b18104c49d8bb77a8f4ddd80822b223edbbd8e49ffcf539018b686b6b6e4f |