Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

MAJ 31-01-2024

To begin automation practice, we can try to personalize our template test sample.testgb by adding a new action step. Let’s observe original file :

############################################################################################
# Getting started with GDSL : a first analysis of www.gouvernement.fr                      #
############################################################################################

# Preparation #
applicationKill,com.android.chrome
browserPrepareAndOpenForReference
pause,${PAUSEAFTERLOAD}

# Blank tab reference #
measureStart,PAUSE_referenceBrowser
pause,${PAUSEDURATION}
measureStop

browserGoToUrl,https://www.gouvernement.fr/

# Loading step #
assertNotExistsText,Tout accepter
measureStart,CHRGT_home
pressEnter
waitUntilText,Tout accepter
pause,${PAUSEAFTERLOAD}
measureStop

# Pause step #
measureStart,PAUSE_home
pause,${PAUSEDURATION}
measureStop

Currently, our test browses the French government website and measures loading and idle of homepage.

We will now add an action step to accept cookies pop-up.

Generate dump

After each test, screenshots of start and end of each steps and a dump of the final state are saved.

For a testbench test:

  • Last execution is automatically selected, change if needed

  • Download files below More information

  • Files are located in the downloaded .zip file:

    • tests-results-XXXXXX.zip\tests-results\launch\parcours\iteration 1\dump\dump.uix

    • tests-results-XXXXXX.zip\tests-results\launch\parcours\iteration 1\screenshots\success.png

For a local device test:

  • Files are located in greenspector folder where testrunner was launched:

    • greenspector\XX-XX-XXXX XXhXXm\tests-results\MYAPP\parcours\iteration 1\dump\dump.uix

    • greenspector\XX-XX-XXXX XXhXXm\tests-results\MYAPP\parcours\iteration 1\screenshots\success.png

Open dump

These files are readable by Uiautomatorviewer:

  • Run it in a terminal with :

uiautomatorviewer

UiAutomatorViewer can create dump with buttons 2 and 3. However, it doesn’t use the same method as Greenspector testrunner. Use this function very carefully and prefer the following way.

  • Use button 1 and precise location of files dump.uix and success.png previously identified

  • All available UI elements are shown

Add a new step

To make our journey and measures safe, we try our best to verify the view state before and after an action. With UIAutomatorviewer, try to find the following informations:

  • Get a text in cookies pop-up

  • Get the id of the button to click

In our new steps, following actions will be made one after another:

  • Verify presence of cookie pop-up by searching for a specific text

  • If yes, click on the accept button

  • Verify disappearance of cookies pop-up

For this example:

  • Verification text: About cookies on government.fr

  • Button id: slideshow-primary-12

Add a new loading step at the end of GDSL file:

# Action step #
# Verify display of cookies pop-up
waitUntilText,About cookies on government.fr
# Start measure
measureStart,CHRGT_cookies
# Click on button
clickById,slideshow-primary-12
# Verify disappearance of cookies pop-up
waitUntilGoneText,About cookies on government.fr
# Wait for residual consumption
pause,${PAUSEAFTERACTION}
# Stop measure
measureStop

A view can often have the same text twice : choose a precise and specific text with text instructions to ensure the right element is targeted.

Prefer id methods in this special case.

Try to relaunch the test with the preferred method.

Troubleshooting

If the test failed, a detailed explanation can be found:

  • Error message indicates the line involved

  • failed.png is the equivalent of success.png in case of failure.

  • dump.uix is the last UI hierarchy before fail viewed by testrunner. To obtain another dump of an intermediate step, place the device on the requested step and use the following command :

testrunner testdslcommand -c "dump"
  • No labels