用于压缩自动化工具的javascript中的窗口本机键输入

时间:2014-12-03 08:45:24

标签: javascript squish

有人可以帮我解释一下这个问题吗?


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

var Forename = testData.field(记录," Forename");

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


Testdata:Forename值为' ABCD'

但它只在应用程序中输入A,而不是全文。

仅输入输入数据的第一个字符的原因是什么?

2 个答案:

答案 0 :(得分:0)

“type”方法一次只输入/考虑一个值。忽略其余的

尝试输入一个字母

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

其他替补是

nativeType("Hello")

或者

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

答案 1 :(得分:0)

类型值parementer中指定的完整字符串应输入:Address Book - Unnamed.File_QTableWidget字段。

有没有什么特别的:地址簿 - Unnamed.File_QTableWidget?它似乎是来自Squish示例AddressBook AUT的小部件。

使用type()和testData.field函数的示例脚本:

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();
}