Did you know ...
you can extend the Python installation used by Squish to make more script modules available to your test scripts
During evaluation or for simple test scenario it is common that test scripts are contained in their own file. But once the requirements for testing start to get more complicated it can happens that two or more test scripts have some common code, this is usually handled by putting the shared code into a single file that is imported when needed. There is two ways to import script modules in your main test script: source() and Python's import.
Importing a module in a test script is the same as importing a module in Python, as long as the
PYTHONPATHcontains the folder(s) where your modules are stored, you can import them. Extending the
PYTHONPATHcan be done before starting either the IDE/squishrunner/server or in the test script itself, something along the lines of:
This is the preferred method as this enable some functionality like code completion in the IDE. You can find it in our manual here
Note: If MyImportantModule uses a Squish function, it will have to import the necessary Squish's modules. You can find more information about it here.
One of the function available in a test script is
source(), this function is equivalent to an C++
#include, i.e it pastes the content of the sourced file where the
source()call is made. Assuming that MyImportantModule looks like:
test.log("Hello world ! (from MyImportantModule)")
Then our test script would look like this:
# will be replaced by the content of the file, i.e:
# test.log("Hello world ! (from MyImportantModule)")
you can change the Python installation which Squish uses
While writing your own module can be helpful at times, it is also known that Python has numerous modules/packages ready to be used. At this point it is worth noting that the Python shipped with Squish is stripped from some modules and pip. So in order to have access to the vast number of modules, we have explained the few steps to follow in order to use a different Python than the one we ship. You can find theses in the following knowledge base article: https://kb.froglogic.com/display/KB/Changing+the+Python+installation+used+by+Squish+binary+packages
you can automate applications using the Squish script API in Python scripts executed via a standard Python interpreter
One reason, among others, when this can prove useful: some scripts are used to automate/test your application and you would like to augment them with different Squish functions/features. An explanation on how to achieve it is already available in our knowledge base: https://kb.froglogic.com/display/KB/Using+Squish+as+a+module+in+other+Python+scripts%2C+applications