Skip to main content

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

As long as you are doing testing work , you will inevitably come into contact with the database.

1 Introduction

As long as you are doing testing work, you will inevitably come into contact with databases. The main application scenarios of databases at work include but are not limited to the following:

  • In the functional test , the data display function is involved, and the database needs to be checked to verify the accuracy and completeness of the data; for example, the product search function

  • In automated testing or performance testing, some interfaces need to be linked to database operations in order to run smoothly ; for example, obtaining the SMS verification code in the registration interface

  • Assertion processing in automated testing, in addition to assertions of response results, also includes assertions to the database

  • In automated testing or performance testing, some scenarios require batch data creation, which may require the use of a database to create data.

  • During testing, if a bug is found and needs to be located, the database may need to be queried for location.

When we use Jmeter or postman tools for interface testing, or use Python to perform automated testing, such as the product search function, we need to check the database to verify the correctness and integrity of the search product results to achieve assertions. How does the database operate here?

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

2. How does Jmeter operate the database?

Step 1: Establish a database connection through JDBC Connection Configuration

Right-click under the Jmeter thread group->Configuration Component->Select JDBC Connection Configuration and make the following configuration

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Note: The jmeter tool does not have a driver to operate the database. You need to add the driver jar package yourself, download one, and put it in the lib directory of jmeter, then click on the test plan and add the jar package path. as follows:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Step 2: Write sql statements through JDBC Request to operate the database and obtain data

Right-click under the Jmeter thread group -> Sampler -> select JDBC Request and make the following configuration:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Click Run and you can see the search results normally:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

3. How does postman operate the database?

Postman itself does not have a database connection function. You need to use xmysql in node.js to generate Rest API, and then use postman to request the API and implement operations on the database.

Step 1: Environment preparation, install xmysql

1. Installation of node.js: Visit https://nodejs.org/en/download to download and install. After the installation is successful, enter node --verison in the cmd command line window. If the version information appears, the installation is successful.

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

2. Installation of xmysql: Enter npm install -g xmysql in the command line window to install. After the installation is complete, enter xmysql and see the instructions, which means the installation is successful.

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Step 2: Connect to the database

Enter in the command line window: xmysql -h hostname -u username -p password -d library name. as follows:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Step 3: Postman operates the database

Postman performs addition, deletion, modification and query operations on the Rest API generated by xmysql. For details, see the official documentation: https://github.com/o1lab/xmysql?utm_source=testingpai.com#xmysql--one-command-to-generate-rest-apis -for-any-mysql-database

Examples are as follows:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

The postman query data operation is as follows:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

4. How does Python operate the database?

Step 1: Environment preparation, install pymysql

To operate the mysql database in python, you need to use the third-party library example pymysql to achieve it. So you need to install pymysql first:

Enter pip install pymysql through the cmd command line window. After installation, check whether the installation is successful through pip show pymysql. Displaying pymysql library information is successful.

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Step 2: In the python file, write code to operate the database
 
import pymysql # import package
# Step 1: Connect to the database conn = pymysql.connect( user="shopxo", # username password="lemfix", # password host="spx.lemfix.com", # domain name or ip of the database database="shopxo", # name of the library port= 3306, # port charset="utf8mb4", # encoding)

# Step 2: Create the cursor cur = conn.cursor()

# Step 3: Execute sql statement - query # cur.execute(sql statement), return value is the number of rows affected by executing the sql row_count = cur.execute("select id, title, price from sxo_goods where is_shelves = 1 and title like '%dress%' and is_delete_time = 0 order by access_count desc,sales_count desc;")print(row_count)
# Step 4: Get the query data search_data = cur.fetchall()print(search_data)
# Step 5: Close the database connection to free up resources cur.close() conn.close()
Run the above code and get the database query results as follows:

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

5. Summary

The above operations are just demonstrations of database connection and query operations. A complete project needs to be combined with business scenarios to design scripts or write code accordingly. On this basis, you can expand based on your own project conditions. There is no end to learning, and practice goes a long way.

Finally, I would like to thank everyone who read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?

How do the three mainstream technologies of Jmeter, Postman and Python operate the database?