Load Testing & Performance Benchmarking (JMeter & k6) · บทเรียน

การกำหนดพารามิเตอร์ด้วยข้อมูล CSV

ใช้การตั้งค่าชุดข้อมูล CSV เพื่อใส่ข้อมูลอินพุตแบบไดนามิกลงในสคริปต์ทดสอบ

บทเรียน 1 จาก 411 ขั้นตอน

การกำหนดพารามิเตอร์ด้วยข้อมูล CSV เป็นบทเรียน Load Testing & Performance Benchmarking (JMeter & k6) ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Load Testing & Performance Benchmarking (JMeter & k6) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Load Testing & Performance Benchmarking (JMeter & k6) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Dynamic Data with CSV

When performance testing, we often need to simulate many users doing similar, but not identical, actions. For example, logging in with different credentials or searching for different items.

This is where parameterization comes in! Instead of hardcoding values, we use variables to inject dynamic data into our tests. This lesson focuses on using CSV files for this purpose in JMeter.

What is Parameterization?

Parameterization is the process of replacing hardcoded values in your test script with variables. These variables then get their values from an external source, like a data file.

  • It makes your tests more realistic by simulating diverse user inputs.
  • It helps prevent caching issues on the server side, as each request can be unique.
  • It allows you to test different scenarios without modifying the test script itself.

Meet CSV Data Set Config

In JMeter, the primary element for parameterization using external files is the CSV Data Set Config. This element reads data from a plain text file, typically with comma-separated values (CSV).

It works by reading a new line of data for each iteration of your test or for each virtual user, making the requests unique.

Preparing Your CSV File

Your CSV file is just a simple text file. Each line represents a set of data for one iteration or one user. Values within a line are separated by a delimiter, usually a comma (`,`).

  • Ensure the file is accessible to JMeter (e.g., in the same directory as your .jmx script).
  • You don't need a header row in the CSV file itself; you'll define variable names in JMeter.

CSV File Example

Here's what a simple CSV file might look like, containing usernames and passwords:

user1,pass1
user2,pass2
user3,pass3

Each line provides a unique pair of username and password that can be used by a different virtual user or in different test iterations.

Adding CSV Data Set Config

To add this element in JMeter:

  1. Right-click on your Test Plan or Thread Group.
  2. Go to Add > Config Element > CSV Data Set Config.

Placing it under the Test Plan makes it available globally. Placing it under a Thread Group limits its scope to that specific group.

Configuring Key Fields

The CSV Data Set Config has several important fields to configure:

  • Filename: Path to your CSV file.
  • Variable Names: Comma-separated list of names for variables (e.g., username,password).
  • Delimiter: Character separating values (default is comma).
  • Recycle on EOF?: If True, JMeter restarts from the beginning of the file when it reaches the end.
  • Stop Thread on EOF?: If True, the thread stops when it runs out of data.
  • Sharing Mode: How data is shared among threads (e.g., All threads, Current thread group).

Using Variables in Requests

Once you've defined your variable names in the CSV Data Set Config (e.g., username and password), you can use them in your JMeter Samplers.

The syntax for referencing a variable is ${variableName}.

For instance, in an HTTP Request, you might use ${username} in the username field and ${password} in the password field.

Example: Login Request

Let's say you're testing a login page that accepts user and pass as parameters. With a CSV file like user1,pass1, you'd configure your HTTP Request as follows:

Method: POST
Path: /login
Parameters:
  user: ${username}
  pass: ${password}

Each time a virtual user makes this request, JMeter will pull the next available username and password from your CSV file.

CSV Configuration Check

You've successfully set up a CSV Data Set Config. Which of the following are crucial settings you must define for it to work correctly?

Recap: Parameterizing with CSV

Great job! You've learned how to parameterize your JMeter tests using the CSV Data Set Config.

  • Parameterization makes tests more realistic.
  • The CSV Data Set Config reads data from a CSV file.
  • You define variable names in the Config element to map to your CSV columns.
  • Use the ${variableName} syntax to reference data in your samplers.
  • Key settings include Filename, Variable Names, Delimiter, Recycle on EOF, Stop Thread on EOF, and Sharing Mode.

Next, we'll explore handling dynamic values directly from server responses!

เริ่มต้นได้ฟรี

เรียนรู้ Load Testing & Performance Benchmarking (JMeter & k6) ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การกำหนดพารามิเตอร์ด้วยข้อมูล CSV” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การกำหนดพารามิเตอร์ด้วยข้อมูล CSV” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Load Testing & Performance Benchmarking (JMeter & k6) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Load Testing & Performance Benchmarking (JMeter & k6) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การกำหนดพารามิเตอร์ด้วยข้อมูล CSV”

ใช้การตั้งค่าชุดข้อมูล CSV เพื่อใส่ข้อมูลอินพุตแบบไดนามิกลงในสคริปต์ทดสอบ คุณปฏิบัติ Load Testing & Performance Benchmarking (JMeter & k6) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Load Testing & Performance Benchmarking (JMeter & k6) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Load Testing & Performance Benchmarking (JMeter & k6) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “การกำหนดพารามิเตอร์ด้วยข้อมูล CSV” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Load Testing & Performance Benchmarking (JMeter & k6) นี้ได้ไหม

ได้ บทเรียน Load Testing & Performance Benchmarking (JMeter & k6) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การกำหนดพารามิเตอร์ด้วยข้อมูล CSV
  2. การจัดการค่าแบบไดนามิก (การเชื่อมโยงค่า)
  3. ฟังก์ชันและตัวแปรของ JMeter
  4. การทดสอบฐานข้อมูลด้วย JDBC
← กลับไปที่ Load Testing & Performance Benchmarking (JMeter & k6)