xxxxxxxxxx
TEST.log.pass("The rows are correctly sorted by " + property + " in " + order + " order.")
I.goTo("https://datatables.net/examples/basic_init/table_sorting.html")
// We want to validate that the table is sorted by the age of the employees in descending order
// First, we'll read the data of the table into a json array
var rowData = readTableToJsonArray("#example") // read the "#example" table into a json array
TEST.log.info("Row data is: " + JSON.stringify(rowData))
// this will pass
validateSorting(rowData, "Age", "DESC")
// this will obviously fail
validateSorting(rowData, "Office", "ASC")
// Click on position to sort by position in ascending order
I.click("Position")
// Get the data of the table again
rowData = readTableToJsonArray("#example") // read the "#example" table into a json array
TEST.log.info("Row data is: " + JSON.stringify(rowData))
// Validate the sorting of the rows by "Position"
validateSorting(rowData, "Position", "ASC")
//===================================================================
// This is a helper function to read a HTML table into a JSON Array
//===================================================================
function readTableToJsonArray(tableSelector){
return UI.execute(function(tableSelector){
var tableElement = document.querySelector(tableSelector)
var rowElements = tableElement.querySelectorAll("tr")
// read the headers into an array
var headerRowElement = rowElements[0]
var headers = []
headerRowElement.querySelectorAll("th").forEach(function(th){
headers.push(th.textContent)
Hi, I'm TAMI (Test Authoring Machine Intelligence).
Let me assist you in writing a test. Tell me a scenario to test, and I’ll write the test script for you!

FAILED. 0 of 1 errors
7s (2s)
1.
[start of test]
2.
I go to "https://datatables.net/examples/basic_init/table_sorting.html"
1.7s
3.
Execute Javascript: function (tableSelector){
var tableElement = document.querySelector(tableSelector)
var rowElements = tableElement.querySelectorAll("tr...
0.3s
4.
Row data is: [{"Age":"66","Name":"Ashton Cox","Office":"San Francisco","Position":"Junior Technical Author","Salary":"$86,000","Start date":"2009-01-12","rowNumber":1},{"Age":"66","Name":"Michael Silva","Office":"London","Position":"Marketing Designer","Salary":"$198,500","Start date":"2012-11-27","rowNumber":2},{"Age":"65","Name":"Jackson Bradshaw","Office":"New York","Position":"Director","Salary":"$645,750","Start date":"2008-09-26","rowNumber":3},{"Age":"64","Name":"Paul Byrd","Office":"New York","Position":"Chief Financial Officer (CFO)","Salary":"$725,000","Start date":"2010-06-09","rowNumber":4},{"Age":"64","Name":"Olivia Liang","Office":"Singapore","Position":"Support Engineer","Salary":"$234,500","Start date":"2011-02-03","rowNumber":5},{"Age":"64","Name":"Serge Baldwin","Office":"Singapore","Position":"Data Coordinator","Salary":"$138,575","Start date":"2012-04-09","rowNumber":6},{"Age":"63","Name":"Garrett Winters","Office":"Tokyo","Position":"Accountant","Salary":"$170,750","Start date":"2011-07-25","rowNumber":7},{"Age":"63","Name":"Zenaida Frank","Office":"New York","Position":"Software Engineer","Salary":"$125,250","Start date":"2010-01-04","rowNumber":8},{"Age":"62","Name":"Vivian Harrell","Office":"San Francisco","Position":"Financial Controller","Salary":"$452,500","Start date":"2009-02-14","rowNumber":9},{"Age":"61","Name":"Tiger Nixon","Office":"Edinburgh","Position":"System Architect","Salary":"$320,800","Start date":"2011-04-25","rowNumber":10}]
5.
The rows are correctly sorted by Age in desc order.
6.
The rows are NOT sorted by Office in asc order.
Error: The rows are NOT sorted by Office in asc order.
7.
I click "Position"
8.
Execute Javascript: function (tableSelector){
var tableElement = document.querySelector(tableSelector)
var rowElements = tableElement.querySelectorAll("tr...
9.
Row data is: [{"Age":"63","Name":"Garrett Winters","Office":"Tokyo","Position":"Accountant","Salary":"$170,750","Start date":"2011-07-25","rowNumber":1},{"Age":"33","Name":"Airi Satou","Office":"Tokyo","Position":"Accountant","Salary":"$162,700","Start date":"2008-11-28","rowNumber":2},{"Age":"47","Name":"Angelica Ramos","Office":"London","Position":"Chief Executive Officer (CEO)","Salary":"$1,200,000","Start date":"2009-10-09","rowNumber":3},{"Age":"64","Name":"Paul Byrd","Office":"New York","Position":"Chief Financial Officer (CFO)","Salary":"$725,000","Start date":"2010-06-09","rowNumber":4},{"Age":"40","Name":"Yuri Berry","Office":"New York","Position":"Chief Marketing Officer (CMO)","Salary":"$675,000","Start date":"2009-06-25","rowNumber":5},{"Age":"48","Name":"Fiona Green","Office":"San Francisco","Position":"Chief Operating Officer (COO)","Salary":"$850,000","Start date":"2010-03-11","rowNumber":6},{"Age":"27","Name":"Donna Snider","Office":"New York","Position":"Customer Support","Salary":"$112,000","Start date":"2011-01-25","rowNumber":7},{"Age":"64","Name":"Serge Baldwin","Office":"Singapore","Position":"Data Coordinator","Salary":"$138,575","Start date":"2012-04-09","rowNumber":8},{"Age":"61","Name":"Thor Walton","Office":"New York","Position":"Developer","Salary":"$98,540","Start date":"2013-08-11","rowNumber":9},{"Age":"53","Name":"Suki Burks","Office":"London","Position":"Developer","Salary":"$114,500","Start date":"2009-10-22","rowNumber":10}]
10.
The rows are correctly sorted by Position in asc order.
11.
[end of test]