         let stepRunner = makeStepRunner(steps: [step1, step2])
         stepRunner.state.afterChange.add { change in
             switch stateChangeCounter {
-            case 0:
-                XCTAssertTrue(change.newValue == .inProgress(index: 0), "state should be inProgress(0)")
-            case 1:
-                XCTAssertTrue(change.newValue == .inProgress(index: 1), "state should be inProgress(1)")
+            case 0...1:
+                assertState(change.newValue, StepRunnerState.inProgress(index: stateChangeCounter))
             case 2:
-                XCTAssertTrue(change.newValue == .success, "state should be success, was \(change.newValue)")
+                assertState(change.newValue, StepRunnerState.success)
                 XCTAssertEqual(stepRunner.model["step2"] as? String, "Hello world!") // Check that it is saved to the model
                 exp.fulfill()
             default:

        var stateChangeCounter = 0
        stepRunner.state.afterChange.add { change in
            switch stateChangeCounter {
            case 0:
                XCTAssertTrue(change.newValue == .inProgress(index: 0), "state should be in progress(0)")
            case 1:
                XCTAssertTrue(change.newValue == .inProgress(index: 1), "state should be in progress(1)")
            case 2:
                XCTAssertTrue(change.newValue == .inProgress(index: 2), "state should be in progress(2)")
            case 3:
                XCTAssertTrue(change.newValue == .success, "state should be success, was \(change.newValue)")

                // assert the model
                let model = stepRunner.model

        stepRunner.state.afterChange.add { change in
            switch stateChangeCounter {
            case 0:
                assertState(change.newValue, StepRunnerState.inProgress(index: 0))
            case 1:
                assertState(change.newValue, StepRunnerState.success)
                exp.fulfill()
            default:
                break
            }
            stateChangeCounter += 1
        }
        stepRunner.run()

        waitForExpectations()
    }

    // MARK: - WaitStep

    func testWaitStep() {
        var startDate: Date!

        let exp = expectation(description: #function)

        let step1 = OpenPageStep(
            path: path(for: "page1"),
            assertionName: "assertPage1Title")

        let step2 = WaitStep(waitTimeInSeconds: 0.5)

        let stepRunner = makeStepRunner(steps: [step1, step2])
        var stateChangeCounter = 0
        stepRunner.state.afterChange.add { change in
            print("afterChange called")
            switch stateChangeCounter {
            case 0:
                assertState(change.newValue, StepRunnerState.inProgress(index: 0))
            case 1:
                assertState(change.newValue, StepRunnerState.inProgress(index: 1))
                startDate = Date()
            case 2:
                assertState(change.newValue, StepRunnerState.success)
                let endDate = Date()
                XCTAssertTrue(endDate.timeIntervalSince(startDate) > 0.49)
                exp.fulfill()
            default:
                break
            }
            stateChangeCounter += 1
        }
        stepRunner.run()
        waitForExpectations()
    }

