blob: 1156d4922f11737724852f04d7662278eab11645 [file] [log] [blame] [view]
Daniel Erat599e0242018-09-15 00:52:551# Tast Quickstart (go/tast-quickstart)
Daniel Erat10513362017-09-26 18:25:532
3[TOC]
4
5## Prerequisites
6
Daniel Eratfe123692018-09-05 20:17:357You'll need a [Chrome OS chroot]. If you've only done Chrome development so far,
Ricardo Quesada1cd62052019-07-11 19:57:428note that this is different from the Chrome checkout described in the
9[Simple Chrome] documentation.
Daniel Erat10513362017-09-26 18:25:5310
11You'll also need a Chrome OS device running a system image built with the `test`
12flag that's reachable from your workstation via SSH. An image running in a
Daniel Eratfe123692018-09-05 20:17:3513[virtual machine] will also work. If you're using a test image that you
14downloaded rather than one built in your chroot, make sure that it's a recent
15version.
Daniel Erat10513362017-09-26 18:25:5316
Chloe Pelling0c804fe2020-09-08 06:30:0517<a name="dataloss"></a> **WARNING: Potential data loss:** Many Tast tests
18remove all user profiles from the device when run, including any local state.
19Prefer to have a device specifically for testing.
20
Daniel Erated7bffa2019-04-22 14:47:4421[Chrome OS chroot]: http://www.chromium.org/chromium-os/quick-start-guide
22[Simple Chrome]: https://chromium.googlesource.com/chromiumos/docs/+/master/simple_chrome_workflow.md
23[virtual machine]: https://chromium.googlesource.com/chromiumos/docs/+/master/cros_vm.md
24
Ricardo Quesada1cd62052019-07-11 19:57:4225## Setup
26
27### Update Chrome OS chroot
28
29Assuming that you already have a valid Chrome OS repo checked out (see
30[Chrome OS chroot]), it is recommended to update the chroot by doing:
31
32```sh
33cd ${CHROMEOS_SRC}
34chromite/bin/cros_sdk # to enter chroot
35./update_chroot # makes sure that the latest dependencies are installed
36```
37
38### IDE
39
40Any [modern editor] supports Go. The following are the instructions to setup
41[Visual Studio Code] with Tast code navigation:
42
431. Download [Visual Studio Code]
442. Install the
45 [Microsoft Go plugin] (VSCode will recommend that plugin once you open a Go file)
463. Update the `GOPATH` environment variable to make code navigation works (`F12` key)
47
48 ```sh
49 mkdir ~/go
50 # Main GOPATH, where extra binaries will get installed.
51 export GOPATH=$HOME/go
52 # Append Tast repos to GOPATH
53 export GOPATH=${GOPATH}:${CHROMEOS_SRC}/src/platform/tast-tests:${CHROMEOS_SRC}/src/platform/tast
54 # Append Tast dependencies
55 export GOPATH=${GOPATH}:${CHROMEOS_SRC}/chroot/usr/lib/gopath
56 ```
57
584. Start Visual Studio Code with Tast
59
60 ```sh
61 cd ${CHROMEOS_SRC}/src/platform/
62 code ./tast-tests ./tast
63 ```
64
65[modern editor]: https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins
66[Visual Studio Code]: https://code.visualstudio.com/
67[Microsoft Go plugin]: https://code.visualstudio.com/docs/languages/go
68
Daniel Erat69966c12017-09-29 23:39:1769## Run a prebuilt test
Daniel Erat10513362017-09-26 18:25:5370
Chloe Pelling0c804fe2020-09-08 06:30:0571**WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and
72local state.
73
Daniel Erat10513362017-09-26 18:25:5374In your chroot, run the following:
75
76```sh
Kevin Shelton4deb1892018-05-18 19:40:4177tast -verbose run -build=false <test-device-ip> ui.ChromeLogin
Daniel Erat10513362017-09-26 18:25:5378```
79
80You should see output scroll by on your workstation, and on the Chrome OS
81device, the test should log in and load a webpage. After the test is done, take
82a look at the results in `/tmp/tast/results/latest` in your chroot.
83
Daniel Erat69966c12017-09-29 23:39:1784## Build and run a test
85
Chloe Pelling0c804fe2020-09-08 06:30:0586**WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and
87local state.
88
Daniel Erat69966c12017-09-29 23:39:1789The previous step ran a test that was already built into your device's system
90image, but you can also use the `tast` command to quickly rebuild all tests and
91push them to the device.
92
93In your chroot, run the same command as before **but without the `-build=false`
94argument**:
95
96```sh
Kevin Shelton4deb1892018-05-18 19:40:4197tast -verbose run <test-device-ip> ui.ChromeLogin
Daniel Erat69966c12017-09-29 23:39:1798```
99
100This time, the command will take a bit longer (but build objects will be
101cached). The test should succeed again.
102
Daniel Erat10513362017-09-26 18:25:53103See [Running Tests] for more information.
104
Daniel Erated7bffa2019-04-22 14:47:44105[Running Tests]: running_tests.md
106
Daniel Erat10513362017-09-26 18:25:53107## Modify a test
108
Daniel Erat69966c12017-09-29 23:39:17109Now, let's modify the test. In your Chrome OS checkout, go to
Daniel Eratd7773002017-12-30 11:11:34110`src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/ui` and open
Kevin Sheltonb922f1e2018-05-18 20:17:56111`chrome_login.go` (for convenience, there's also a `local_tests` symlink at the
Kevin Shelton4deb1892018-05-18 19:40:41112top of `tast-tests`). The `ChromeLogin` function here will run directly on the
Daniel Erat10513362017-09-26 18:25:53113test device.
114
Paul Fagerburg6a6a4fa2020-04-17 17:34:21115At the end of the anonymous function inside `testChromeLogin`, add the following code:
Daniel Erat10513362017-09-26 18:25:53116
117```go
Daniel Eratf5b02582018-09-30 17:53:54118if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil {
Daniel Erat10513362017-09-26 18:25:53119 s.Error("Failed to open page: ", err)
120}
121```
122
Daniel Erat69966c12017-09-29 23:39:17123Back in your chroot, run `tast` again:
Daniel Erat10513362017-09-26 18:25:53124
125```sh
Kevin Shelton4deb1892018-05-18 19:40:41126tast -verbose run <test-device-ip> ui.ChromeLogin
Daniel Erat10513362017-09-26 18:25:53127```
128
Daniel Erat69966c12017-09-29 23:39:17129This time, the test should additionally open a Google search page.
Daniel Erat10513362017-09-26 18:25:53130
131Return to the test file and add the following statement at the end of the
Paul Fagerburg6a6a4fa2020-04-17 17:34:21132anonymous function inside `testChromeLogin`:
Daniel Erat10513362017-09-26 18:25:53133
134```go
135s.Error("This is an intentional error")
136```
137
138If you build and run the test again, you should see it fail.
139
Daniel Eratfe123692018-09-05 20:17:35140## Next steps
141
Ricardo Quesada1cd62052019-07-11 19:57:42142See [Writing Tests] for more information, and explore the
143[tast-tests repository] to see existing tests and related packages. [Codelab #1]
144walks through the creation of a simple test.
Daniel Erated7bffa2019-04-22 14:47:44145
Daniel Eratfe123692018-09-05 20:17:35146Additional Tast documentation is available in the [tast repository].
Daniel Erat10513362017-09-26 18:25:53147
148Many resources are available for learning more about Go. Here are a few:
149
150* [A Tour of Go] - In-browser introduction to Go's core features.
151* [Official Go documentation] - Package documentation, specifications, blog
152 posts, and recorded talks.
Daniel Erat396132f2018-09-23 15:46:43153* [Go at Google: Language Design in the Service of Software Engineering] -
154 High-level overview of Go's features and design philosophy.
Daniel Erat10513362017-09-26 18:25:53155* [Community Learn wiki] - Links to external resources.
156
Daniel Erat10513362017-09-26 18:25:53157[Writing Tests]: writing_tests.md
Daniel Eratfe123692018-09-05 20:17:35158[tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/
Daniel Erated7bffa2019-04-22 14:47:44159[Codelab #1]: codelab_1.md
Daniel Eratfe123692018-09-05 20:17:35160[tast repository]: https://chromium.googlesource.com/chromiumos/platform/tast/
Daniel Erat10513362017-09-26 18:25:53161[A Tour of Go]: https://tour.golang.org/
162[Official Go documentation]: https://golang.org/doc/
Daniel Erat396132f2018-09-23 15:46:43163[Go at Google: Language Design in the Service of Software Engineering]: https://talks.golang.org/2012/splash.article
Daniel Erat10513362017-09-26 18:25:53164[Community Learn wiki]: https://github.com/golang/go/wiki/Learn