Window native key inputs in javascript for squish automation tool

1.1k views Asked by At

Can anyone please help me to reason for the issue?


type(waitForObject(":Address Book - Unnamed.File_QTableWidget"), "");

var Forename = testData.field(record, "Forename");

type(waitForObject(":Address Book - Unnamed.File_QTableWidget"), Forename);


Testdata: Forename value is 'ABCD'

But it is entering only A in the application, not the full text.

What could be the reason for entering only the 1st character of the input data?

2

There are 2 answers

0
Arindam Roychowdhury On

"type" method enters/considers only one value at a time. Ignores the rest

Try entering a letter a time

type(waitForObject(":Address Book - Unnamed.File_QTableWidget"), 'A');
type(waitForObject(":Address Book - Unnamed.File_QTableWidget"), 'B');
type(waitForObject(":Address Book - Unnamed.File_QTableWidget"), 'C');

Other alternates are

nativeType("Hello")

Or

button = findObject("Addressbook.ABCentralWidget1.AddButton")
button.setText("ABCD") 
0
amandaB On

The complete string specified in the type value parementer should be entered into the :Address Book - Unnamed.File_QTableWidget field.

Is there anything specifical about the :Address Book - Unnamed.File_QTableWidget? It appears to be a widget from the Squish sample AddressBook AUT.

A sample script using the type() and testData.field functions:

function invokeMenuItem(menu, item)
{
    activateItem(waitForObjectItem("{type='QMenuBar' visible='true'}", menu));
    activateItem(waitForObjectItem("{type='QMenu' title='" + menu + "'}", item));
}


function addNameAndAddress(oneNameAndAddress)
{
    invokeMenuItem("Edit", "Add...");
    var fieldNames = new Array("Forename", "Surname", "Email", "Phone");
    for (var i = 0; i < oneNameAndAddress.length; ++i) {
        var fieldName = fieldNames[i];
        var text = oneNameAndAddress[i];
        type(waitForObject(":" + fieldName + ":_QLineEdit"), text);
    }
    clickButton(waitForObject(":Address Book - Add.OK_QPushButton"));
}


function checkNameAndAddress(table, record)
{
    waitForObject(table);
    for (var column = 0; column < testData.fieldNames(record).length; ++column)
        test.compare(table.item(0, column).text(), // New addresses are inserted at the start
                     testData.field(record, column));
}


function closeWithoutSaving()
{
    invokeMenuItem("File", "Quit");
    clickButton(waitForObject(":Address Book.Cancel_QPushButton"));
}


function main()
{
    startApplication("addressbook");
    var table = waitForObject(":Address Book_QTableWidget");
    invokeMenuItem("File", "New");
    test.verify(table.rowCount == 0);
    var limit = 10; // To avoid testing 100s of rows since that would be boring
    var records = testData.dataset("MyAddresses.tsv");
    for (var row = 0; row < records.length; ++row) {
        var record = records[row];
        var forename = testData.field(record, "Forename");
        var surname = testData.field(record, "Surname");
        var email = testData.field(record, "Email");
        var phone = testData.field(record, "Phone");
        table.setCurrentCell(0, 0); // always insert at the start
        addNameAndAddress(new Array(forename, surname, email, phone));
        checkNameAndAddress(table, record);
        if (row > limit)
            break;
    }
    test.verify(table.rowCount == row + 1);
    closeWithoutSaving();
}