28 noiembrie 2019

QF teste: exemple de procedura



import java.nio.file.Path

import java.util.concurrent.TimeUnit
import java.util.regex.Pattern

def referenceFile = rc.lookup("referenceFile")
def actualFile = rc.lookup("generatedFile")

def reference = new File(referenceFile).text
def actual = new File(actualFile).text

def isADELrapFormat = reference.contains("<ADELrap")

if(isADELrapFormat) {
    reference = fixFieldsToBeIgnoredInComparison(reference)
    actual = fixFieldsToBeIgnoredInComparison(actual)
}

rc.setLocal("areIdentical", rc.checkEqual(reference, actual, "Mesaj", level:2, report:true, nowrap:false))

private static String fixFieldsToBeIgnoredInComparison(final String xml) {
    final Pattern last_modified_time = Pattern.compile("<LAST_MODIFIED_TIME>.*</LAST_MODIFIED_TIME>");
    return last_modified_time.matcher(xml).replaceFirst("<LAST_MODIFIED_TIME>XXXX</LAST_MODIFIED_TIME>")
}

27 noiembrie 2019

QF teste


Basic setup

Get the ApplicationsSetup_branch.qft (the list of test suites) from STI.
Open it with QF, modify its variable definitions:
  • mainAppRootDir should point to the distribution which will be tested (which has the folders: bin, license, matlab, etc)
  • setup_version should be R9999.9999
  • create two local folders and make testDataFolder and TestResultsFolder point to them
Make sure "Name override mode" is set to "Override everything": go to Edit -> Options, check in Record -> Components and Replay -> Recognition.


Start the application

The application is run from QF itself: go to the left panel -> Procedures -> Dependency: Dependency -> Setup: Start SUT and hit the play button


Create a test

An easy way to record a run is to create a new sequence. If you go to the left panel -> Extras you will see a list of sequences and play one of them to see what it is doing.


Basic steps to create a new sequence
  1. Hit the record button
  2. Do something in your application
  3. Hit the square button to stop recording
  4. When you play the recording, a normal exit disables the Play button and nothing happens, whereas for test failure you will see an error window.

Tips

Depending on the tool you are testing, it is nice to start by deleting the current project and make a new one. Before you stop recording, it is nice to bring the screen to the same place you started from (without deleting the current project though).

Copy your input files into testDataFolder.
When you load your input files, make sure you start from a common parent of testDataFolder and testResultsFolder and then navigate to the file you need. This will make it clear for the QF tool on how to get there.

If you have to export files, export them to your testResultsFolder and navigate to it like described at (2).
Once you first exported a file, rename it using the keyword "reference" to save it as a reference.
To compare the reference file with the newly generated file, use the method shellutils.compareFiles:
  • right click on the sequence -> insert node -> procedure nodes -> procedure call
  • procedure name is "shellutils.compareFiles", variable return type is "areIdentical"
  • you need to fill out 2 variable definitions, one for referenceFile and the other for generatedFile (enter your paths)
  • you need to move the procedure call inside the body of the sequence, as its last step
  • the body of the compareFiles is located in Procedures -> Package: shellutils -> Procedure: compareFiles
  • you can use a different procedure call or make your own, if the above doesn't fit you.
Your sequence doesn't have to cover the whole flow. You can stop the sequence at any time and with the next sequence resume from where you left off.

Steps inside a sequence (such as mouse events, inputs, etc) can be moved freely to another sequence in case the use case is split. Also, if QF doesn't capture certain components, feel free to stop the sequence before QF will throw the error, and start a new sequence after you have manually fixed it or just waited for it to disappear.