Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Iterating Over Tables in a Qt GUI Test

DZone's Guide to

Iterating Over Tables in a Qt GUI Test

Take a look at this brief tutorial on how to iterate over a table in a GUI test using either QTableView or QTableWidget.

· Performance Zone ·
Free Resource

SignalFx is the only real-time cloud monitoring platform for infrastructure, microservices, and applications. The platform collects metrics and traces across every component in your cloud environment, replacing traditional point tools with a single integrated solution that works across the stack.

The Automated GUI Testing Tool Squish makes it possible to verify entire tables using a table verification point, but there are times when the requirements of a test case make it necessary to iterate over the items of the table in a GUI test.

For example, in cases where you want to compare the data in a table with that of a data file or when you need to verify a set of rows or columns for a certain condition.

The approach to iterate over the items of a table can differ somewhat depending upon whether the table in the AUT is based on a QTableView or a QTableWidget. This is because QTableWidget  comes with a built-in item model and has convenience methods for handling items, whereas the QTableView implements the interfaces defined by the QAbstractTableView class to allow it to display data provided by models derived from the QAbstractItemModel class.

Let's say we want to very that none of table cells are empty. In this case, we would iterate over the items using the columnCount  and rowCount  property of the QTableWidget:

Iterating Over QTableWidget Items:

    table = waitForObject(":Address Book - MyAddresses.adr.File_QTableWidget")
    columnCount = table.columnCount
    rowCount = table.rowCount
    for row in range(rowCount):
        for col in range(columnCount):
            item = table.item(row, col)
            itemText = item.text()
            test.log(str(itemText))
            test.verify(itemText != "")

A similar approach can also be used to iterate over the items of other Qt widgets like QTreeWidget, QListWidget.

QTableView on the other hand implements a table view that displays items from a model. Therefore we can use the Qt API to access the model directly. Iterating over QTableView items:

Iterating over QTableView items:

    table = waitForObject(":Item Views_QTableView")
    model = table.model()
    columnCount = model.columnCount()
    rowCount = model.rowCount()
    for row in range(model.rowCount()):
        for column in range(model.columnCount()):
            index = model.index(row, column)
            text = model.data(index).toString()
            test.verify(text != "")


SignalFx is built on a massively scalable streaming architecture that applies advanced predictive analytics for real-time problem detection. With its NoSample™ distributed tracing capabilities, SignalFx reliably monitors all transactions across microservices, accurately identifying all anomalies. And through data-science-powered directed troubleshooting SignalFx guides the operator to find the root cause of issues in seconds.

Topics:
squish ,qt ,qt+qml ,gui testing ,automated testing ,test script

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}