| 1 |
The scripts are written in QtScript, a dialect of ECMAScript; most of QtCore |
| 2 |
and QtGui are bound - for example, you can get the user's home directory like |
| 3 |
this: |
| 4 |
|
| 5 |
var home = QDesktopServices.storageLocation(QDesktopServices.HomeLocation); |
| 6 |
|
| 7 |
In general, consult http://doc.trolltech.com/, replacing "::" with ".". |
| 8 |
|
| 9 |
The following additional methods are defined: |
| 10 |
|
| 11 |
- objectFromPath("ParentWidget::ChildWidget::GrandChildWidget"); |
| 12 |
Returns a reference to a widget in the application under test. |
| 13 |
|
| 14 |
This will generally be automatically generated via the record |
| 15 |
functionality. |
| 16 |
|
| 17 |
- assert(bool predicate); |
| 18 |
Throws an exception if the specified predicate is false. |
| 19 |
|
| 20 |
- compare(var result, var expected); |
| 21 |
Throws an exception if the provided values are different; this is |
| 22 |
preferable to assert(result == expected), as it provides a more |
| 23 |
detailed error message. |
| 24 |
|
| 25 |
- importExtension("extensionName"); |
| 26 |
Attempts to load the specified QtScript extension. If the extension can |
| 27 |
not be loaded, an exception is thrown. Example: |
| 28 |
|
| 29 |
importExtension("qt.sql"); // loads QtSql |
| 30 |
|
| 31 |
There are several options while recording to make the resulting script easier |
| 32 |
to read and alter under the "Options" menu, all of which are turned on by |
| 33 |
default: |
| 34 |
|
| 35 |
- Ignore Mouse Movements |
| 36 |
Mouse movements will not be recorded - clicks, keypresses, and all |
| 37 |
other events will be kept though. In most cases, mouse movements are a |
| 38 |
huge amount of irrelevant spam. |
| 39 |
|
| 40 |
- Simplify Strings |
| 41 |
This analyses key presses/releases to try and figure out the actual |
| 42 |
text; for example, without it, typing 'Foo' will result in (pseudocode): |
| 43 |
|
| 44 |
press(Qt.Key_Shift); |
| 45 |
wait(); |
| 46 |
press(Qt.Key_F); |
| 47 |
wait(); |
| 48 |
release(Qt.Key_F); |
| 49 |
wait(); |
| 50 |
release(Qt.Key_Shift); |
| 51 |
wait(); |
| 52 |
press(Qt.Key_O); |
| 53 |
wait(); |
| 54 |
release(Qt.Key_O); |
| 55 |
wait(); |
| 56 |
press(Qt.Key_O); |
| 57 |
wait(); |
| 58 |
release(Qt.Key_O); |
| 59 |
|
| 60 |
In reality, it will be longer than the above. When this option is |
| 61 |
enabled, instead, the following will be written to the script: |
| 62 |
|
| 63 |
sendText("Foo"); |
| 64 |
|
| 65 |
- Use Variables for Object References |
| 66 |
This reduces the number of calls to objectFromPath; for example: |
| 67 |
|
| 68 |
objectFromPath("MainWindow::centralWidget::tabWidget::mainTab::LineEdit-1").foo(); |
| 69 |
objectFromPath("MainWindow::centralWidget::tabWidget::mainTab::LineEdit-1").bar(); |
| 70 |
|
| 71 |
Will be replaced with: |
| 72 |
|
| 73 |
var LineEdit_1 = objectFromPath("MainWindow::centralWidget::tabWidget::mainTab::LineEdit-1"); |
| 74 |
LineEdit_1.foo(); |
| 75 |
LineEdit_1.bar(); |
| 76 |
|
| 77 |
- Use Variables for Strings |
| 78 |
This replaces strings for setText with variables declared at the top of the file. For example: |
| 79 |
|
| 80 |
foo(); |
| 81 |
sendText("/home/fred/someFile.txt"); |
| 82 |
baz(); |
| 83 |
|
| 84 |
Would be replaced with: |
| 85 |
|
| 86 |
var string0 = "/home/fred/someFile.txt"; |
| 87 |
foo(); |
| 88 |
sendText(string0); |
| 89 |
baz(); |