Tast Quickstart (go/tast-quickstart)

Prerequisites

You‘ll need a Chrome OS chroot. If you’ve only done Chrome development so far, note that this is different from the Chrome checkout described in the Simple Chrome documentation.

You‘ll also need a Chrome OS device running a system image built with the test flag that’s reachable from your workstation via SSH. An image running in a virtual machine will also work. If you‘re using a test image that you downloaded rather than one built in your chroot, make sure that it’s a recent version.

Setup

Update Chrome OS chroot

Assuming that you already have a valid Chrome OS repo checked out (see Chrome OS chroot), it is recommended to update the chroot by doing:

cd ${CHROMEOS_SRC}
chromite/bin/cros_sdk    # to enter chroot
./update_chroot          # makes sure that the latest dependencies are installed

IDE

Any modern editor supports Go. The following are the instructions to setup Visual Studio Code with Tast code navigation:

  1. Download Visual Studio Code

  2. Install the Microsoft Go plugin (VSCode will recommend that plugin once you open a Go file)

  3. Update the GOPATH environment variable to make code navigation works (F12 key)

    mkdir ~/go
    # Main GOPATH, where extra binaries will get installed.
    export GOPATH=$HOME/go
    # Append Tast repos to GOPATH
    export GOPATH=${GOPATH}:${CHROMEOS_SRC}/src/platform/tast-tests:${CHROMEOS_SRC}/src/platform/tast
    # Append Tast dependencies
    export GOPATH=${GOPATH}:${CHROMEOS_SRC}/chroot/usr/lib/gopath
    
  4. Start Visual Studio Code with Tast

    cd ${CHROMEOS_SRC}/src/platform/
    code ./tast-tests ./tast
    

Run a prebuilt test

In your chroot, run the following:

tast -verbose run -build=false <test-device-ip> ui.ChromeLogin

You should see output scroll by on your workstation, and on the Chrome OS device, the test should log in and load a webpage. After the test is done, take a look at the results in /tmp/tast/results/latest in your chroot.

Build and run a test

The previous step ran a test that was already built into your device's system image, but you can also use the tast command to quickly rebuild all tests and push them to the device.

In your chroot, run the same command as before but without the -build=false argument:

tast -verbose run <test-device-ip> ui.ChromeLogin

This time, the command will take a bit longer (but build objects will be cached). The test should succeed again.

See Running Tests for more information.

Modify a test

Now, let‘s modify the test. In your Chrome OS checkout, go to src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/ui and open chrome_login.go (for convenience, there’s also a local_tests symlink at the top of tast-tests). The ChromeLogin function here will run directly on the test device.

At the end of the anonymous function inside testChromeLogin, add the following code:

if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil {
	s.Error("Failed to open page: ", err)
}

Back in your chroot, run tast again:

tast -verbose run <test-device-ip> ui.ChromeLogin

This time, the test should additionally open a Google search page.

Return to the test file and add the following statement at the end of the anonymous function inside testChromeLogin:

s.Error("This is an intentional error")

If you build and run the test again, you should see it fail.

Next steps

See Writing Tests for more information, and explore the tast-tests repository to see existing tests and related packages. Codelab #1 walks through the creation of a simple test.

Additional Tast documentation is available in the tast repository.

Many resources are available for learning more about Go. Here are a few: