DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Organizing Knowledge With Knowledge Graphs: Industry Trends
  • Best Practices for Building the Data Pipelines
  • Discrepancies Between Test and FastAPI App Data
  • Mastering Database Unit Testing: A Full Guide and 5 Essential Tools

Trending

  • The Agile Paradox
  • Squid Game: The Clean Code Trials — A Java Developer's Survival Story
  • Docker Model Runner: A Game Changer in Local AI Development (C# Developer Perspective)
  • Scrum Smarter, Not Louder: AI Prompts Every Developer Should Steal
  1. DZone
  2. Data Engineering
  3. Databases
  4. Iterating Over Tables in a Qt GUI Test

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.

By 
Reginald Stadlbauer user avatar
Reginald Stadlbauer
·
Feb. 25, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.7K Views

Join the DZone community and get the full member experience.

Join For Free

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 != "")


Database Testing

Published at DZone with permission of Reginald Stadlbauer. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Organizing Knowledge With Knowledge Graphs: Industry Trends
  • Best Practices for Building the Data Pipelines
  • Discrepancies Between Test and FastAPI App Data
  • Mastering Database Unit Testing: A Full Guide and 5 Essential Tools

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: