/
Best practices and tips

Best practices and tips

UPDATE 19 NOV 2024

Process of script writing

We recommend that you add the steps to your test file progressively:

  1. Add the startMeasure keyword,Step name to the test file

  2. Add the GDSL instruction(s) for composing the step (e.g. click)

  3. Identify a text on the application that should appear at the end of the action or load

  4. Add the expected text with a wait keyword

  5. Add the stopMeasure keyword to end the measurement

  6. Launch the test

  7. Continue like that step by step

Note: The step for measuring residual loads is necessary because resources are used even if the view is present (end of loading of certain page elements, scripts...). In this case, the line pause,${PAUSEAFTERLOAD} is used.

The extension for VS Code guides in that process and help avoiding errors.

 

## Add meaningful comments to the code :

  • At the beginning of the script, give a brief description of the scenario

  • When using a ClickByXY or ClickById command, indicate the action performed by this command.

  • When using an if, while or find command. Specify the purpose of the use.

  • When a manipulation is out of the ordinary (need for manual intervention, out-of-measure processing, abnormal pause, etc.) Explain the manipulation in question and why it must be carried out in this way.

 

Tips for automation

Switch the terminal in English because the testbench terminals are in English.

To go faster during the writing of script and test part, modify the job.yml file:

  • Replace PAUSEDURATION: 30000which configures the time of a pause step, by PAUSEDURATION: 1000

  • config-skipsetupphone: true allows to skip device preparation at the beginning of the test

  • Command testrunner testdslcommand -c "clickBy..." allows you to run a single command without restarting an entire script.

  • --dd or --disable-dumpsys to delete the dumpsys iteration with the CLI. Be careful to remove this option for final measurements.

 

Each time you launch a test, it is sent on Greenspector server by default. During the automation phase, it is not necessary to sent data on web interface. In job.yml file,

  • Replace online: true by online: false to avoid unnecessary measurements to appear in the web interface

If you want to see detailled results on Greenspector Studio, set this parameter at true and create a test version not to mix them with official measures.

 

Sometimes there are elements that are only present on the first display of a screen. This can cause problems when several tests are run on the same application.

We therefore recommend that you use the following commands: The "waitUntilBeforeClick"

  • waitUntilByTextBeforeClick

  • waitUntilByDescBeforeClick

  • waitUntilByTextExactBeforeClick

  • waitUntilByIdBeforeClick

The second parameter of these methods is an optional Boolean which, if set to true, prevents the test from failing on this instruction even if it is false. The default value of this parameter is false.

This test will fail if “OK” is not found: waitUntilByTextBeforeClick,OK

This test continues on the next instruction if “OK” is not found: waitUntilByTextBeforeClick,OK,true

 

GDSL best practices

Prepare the measuring web environment with browserPrepareAndOpenForReference which cleans and closes open tabs. Next, an all-black page is opened (https://dl.greenspector.com/black/), which will be used as the reference measurement for the web.

 

Name steps with camelCase naming convention (example : CHRGT_homePage)

  • Do not use “/” in step name : measures will not be sent

  • Enter the view name in the step name:

    • CHRGT_[viewName]

    • In the case of an action step, we recommend using a name of the form ACTION_[viewName]_[actionName] (example: ACTION_homePage_writeSearch)

    • SCROLL_[ viewName]

    • PAUSE_[viewName]

 

When loading a new view :

  • Wait (waitUntil) for the last element to be displayed. This command can also be used to detect the success of an action (if this leads to a change in the display).

    • It is recommended that you wait for the exact element: waitUntilTextExact

    • In all cases, use waitUntilPageLoaded as a last resort. Not all data is loaded after this function. This depends on the quality of the network. It is preferable to use a function such as waitUntilText or waitUntilId.

  • Before proceeding with a load measurement, check that the expected element (waitUntil) is not already present: (assertNotExists)

 

Values of pause steps :

  • A pause step follows each loading step. It then has a PAUSEDURATION duration of 30000 ms. This type of pause can also be used to measure the inactive state of a digital service.

  • A PAUSEAFTERLOAD pause of 1000 ms at the end of the loading and action/scroll stages.

  • A PAUSEAFTERACTION pause of 500 ms is placed after each action command (except before a PAUSEAFTERLOAD pause). This ensures that the steps last at least one second.

  • A PAUSEAFTERSCROLL pause of 500 ms is placed after each scroll/swipe command (except before a PAUSEAFTERLOAD pause).

 

Priorities of element detection tag : text/description > id > class > package

  • If it's not possible to find the element via these tags, use the tree method (parent/child)

  • Only if the above methods are not possible, use XY or Percent (and specify the element clicked as a comment).

 

When scrolling, swipeVertical is preferable to scrollDownward and scrollUpward, as it is more precise. For even greater precision, you can add a 4th parameter with the swipe time (default 500 ms). For more information, see scroll documentation.

The swipeVertical function does not exist on iOS. Instead, there are the scrollDown, scrollUp and swipe functions.

 

On the web in particular, accept cookies in a separate measure:

measureStart,CHRGT_homePageAfterCookies clickByText,accept all waitUntilText,Actu pause,${PAUSEAFTERLOAD} measureStop measureStart,PAUSE_homePageAfterCookies pause,${PAUSEDURATION} measureStop

 

The clickByText function searches by text, then by description. It is therefore useful when the description is accessible.

 

When filling in forms :

  • The pressBack function can be used to deactivate the keyboard. It can also be used to exit full-screen mode for videos.

  • If fields are not accessible by their text, description or identifier, you can use the clickOnFirstEmptyEditText function. This selects the next empty text field.

  • After the enterText function, do not enter any special or accented characters, as they are not taken into account. This function can also invert numbers when filling in a telephone number in a field. To get round this problem, you can use functions starting with setText.