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

ตัวควบคุมตรรกะและลูป

ใช้ตัวควบคุมตรรกะเพื่อจัดการลำดับการทดสอบ และใช้ตัวควบคุมลูปสำหรับการดำเนินการซ้ำ

ตัวควบคุมตรรกะและลูป เป็นบทเรียน 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 บทเรียน

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

Intro to Test Flow Control

Welcome! In this lesson, we'll dive into Logic Controllers and Loop Controllers in JMeter. These powerful elements help you build more realistic and dynamic performance test plans.

They allow you to control the order and frequency of requests, simulating complex user behaviors beyond simple linear execution.

Understanding Logic Controllers

Logic Controllers in JMeter dictate the order in which user requests are processed. They add intelligence to your test plan, enabling conditional execution or specific sequencing.

  • They act like "if-else" statements or "switch" cases in programming.
  • Useful for scenarios where actions depend on previous outcomes or data.

Think of them as the brain of your test script, guiding the flow.

Introducing the If Controller

The If Controller is a fundamental logic controller. It executes its child elements (requests, other controllers) only if a specified condition evaluates to true.

  • Purpose: Simulate conditional actions, like a user clicking a "login" button only if they are not already logged in.
  • Condition: You define a condition using JMeter functions or variables, often a JavaScript or Groovy expression.

Crafting If Controller Logic

The condition for an If Controller is a powerful expression. It's often a boolean check on a variable or a response value.

For example, if you want to execute a request only when a variable userStatus is "new", your condition might look like this:

${__groovy(vars.get("userStatus").equals("new"),)}

This tells JMeter to run the child elements only if userStatus is "new".

Understanding Loop Controllers

Loop Controllers are designed to repeat a set of actions a specific number of times, or indefinitely. They're essential for simulating repetitive user behavior.

  • Purpose: Simulate actions like browsing multiple pages, adding several items to a cart, or performing repeated searches.
  • They enclose sampler requests or other controllers that need to be executed multiple times.

Configuring the Loop Controller

When you add a Loop Controller to your test plan, you specify how many times its contained elements should run. You have two main options:

  • Loop Count: Enter a positive integer to repeat actions a fixed number of times (e.g., 3 for adding 3 items).
  • Forever: Check this box to make the loop run continuously. This is often used with a Thread Group's duration or scheduler.

Practical Loop Controller Use

Imagine a user adding multiple items to a shopping cart. Instead of duplicating "Add to Cart" requests, you can use a Loop Controller.

You'd place an "Add to Cart" HTTP Request sampler inside the Loop Controller, setting the loop count to, say, 5. This efficiently simulates adding 5 items.

Each iteration of the loop can use different data (e.g., from a CSV Data Set Config), making it very dynamic.

Nesting Controllers for Complexity

JMeter allows you to nest controllers, creating sophisticated test flows. You can place a Loop Controller inside an If Controller, or vice-versa.

  • Loop inside If: "If user is premium, then loop 5 times through a special offer."
  • If inside Loop: "Loop 10 times through browsing items, and if an item is a 'featured product', click on it."

This nesting capability makes your test plans incredibly flexible and realistic.

Tips for Effective Controller Use

To get the most out of Logic and Loop Controllers, consider these best practices:

  • Keep conditions simple: Overly complex If Controller conditions can be hard to debug.
  • Use variables: Store dynamic values in variables and reference them in conditions or loop counts.
  • Don't over-nest: Too many nested controllers can make your test plan difficult to read and maintain.
  • Add comments: Explain the purpose of complex controller structures.

Test Your Controller Knowledge

Time for a quick check on what you've learned about JMeter controllers!

Controllers: A Powerful Summary

Great job! In this lesson, you learned about two essential JMeter controllers:

  • Logic Controllers: Like the If Controller, they enable conditional execution and manage the flow of your test plan.
  • Loop Controllers: They allow you to repeat actions a specified number of times, simulating repetitive user behaviors efficiently.

Mastering these controllers is key to building advanced, realistic, and robust performance tests in JMeter. Next, we'll explore Assertions!

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

บทเรียน “ตัวควบคุมตรรกะและลูป” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “ตัวควบคุมตรรกะและลูป”

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

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

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

บทเรียน “ตัวควบคุมตรรกะและลูป” ใช้เวลานานแค่ไหน

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

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

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

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

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