Playwright + Java · Lesson 4 of 38

0/38 done

Module 4: Arrays

4. Java Arrays & Array Utility Operations

13 minlesson

Your task

Implement verifyMenuItems:

  1. Accept String[] actualItems and String[] expectedItems.
  2. Return true if Arrays.equals(actualItems, expectedItems) is true, otherwise false.

Write it in the editor, then press Check answer (Ctrl + Enter).

Java Arrays in Test Automation

java
import java.util.Arrays;

// Single-dimensional array:
String[] expectedTabs = {"Home", "Courses", "Practice", "Profile"};

// Iteration:
for (int i = 0; i < expectedTabs.length; i++) {
    System.out.println("Checking tab: " + expectedTabs[i]);
}

// Sorting and searching:
int[] responseTimes = {450, 120, 890, 230};
Arrays.sort(responseTimes); // [120, 230, 450, 890]
int minTime = responseTimes[0];

Key Takeaways & Walkthrough Summary

In automated testing, arrays represent fixed lists of test inputs, user roles, and expected menu items. In this lesson, we cover single and multi-dimensional arrays, traversal, and the java.util.Arrays utility class. Let's master arrays!

Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why does actualItems.equals(expectedItems) return false even with identical contents?

Arrays in Java inherit Object.equals, which compares references. Use Arrays.equals(arr1, arr2) to compare element contents.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Java
Skip