メインコンテンツまでスキップ
バージョン:23.5

Validating Data Tables in Eggplant Functional

Data tables are a common component of many desktop, web, and even some mobile applications. All industries use software that leverages data tables in some way, such as for displaying hospital patient lists, financial data, or open job opportunities.

Common use cases surrounding data tables include validating that the content displayed by a data table in an application UI mirrors the content of the underlying database, or validating that a record submitted in a form persists and is displayed later in the application's data table. Data table validation with the Eggplant Functional test automation tool is powerful and leverages the advanced scripting and database access capabilities of SenseTalk.

Data Table Validation in Action

The following video shows examples of Eggplant Functional validating different aspects of distinct data tables.

Tech Talk

These SenseTalk commands, functions, variables, and syntax are used in data table validation, and are referenced in the above video.

readText() Function
readTable() Function
imageRectangle() Function
foundImageInfo() Function
remoteClipboard() Function
Local Variables
* Repeat Loops
Arithmetic Commands
Property Lists
Conditional Statements
Points and Rectangles
Messages
Chunk Syntax and Working with Chunks
* Working with Databases

Scripts for Data Table Validation

The following scripts can be used for validating tables.

Compare records script: This script retrieves all data rows from a database and from a displayed data table, and compares their contents.

//The script leverages functions stored in the RetrieveRecords script

put RetrieveRecords.fromUI into ActualRecords
log "The actual records are:"
LogAllRecords ActualRecords

log "-------------------------------------------------------"

put RetrieveRecords.fromDB into ExpectedRecords
log "The expected records are:"
LogAllRecords ExpectedRecords

If ActualRecords = ExpectedRecords
LogSuccess "The record sets match."
else
LogError "The record sets don't match."
End If

If item 5 of ActualRecords = item 5 of ExpectedRecords
put item 5 of ActualRecords
put item 5 of ExpectedRecords
LogSuccess "The 5th records match."
End If

on LogAllRecords RecordList
repeat with each item of RecordList
Log it
end repeat
end LogAllRecords

Retrieve records script:

This script retrieves individual records from a table.

function fromUI
//This function uses the View element on the screen to identify each row of data in the table.
put everyImageRectangle ("ViewIdentifier") into Rows
put imageRectangle ("ItemIDColumn") into ItemIDLoc
put imageRectangle ("NameColumn") into NameLoc
put imageRectangle ("ProductLineIDColumn") into ProductLineIDLoc

repeat with each Row of Rows
set theTop to Row's top
set theBottom to Row's bottom
put readText (ItemIDLoc's left,theTop,NameLoc's left,theBottom) into theItemID
put readText (NameLoc's left,theTop,ProductLineIDLoc's left,theBottom) into theName
insert (ItemID:theItemID,Name:theName) into TableRead
end repeat

return TableRead
end fromUI

function fromDB
set myDB to (type:"odbc", DSN:"mySQLDB", user:"root", password:"eggPlant")
put table "table_demo_data2" of myDB into myDBTable
return the records of myDBTable
end fromDB

Contains all script: This script shows how to verify whether a set of information is contained within a list.

put ((food:"Grilled Cheese",drink:"milk"),(food:"Hamburger",drink:"soda")) into ActualRecords
put ((food:"Hamburger",drink:"soda"),(food:"Grilled Cheese",drink:"lemonade")) into ExpectedRecords

repeat with each myRecord of ExpectedRecords
Assert that ActualRecords contains myRecord with warning
end repeat

Read full table script: This script reads all rows of data in a data table when there is no identifier for each data row.

put imageRectangle ("SymbolColumn") into SymbolColumnLoc
put foundImageInfo()'s imageLocation into StartLoc
put imageRectangle ("NameColumn") into NameColumnLoc
put imageRectangle ("PriceColumn") into PriceColumnLoc
put (StartLoc,(SymbolColumnLoc's right,StartLoc's y + 42)) into SymbolRead
put ((NameColumnLoc's left, StartLoc's y),(NameColumnLoc's right,StartLoc's y + 42)) into NameRead
put ((PriceColumnLoc's left, StartLoc's y),(PriceColumnLoc's right,StartLoc's y + 42)) into PriceRead
repeat until endofTable is true
put readtext(SymbolRead) into Symbol
if Symbol is empty then
set endofTable to true
exit repeat
end if
put readtext(NameRead) into Name
put readtext(PriceRead) into Price
add ((0,45),(0,45)) to SymbolRead
add ((0,45),(0,45)) to NameRead
add ((0,45),(0,45)) to PriceRead
insert (Symbol:Symbol, Name:Name, Price:Price) after TableRead
end repeat

Log "The table records are:"
Log TableRead

Read adjacent entry script: This script searches for an expected value within a search rectangle, and then validates content adjacent to the found expected value.

Set the searchRectangle to ("FIRSTColumn",(imageLocation("LASTColumn")'s x, the remotescreensize's y))

repeat until imageFound (text:"EG629610")
MoveTo the remoteScreenRectangle's center
ScrollWheelDown 4
end repeat

set the searchRectangle to ()

put foundImageInfo()'s imageRectangle into RowLoc
put imageRectangle ("LASTColumn") into LASTColumnLoc

put (LASTColumnLoc's left, RowLoc's Top - 20, imageLocation("DOBColumn")'s x, RowLoc's Bottom + 20) into LastNameReadArea

Assert that readText(LastNameReadArea) is "DemoCardio"

Find entry script This script searches for an expected value within a search rectangle.

put readText ("RecordNumberUL","RecordNumberLR") into PatientPRN

Set the searchRectangle to ("FIRSTColumn",(imageLocation("LASTColumn")'s x, the remotescreensize's y))

WaitFor 10, text:PatientPRN

Use remote clipboard script: This script uses the clipboard to retrieve a data value from a specific column for a specific row of the data table.

put imageRectangle ("GasolinePerGallonColumn") into GasolineLoc
put imageLocation(image:"UnitedStatesColumn",searchRectangle:(GasolineLoc's topLeft,(GasolineLoc's right, the remoteScreenSize's height))) into ColumnLoc

DoubleClick (ColumnLoc's x,imageLocation ("MayRow")'s y)

TypeText ControlKey,"c"

put the remoteClipBoard into DollarValue
Log "The scraped value is"&&DollarValue&period

If DollarValue is greater than 2.000 then
LogSuccess "The value is greater than 2 dollars."
else
LogWarning "The value is equal to or less than 2 dollars."
End If

Scroll and extract script: This script continues scrolling the data table, retrieving and storing the data rows for each page of the data table.

put imageRectangle ("RowNumColumn") into RowLoc
put foundImageInfo()'s imageLocation into StartUpperLeft
put imageRectangle ("ScrollProgressColumn") into ScrollLoc

put (StartUpperLeft,(RowLoc's right,StartUpperLeft's y + 38)) into RowRead
put ((ScrollLoc's left, StartUpperLeft's y),(ScrollLoc's right,StartUpperLeft's y + 38)) into ScrollRead

repeat until the number of items of Records is greater than 50
set EndReached to false
repeat until EndReached is true
put readText(RowRead) into RowValue
if RowValue is empty then
set EndReached to true
exit repeat
end if
put readText(ScrollRead) into ScrollValue
add ((0,37),(0,37)) to RowRead
add ((0,37),(0,37)) to ScrollRead
insert (RowNumber:RowValue,ScrollProgressPercent:ScrollValue) into Records
end repeat
TypeText PageDown
wait 3
put the last item of Records into LastReadRecord
put LastReadRecord's ScrollProgressPercent into LastReadPercent
put imageRectangle (text:LastReadPercent)'s bottom into LastLocY
put ((RowLoc's left,LastLocY + 14),(RowLoc's right,LastLocY + 51)) into RowRead
put ((ScrollLoc's left, LastLocY + 14),(ScrollLoc's right,LastLocY + 51)) into ScrollRead
end repeat

log records

Validate records script: This script uses optical character recognition (OCR) to search against a displayed data table for all values stored in a database table.

set myDB to (type:"odbc", DSN:"mySQLDB", user:"root", password:"eggPlant")
put table "table_demo_data" of myDB into myDBTable
put the records of myDBTable into myDBData

set the searchRectangle to ("TableUL","TableLR")
repeat with each myRecord of myDBData
WaitFor 5, text:myRecord's Time
WaitFor 5, text:myRecord's Gene_Copies
end repeat