source
source(filename)
Reads and evaluates the contents of filename
, line-by-line. Unlike the scripting language's normal "import" mechanism, (such as Python's import
or Perl's use
), this is more like the C++ #include
directive in that the statements are inserted into your script at that location. This is one way to parse your own shared script files rather than using the scripting language's import mechanism, which may require customization to your environment for it to locate your own modules.
A common use case is to write something like source(findFile("scripts", "common.js"))
. This uses the String findFile(where, filename) function to produce a filename including a path and then evaluates that file's contents as a script. This typically results in additional functions (and even new classes and variables) becoming available to the test script that performs this call.
For Ruby, use the built-in require
method instead—inside a function or method. For example, require findFile("scripts", "common.rb"))
.
See also, How to Create and Use Shared Data and Shared Scripts, Import Squish Resource dialog, and New Squish Test Script dialog.
© 2024 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.