Sample CLI Script Files

Link to Sample CLI Script Files copied to clipboard

This topic provides samples that will be useful for your own work. You can use some of these scripts, or some of the functions within them.

Note: You can execute shell scripts that incorporate CLI commands from the bash prompt in the Windows platform as simply as you execute the command from the shell command prompt on UNIX.

Starter Script or Template You can use the following template or starter script to start working on a simple CLI script:

  {
            "projects": [
                {
                    "name": "example-name",
                    "id": "example-id",
                    "pageList": [
                        {
                            "name": "Page 1",
                            "url": "https://changeme.com",
                            "actions": [
                                "action 1",
                                "action 2",
                                "action 3"
                            ]
                        }
                    ]
                }
            ]
        }

Sample - Adding Products to a Cart

The following sample allows you to go to the website, http://webtestingcourse.dequecloud.com/, analyze the pages, search for a specific laptop to be purchased, specify the number of laptops to be purchased, and then add the laptops to the cart. Use the analyze with title command if you want to analyze the page with a custom title. Use the wait command to wait for the given job to complete and return the exit status of the waited for command.

{
    "projects": [
      {
        "name": "Project Name",
        "id": "project-name",
        "pageList": [
          {
            "name": "Page 1",
            "url": "http://webtestingcourse.dequecloud.com/",
            "actions": [
              "wait for 1s",
              "analyze with title \"home-page\"",
              "select element \"fieldset > input[type='text'][name='q']\"",
              "change the value of \"fieldset > input[type='text'][name='q']\" to \"laptop\"",
              "select element \"#go\"",
              "wait for 1s",
              "analyze with title \"search-results\"",
  ​
              "select element \"li:nth-child(1) > a[href$='laptop1.php']\"",
              "wait for 1s",
              "analyze with title \"laptop\"",
              
              "select element \"a > img[src$='addToCartButton.gif']\"",
              "wait for 1s",
              "analyze with title \"add-to-cart\""
            ]
          }
        ]
      }
    ]
  }

Sample - Script without any Analyze Steps

The following sample is when you want to create scripts for session establishment tasks without any analyze action. An example is when a user wants to log into a website.

{
         "projects": [{
           "name": "Project Name",
           "id": "project-name",
           "pageList": [{
               "name": "Page 1",
               "url": "https://phptravels.net/login",
               "actions": [
       ​
                 "select element \".form-group > input[type='email'][name='email']\"",
                 "change the value of \".form-group > input[type='email'][name='email']\" to \"supplier@phptravels.com\"",
                 "select element \".form-group.mb-2 > input[type='password'][name='password']\"",
                 "change the value of \".form-group.mb-2 > input[type='password'][name='password']\" to \"demosupplier\"",
                 "select element \"#fadein > .container > div > .modal-content.align-self-center > .modal-body > .contact-form-action > form > div:nth-child(3) > button\"",
                                         "wait for 5s"			
               ]
             },
             {
               "name": "Page 2",
               "url": "https://phptravels.net/account/dashboard"
             }
           ]
         }]
       }

Note: To test a file without any 'analyze' actions, use the --no-analyze flag with axe DevTools CLI.