Daniel Erat | 599e024 | 2018-09-15 00:52:55 | [diff] [blame] | 1 | # Tast Quickstart (go/tast-quickstart) |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
Jesse McGuire | 84c0970 | 2022-05-06 23:17:29 | [diff] [blame] | 7 | You'll need a [ChromeOS chroot]. If you've only done Chrome development so far, |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 8 | note that this is different from the Chrome checkout described in the |
| 9 | [Simple Chrome] documentation. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 10 | |
Jesse McGuire | 84c0970 | 2022-05-06 23:17:29 | [diff] [blame] | 11 | You'll also need a ChromeOS device running a system image built with the `test` |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 12 | flag that's reachable from your workstation via SSH. An image running in a |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 13 | [virtual machine] will also work. If you're using a test image that you |
| 14 | downloaded rather than one built in your chroot, make sure that it's a recent |
| 15 | version. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 16 | |
Chloe Pelling | 0c804fe | 2020-09-08 06:30:05 | [diff] [blame] | 17 | <a name="dataloss"></a> **WARNING: Potential data loss:** Many Tast tests |
| 18 | remove all user profiles from the device when run, including any local state. |
| 19 | Prefer to have a device specifically for testing. |
| 20 | |
torikauffman | ca09360 | 2024-05-30 15:11:50 | [diff] [blame] | 21 | [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 Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 24 | |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 25 | ## Setup |
| 26 | |
Jesse McGuire | 84c0970 | 2022-05-06 23:17:29 | [diff] [blame] | 27 | ### Update ChromeOS chroot |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 28 | |
Jesse McGuire | 84c0970 | 2022-05-06 23:17:29 | [diff] [blame] | 29 | Assuming that you already have a valid ChromeOS repo checked out (see |
| 30 | [ChromeOS chroot]), it is recommended to update the chroot by doing: |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 31 | |
| 32 | ```sh |
| 33 | cd ${CHROMEOS_SRC} |
| 34 | chromite/bin/cros_sdk # to enter chroot |
| 35 | ./update_chroot # makes sure that the latest dependencies are installed |
| 36 | ``` |
| 37 | |
| 38 | ### IDE |
| 39 | |
| 40 | Any [modern editor] supports Go. The following are the instructions to setup |
| 41 | [Visual Studio Code] with Tast code navigation: |
| 42 | |
| 43 | 1. Download [Visual Studio Code] |
Edman Anjos | 24effe5 | 2022-03-01 13:05:06 | [diff] [blame] | 44 | 2. Install the [official Go extension] (VSCode will recommend that extension |
Keigo Oka | 11b8a6c | 2023-02-27 09:02:10 | [diff] [blame] | 45 | 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 Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 47 | 3. 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 | |
| 59 | 4. Start Visual Studio Code with Tast |
| 60 | |
| 61 | ```sh |
| 62 | cd ${CHROMEOS_SRC}/src/platform/ |
| 63 | code ./tast-tests ./tast |
| 64 | ``` |
| 65 | |
Marcello Salomao | c8c68c4 | 2022-01-30 23:53:04 | [diff] [blame] | 66 | Note: If you are using the VSCode "Remote-SSH" extension, restart |
| 67 | VSCode's SSH server after setting the GOPATH, otherwise the Go |
| 68 | extension won't pick it up. For example, using the VSCode command |
| 69 | palette, you can run `>Remote-SSH: Kill VS Code Server on Host`. |
| 70 | |
| 71 | After that, it's useful to add the following to your settings JSON to |
| 72 | avoid opening a 404 page whenever you try to follow links from import |
| 73 | statements: |
| 74 | |
| 75 | ``` |
| 76 | "gopls": { |
| 77 | "ui.navigation.importShortcut": "Definition" |
| 78 | }, |
| 79 | ``` |
| 80 | |
| 81 | https://github.com/golang/vscode-go/issues/237#issuecomment-646067281 |
| 82 | |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 83 | [modern editor]: https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins |
| 84 | [Visual Studio Code]: https://code.visualstudio.com/ |
Edman Anjos | 24effe5 | 2022-03-01 13:05:06 | [diff] [blame] | 85 | [official Go extension]: https://code.visualstudio.com/docs/languages/go |
Keigo Oka | 11b8a6c | 2023-02-27 09:02:10 | [diff] [blame] | 86 | [CrOS IDE]: https://marketplace.visualstudio.com/items?itemName=Google.cros-ide |
| 87 | [among others]: http://go/cros-ide-doc-tast-tests |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 88 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 89 | ## Run a prebuilt test |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 90 | |
Chloe Pelling | 0c804fe | 2020-09-08 06:30:05 | [diff] [blame] | 91 | **WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and |
| 92 | local state. |
| 93 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 94 | In your chroot, run the following: |
| 95 | |
| 96 | ```sh |
Angavai Shanmugam | 00fbf19 | 2021-07-12 20:21:35 | [diff] [blame] | 97 | tast -verbose run -build=false <test-device-ip> login.Chrome |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 98 | ``` |
| 99 | |
Jesse McGuire | 84c0970 | 2022-05-06 23:17:29 | [diff] [blame] | 100 | You should see output scroll by on your workstation, and on the ChromeOS |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 101 | device, the test should log in and load a webpage. After the test is done, take |
| 102 | a look at the results in `/tmp/tast/results/latest` in your chroot. |
| 103 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 104 | ## Build and run a test |
| 105 | |
Chloe Pelling | 0c804fe | 2020-09-08 06:30:05 | [diff] [blame] | 106 | **WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and |
| 107 | local state. |
| 108 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 109 | The previous step ran a test that was already built into your device's system |
| 110 | image, but you can also use the `tast` command to quickly rebuild all tests and |
| 111 | push them to the device. |
| 112 | |
| 113 | In your chroot, run the same command as before **but without the `-build=false` |
| 114 | argument**: |
| 115 | |
| 116 | ```sh |
Angavai Shanmugam | 00fbf19 | 2021-07-12 20:21:35 | [diff] [blame] | 117 | tast -verbose run <test-device-ip> login.Chrome |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 118 | ``` |
| 119 | |
| 120 | This time, the command will take a bit longer (but build objects will be |
| 121 | cached). The test should succeed again. |
| 122 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 123 | See [Running Tests] for more information. |
| 124 | |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 125 | [Running Tests]: running_tests.md |
| 126 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 127 | ## Modify a test |
| 128 | |
Jesse McGuire | 84c0970 | 2022-05-06 23:17:29 | [diff] [blame] | 129 | Now, let's modify the test. In your ChromeOS checkout, go to |
Seewai Fu | 85c8e4d | 2023-05-31 23:46:38 | [diff] [blame] | 130 | `src/platform/tast-tests/src/go.chromium.org/tast-tests/cros/local/bundles/cros/login` and open |
Yu-Ping Wu | 46e3fc2 | 2023-06-28 08:02:40 | [diff] [blame] | 131 | `chrome.go` (for convenience, there's also a `cros` symlink at the |
Keigo Oka | e2165fd | 2021-08-16 23:55:01 | [diff] [blame] | 132 | top of `tast-tests`). The `Chrome` function here will run directly on the |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 133 | test device. |
| 134 | |
Alan Green | 81d8d7b | 2022-11-20 22:09:36 | [diff] [blame] | 135 | At the end of the function `testChromeLogin`, add the following code: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 136 | |
| 137 | ```go |
Daniel Erat | f5b0258 | 2018-09-30 17:53:54 | [diff] [blame] | 138 | if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil { |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 139 | s.Error("Failed to open page: ", err) |
| 140 | } |
| 141 | ``` |
| 142 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 143 | Back in your chroot, run `tast` again: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 144 | |
| 145 | ```sh |
Angavai Shanmugam | 00fbf19 | 2021-07-12 20:21:35 | [diff] [blame] | 146 | tast -verbose run <test-device-ip> login.Chrome |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 147 | ``` |
| 148 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 149 | This time, the test should additionally open a Google search page. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 150 | |
| 151 | Return to the test file and add the following statement at the end of the |
Alan Green | 81d8d7b | 2022-11-20 22:09:36 | [diff] [blame] | 152 | function `testChromeLogin`: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 153 | |
| 154 | ```go |
| 155 | s.Error("This is an intentional error") |
| 156 | ``` |
| 157 | |
| 158 | If you build and run the test again, you should see it fail. |
| 159 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 160 | ## Next steps |
| 161 | |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 162 | See [Writing Tests] for more information, and explore the |
| 163 | [tast-tests repository] to see existing tests and related packages. [Codelab #1] |
| 164 | walks through the creation of a simple test. |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 165 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 166 | Additional Tast documentation is available in the [tast repository]. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 167 | |
| 168 | Many 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 Erat | 396132f | 2018-09-23 15:46:43 | [diff] [blame] | 173 | * [Go at Google: Language Design in the Service of Software Engineering] - |
| 174 | High-level overview of Go's features and design philosophy. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 175 | * [Community Learn wiki] - Links to external resources. |
| 176 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 177 | [Writing Tests]: writing_tests.md |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 178 | [tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/ |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 179 | [Codelab #1]: codelab_1.md |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 180 | [tast repository]: https://chromium.googlesource.com/chromiumos/platform/tast/ |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 181 | [A Tour of Go]: https://tour.golang.org/ |
| 182 | [Official Go documentation]: https://golang.org/doc/ |
Daniel Erat | 396132f | 2018-09-23 15:46:43 | [diff] [blame] | 183 | [Go at Google: Language Design in the Service of Software Engineering]: https://talks.golang.org/2012/splash.article |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 184 | [Community Learn wiki]: https://github.com/golang/go/wiki/Learn |