blob: 2bf43c5c08a0a8732c34b895897ed5651a47ebd3 [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
Jesse McGuire84c09702022-05-06 23:17:297You'll need a [ChromeOS 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
Jesse McGuire84c09702022-05-06 23:17:2911You'll also need a ChromeOS device running a system image built with the `test`
Daniel Erat10513362017-09-26 18:25:5312flag 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
torikauffmanca093602024-05-30 15:11:5021[ChromeOS chroot]: https://www.chromium.org/chromium-os/developer-library/guides/development/developer-guide/#create-a-chroot
22[Simple Chrome]: https://www.chromium.org/chromium-os/developer-library/guides/development/simple-chrome-workflow
23[virtual machine]: https://www.chromium.org/chromium-os/developer-library/guides/containers/cros-vm
Daniel Erated7bffa2019-04-22 14:47:4424
Ricardo Quesada1cd62052019-07-11 19:57:4225## Setup
26
Jesse McGuire84c09702022-05-06 23:17:2927### Update ChromeOS chroot
Ricardo Quesada1cd62052019-07-11 19:57:4228
Jesse McGuire84c09702022-05-06 23:17:2929Assuming that you already have a valid ChromeOS repo checked out (see
30[ChromeOS chroot]), it is recommended to update the chroot by doing:
Ricardo Quesada1cd62052019-07-11 19:57:4231
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]
Edman Anjos24effe52022-03-01 13:05:06442. Install the [official Go extension] (VSCode will recommend that extension
Keigo Oka11b8a6c2023-02-27 09:02:1045 once you open a Go file), and optionally [CrOS IDE], which [among others]
46 substitutes the step 3 and 4 once you open a Tast test file.
Ricardo Quesada1cd62052019-07-11 19:57:42473. Update the `GOPATH` environment variable to make code navigation works (`F12` key)
48
49 ```sh
50 mkdir ~/go
51 # Main GOPATH, where extra binaries will get installed.
52 export GOPATH=$HOME/go
53 # Append Tast repos to GOPATH
54 export GOPATH=${GOPATH}:${CHROMEOS_SRC}/src/platform/tast-tests:${CHROMEOS_SRC}/src/platform/tast
55 # Append Tast dependencies
56 export GOPATH=${GOPATH}:${CHROMEOS_SRC}/chroot/usr/lib/gopath
57 ```
58
594. Start Visual Studio Code with Tast
60
61 ```sh
62 cd ${CHROMEOS_SRC}/src/platform/
63 code ./tast-tests ./tast
64 ```
65
Marcello Salomaoc8c68c42022-01-30 23:53:0466Note: If you are using the VSCode "Remote-SSH" extension, restart
67VSCode's SSH server after setting the GOPATH, otherwise the Go
68extension won't pick it up. For example, using the VSCode command
69palette, you can run `>Remote-SSH: Kill VS Code Server on Host`.
70
71After that, it's useful to add the following to your settings JSON to
72avoid opening a 404 page whenever you try to follow links from import
73statements:
74
75```
76 "gopls": {
77 "ui.navigation.importShortcut": "Definition"
78 },
79```
80
81https://github.com/golang/vscode-go/issues/237#issuecomment-646067281
82
Ricardo Quesada1cd62052019-07-11 19:57:4283[modern editor]: https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins
84[Visual Studio Code]: https://code.visualstudio.com/
Edman Anjos24effe52022-03-01 13:05:0685[official Go extension]: https://code.visualstudio.com/docs/languages/go
Keigo Oka11b8a6c2023-02-27 09:02:1086[CrOS IDE]: https://marketplace.visualstudio.com/items?itemName=Google.cros-ide
87[among others]: http://go/cros-ide-doc-tast-tests
Ricardo Quesada1cd62052019-07-11 19:57:4288
Daniel Erat69966c12017-09-29 23:39:1789## Run a prebuilt test
Daniel Erat10513362017-09-26 18:25:5390
Chloe Pelling0c804fe2020-09-08 06:30:0591**WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and
92local state.
93
Daniel Erat10513362017-09-26 18:25:5394In your chroot, run the following:
95
96```sh
Angavai Shanmugam00fbf192021-07-12 20:21:3597tast -verbose run -build=false <test-device-ip> login.Chrome
Daniel Erat10513362017-09-26 18:25:5398```
99
Jesse McGuire84c09702022-05-06 23:17:29100You should see output scroll by on your workstation, and on the ChromeOS
Daniel Erat10513362017-09-26 18:25:53101device, the test should log in and load a webpage. After the test is done, take
102a look at the results in `/tmp/tast/results/latest` in your chroot.
103
Daniel Erat69966c12017-09-29 23:39:17104## Build and run a test
105
Chloe Pelling0c804fe2020-09-08 06:30:05106**WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and
107local state.
108
Daniel Erat69966c12017-09-29 23:39:17109The previous step ran a test that was already built into your device's system
110image, but you can also use the `tast` command to quickly rebuild all tests and
111push them to the device.
112
113In your chroot, run the same command as before **but without the `-build=false`
114argument**:
115
116```sh
Angavai Shanmugam00fbf192021-07-12 20:21:35117tast -verbose run <test-device-ip> login.Chrome
Daniel Erat69966c12017-09-29 23:39:17118```
119
120This time, the command will take a bit longer (but build objects will be
121cached). The test should succeed again.
122
Daniel Erat10513362017-09-26 18:25:53123See [Running Tests] for more information.
124
Daniel Erated7bffa2019-04-22 14:47:44125[Running Tests]: running_tests.md
126
Daniel Erat10513362017-09-26 18:25:53127## Modify a test
128
Jesse McGuire84c09702022-05-06 23:17:29129Now, let's modify the test. In your ChromeOS checkout, go to
Seewai Fu85c8e4d2023-05-31 23:46:38130`src/platform/tast-tests/src/go.chromium.org/tast-tests/cros/local/bundles/cros/login` and open
Yu-Ping Wu46e3fc22023-06-28 08:02:40131`chrome.go` (for convenience, there's also a `cros` symlink at the
Keigo Okae2165fd2021-08-16 23:55:01132top of `tast-tests`). The `Chrome` function here will run directly on the
Daniel Erat10513362017-09-26 18:25:53133test device.
134
Alan Green81d8d7b2022-11-20 22:09:36135At the end of the function `testChromeLogin`, add the following code:
Daniel Erat10513362017-09-26 18:25:53136
137```go
Daniel Eratf5b02582018-09-30 17:53:54138if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil {
Daniel Erat10513362017-09-26 18:25:53139 s.Error("Failed to open page: ", err)
140}
141```
142
Daniel Erat69966c12017-09-29 23:39:17143Back in your chroot, run `tast` again:
Daniel Erat10513362017-09-26 18:25:53144
145```sh
Angavai Shanmugam00fbf192021-07-12 20:21:35146tast -verbose run <test-device-ip> login.Chrome
Daniel Erat10513362017-09-26 18:25:53147```
148
Daniel Erat69966c12017-09-29 23:39:17149This time, the test should additionally open a Google search page.
Daniel Erat10513362017-09-26 18:25:53150
151Return to the test file and add the following statement at the end of the
Alan Green81d8d7b2022-11-20 22:09:36152function `testChromeLogin`:
Daniel Erat10513362017-09-26 18:25:53153
154```go
155s.Error("This is an intentional error")
156```
157
158If you build and run the test again, you should see it fail.
159
Daniel Eratfe123692018-09-05 20:17:35160## Next steps
161
Ricardo Quesada1cd62052019-07-11 19:57:42162See [Writing Tests] for more information, and explore the
163[tast-tests repository] to see existing tests and related packages. [Codelab #1]
164walks through the creation of a simple test.
Daniel Erated7bffa2019-04-22 14:47:44165
Daniel Eratfe123692018-09-05 20:17:35166Additional Tast documentation is available in the [tast repository].
Daniel Erat10513362017-09-26 18:25:53167
168Many resources are available for learning more about Go. Here are a few:
169
170* [A Tour of Go] - In-browser introduction to Go's core features.
171* [Official Go documentation] - Package documentation, specifications, blog
172 posts, and recorded talks.
Daniel Erat396132f2018-09-23 15:46:43173* [Go at Google: Language Design in the Service of Software Engineering] -
174 High-level overview of Go's features and design philosophy.
Daniel Erat10513362017-09-26 18:25:53175* [Community Learn wiki] - Links to external resources.
176
Daniel Erat10513362017-09-26 18:25:53177[Writing Tests]: writing_tests.md
Daniel Eratfe123692018-09-05 20:17:35178[tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/
Daniel Erated7bffa2019-04-22 14:47:44179[Codelab #1]: codelab_1.md
Daniel Eratfe123692018-09-05 20:17:35180[tast repository]: https://chromium.googlesource.com/chromiumos/platform/tast/
Daniel Erat10513362017-09-26 18:25:53181[A Tour of Go]: https://tour.golang.org/
182[Official Go documentation]: https://golang.org/doc/
Daniel Erat396132f2018-09-23 15:46:43183[Go at Google: Language Design in the Service of Software Engineering]: https://talks.golang.org/2012/splash.article
Daniel Erat10513362017-09-26 18:25:53184[Community Learn wiki]: https://github.com/golang/go/wiki/Learn