Squish/Finding List Items that End in a Given String: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
= Finding list items that ends in a given string =
= Finding list items that ends in a given string =


As Squish uses the full item text for identifying items in a list view, this could cause problems when<br />the beginning of the item text is different based on e.g. which machine you are running the test case.
As Squish uses the full item text for identifying items in a list view, this could cause problems when
the beginning of the item text is different based on e.g. which machine you are running the test case.


One solution to this could be to look for items ending with a given string, to avoid including<br />the changing string prefix. This can be done with the utility function below, which clicks an item<br />that ends in a given string in a given column:
One solution to this could be to look for items ending with a given string, to avoid including
the changing string prefix. This can be done with the utility function below, which clicks an item
that ends in a given string in a given column:


<code>def clickListItem(obj, endValue, column):<br /> model = waitForObject(obj).model()<br /> rows = model.rowCount()
<code>def clickListItem(obj, endValue, column):
model = waitForObject(obj).model()
rows = model.rowCount()


for i in range(rows):<br /> itemString=str(model.data(model.index(i, column), Qt.DisplayRole).toString())
for i in range(rows):
itemString=str(model.data(model.index(i, column), Qt.DisplayRole).toString())


if itemString.endswith(endValue):<br /> waitForObjectItem(obj, itemString)<br /> clickItem(obj, itemString, 0, 0, 0, Qt.LeftButton)<br /> return
if itemString.endswith(endValue):
waitForObjectItem(obj, itemString)
clickItem(obj, itemString, 0, 0, 0, Qt.LeftButton)
return


test.fatal("Could not find item with end value: " + endValue)</code>
test.fatal("Could not find item with end value: " + endValue)</code>


Selecting an item that ends in the string "value1" in a specific list view is then done by doing:<br /><code>clickListItem(":MyQListView", "value1", 0)<code>
Selecting an item that ends in the string "value1" in a specific list view is then done by doing:
<code>clickListItem(":MyQListView", "value1", 0)<code>

Revision as of 11:19, 25 February 2015

this page in:

Finding list items that ends in a given string

As Squish uses the full item text for identifying items in a list view, this could cause problems when the beginning of the item text is different based on e.g. which machine you are running the test case.

One solution to this could be to look for items ending with a given string, to avoid including the changing string prefix. This can be done with the utility function below, which clicks an item that ends in a given string in a given column:

def clickListItem(obj, endValue, column):
 model = waitForObject(obj).model()
 rows = model.rowCount()

for i in range(rows):
 itemString=str(model.data(model.index(i, column), Qt.DisplayRole).toString())

if itemString.endswith(endValue):
 waitForObjectItem(obj, itemString)
 clickItem(obj, itemString, 0, 0, 0, Qt.LeftButton)
 return

test.fatal("Could not find item with end value: " + endValue)

Selecting an item that ends in the string "value1" in a specific list view is then done by doing: clickListItem(":MyQListView", "value1", 0)