Stop 06 · Programming Fundamentals for AutomationTopics · 4/10

Working With Arrays & Collections

Part of the QA Testing Roadmap

In short

Testers rarely test one input. You test fifty usernames, ten browsers, twenty product ids. Collections are how your script carries all of them around.

Storing and manipulating lists of data — essential for data-driven testing, where the same test logic runs repeatedly against different sets of input data.

The purple blob holds open a round steel spice box filled with small bowls of colourful spices.

Think of it like this

Amma's masala dabba

The steel dabba has bowls in a fixed circle: you know the third one is haldi. That's a list, found by position. Now imagine each bowl has a sticker: 'jeera', 'mirchi'. That's a dictionary, found by name. Same box, two ways to find things.

Watch it happen

List vs dictionary

List / ArrayList

  • Ordered items, found by index
  • Index starts at 0, not 1
  • Great for many test inputs

Dict / HashMap

  • Key and value pairs
  • Look up by name, not position
  • Great for one record's fields

Most test data is both: a list of dictionaries, where each dictionary is one test case with named fields.

The big ideas

What you need to know

Index from zero

In a list of three, the items are at 0, 1 and 2. Asking for index 3 is an error.

Keys are labels

user['email'] reads the email field. Clearer than remembering it was item 2.

Rows of cases

A list of dictionaries looks like a spreadsheet: each dictionary is a row, each key a column.

Check the length

len(results) tells you how many items came back. Comparing counts is a quick, useful check.

See it in code

Walk through the code

python
1login_cases = [2    {"email": "asha@test.com", "password": "Pass@123", "expect": "success"},3    {"email": "asha@test.com", "password": "wrong", "expect": "error"},4    {"email": "", "password": "Pass@123", "expect": "error"},5]6 7for case in login_cases:8    print("Try", case["email"] or "(blank)", "-> expect", case["expect"])9 10print("Total cases:", len(login_cases))11print("First case email:", login_cases[0]["email"])

1/3Each dictionary is one test case with named fields. The list holds all of them.

A list of dictionaries: the standard shape for data-driven tests in any language.

Save yourself the pain

Common mistakes

Oops

Reading items by position like case[2] and forgetting what 2 meant.

Do this instead

Use dictionaries with clear keys, so case['expect'] explains itself.

Oops

Looping from 1 to len(list) and silently skipping the first item.

Do this instead

Use for item in items, or start your index at 0.

Your mission

Store and query test cases

~25 min

Quick check

browsers = ['chrome', 'firefox', 'safari']. What does browsers[1] return?

Go deeper

  1. 1Practice iterating over an array/list of test data and running the same check on each item.
  2. 2Learn basic collection operations: filtering, mapping, and sorting.
  3. 3Build a small data-driven test script running the same assertion against multiple inputs.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge