by admin | May 21, 2020 | API Testing, Fixed |
Using Python Jenkins API endpoints, you can automate your Jenkins servers. You shall install plugins, set the next build number and can do a lot more using Jenkins Python REST endpoints. In this blog article, you will learn step by step methods of installing and automating Jenkins server using Python code.
Python Jenkins API Package Installation
pip install python-jenkins
Connecting Jenkins Server
Connecting your Jenkins server is straight forward. Import ‘jenkins’ module and connect the server using URL, username, and password as shown below.
import jenkins
try:
server = jenkins.Jenkins('http://localhost:8080', username='admin', password='admin')
except Exception as e:
print(e)
Updating Build Number
next_bn = server.get_job_info('job_name')['nextBuildNumber']
server.set_next_build_number('job_name', next_bn + 50)
Get Test Results
Let’s say you wish to display a specific build’s test results, Using ‘get_build_test_report’ method, you can retrieve the test results for a Jenkins build. Not only that even If you intent to create an automation testing metrics utility, this method would be an ideal option to retrieve and display specific build’s test results.
Plugin Details
If you have a common test automation framework which is used widely in your organization, then you can get all the installed plugins details, identify the missing plugins which are recommended for your automation testing framework, and suggest them in Jenkins console window.
Enabling & Disabling Jobs
You shall enable & disable Jenkins jobs based on your automated script outcome. For instance: If a job is to be scheduled within a stipulated time frame with some valid condition and if the same needn’t be executed, then you use enabling & disabling Jenkins job options using Jenkins API endpoints.
Conclusion
As a QA company, we use Jenkins, TeamCity, and BuildBot for continuous integration of various automation testing projects. However, operating Jenkins server using Python offers greater flexibility to extract and control jobs via coding. On a parting noted we thank you very much for reading this blog article and hereby coclude with a hope that you have enjoyed this blog article. See you soon with more insightful articles !!!
by admin | Sep 7, 2019 | API Testing, Fixed, Blog |
Writing automated API tests can be done using any Python HTTP client library & assertions packages. If we get all the API testing capabilities in one framework, it would minimize script creation & maintenance time. In this article, you will learn how to automate API testing using Apiritif framework.
Apiritif is a Python based API testing framework which eases automated API tests creation and maintenance. It is developed by Blazemeter and has all necessary utilities and assertions methods for API testing.
HTTP Requests
from apiritif import http
response = http.get("http://example.com")
response.assert_ok() # will raise AssertionError if request wasn't successful
Assertions
response = http.get("http://example.com/")
# assert that request succeeded (status code is 2xx or 3xx)
response.assert_ok()
# assert that request has failed
response.assert_failed()
# status code based assertions
response.assert_2xx()
response.assert_3xx()
response.assert_4xx()
response.assert_5xx()
response.assert_status_code(code)
response.assert_not_status_code(code)
# content-based assertions
# assert that response body contains a string
response.assert_in_body(member)
# assert that response body doesn't contain a string
response.assert_not_in_body(member)
# search (or match) response body with a regex
response.assert_regex_in_body(regex, match=False)
response.assert_regex_not_in_body(regex, match=False)
# assert that response has header
response.assert_has_header(header)
# assert that response has header with given value
response.assert_header_value(header, value)
# assert that response's headers contains a string
response.assert_in_headers(member)
response.assert_not_in_headers(member)
# search (or match) response body with a regex
response.assert_regex_in_headers(member)
response.assert_regex_not_in_headers(member)
# assert that response body matches JSONPath query
response.assert_jsonpath(jsonpath_query, expected_value=None)
response.assert_not_jsonpath(jsonpath_query)
# assert that response body matches XPath query
response.assert_xpath(xpath_query, parser_type='html', validate=False)
response.assert_not_xpath(xpath_query, parser_type='html', validate=False)
by admin | Jun 17, 2019 | API Testing, Blog |