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 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 7 | You'll need a [Chrome OS 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 | |
| 11 | You'll also need a Chrome OS device running a system image built with the `test` |
| 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 | |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 21 | [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 Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 25 | ## Setup |
| 26 | |
| 27 | ### Update Chrome OS chroot |
| 28 | |
| 29 | Assuming 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 |
| 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] |
| 44 | 2. Install the |
| 45 | [Microsoft Go plugin] (VSCode will recommend that plugin once you open a Go file) |
| 46 | 3. 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 | |
| 58 | 4. 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 Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 69 | ## Run a prebuilt test |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 70 | |
Chloe Pelling | 0c804fe | 2020-09-08 06:30:05 | [diff] [blame^] | 71 | **WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and |
| 72 | local state. |
| 73 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 74 | In your chroot, run the following: |
| 75 | |
| 76 | ```sh |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 77 | tast -verbose run -build=false <test-device-ip> ui.ChromeLogin |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 78 | ``` |
| 79 | |
| 80 | You should see output scroll by on your workstation, and on the Chrome OS |
| 81 | device, the test should log in and load a webpage. After the test is done, take |
| 82 | a look at the results in `/tmp/tast/results/latest` in your chroot. |
| 83 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 84 | ## Build and run a test |
| 85 | |
Chloe Pelling | 0c804fe | 2020-09-08 06:30:05 | [diff] [blame^] | 86 | **WARNING: Potential data loss:** Tast [may delete](#dataloss) profiles and |
| 87 | local state. |
| 88 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 89 | The previous step ran a test that was already built into your device's system |
| 90 | image, but you can also use the `tast` command to quickly rebuild all tests and |
| 91 | push them to the device. |
| 92 | |
| 93 | In your chroot, run the same command as before **but without the `-build=false` |
| 94 | argument**: |
| 95 | |
| 96 | ```sh |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 97 | tast -verbose run <test-device-ip> ui.ChromeLogin |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 98 | ``` |
| 99 | |
| 100 | This time, the command will take a bit longer (but build objects will be |
| 101 | cached). The test should succeed again. |
| 102 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 103 | See [Running Tests] for more information. |
| 104 | |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 105 | [Running Tests]: running_tests.md |
| 106 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 107 | ## Modify a test |
| 108 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 109 | Now, let's modify the test. In your Chrome OS checkout, go to |
Daniel Erat | d777300 | 2017-12-30 11:11:34 | [diff] [blame] | 110 | `src/platform/tast-tests/src/chromiumos/tast/local/bundles/cros/ui` and open |
Kevin Shelton | b922f1e | 2018-05-18 20:17:56 | [diff] [blame] | 111 | `chrome_login.go` (for convenience, there's also a `local_tests` symlink at the |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 112 | top of `tast-tests`). The `ChromeLogin` function here will run directly on the |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 113 | test device. |
| 114 | |
Paul Fagerburg | 6a6a4fa | 2020-04-17 17:34:21 | [diff] [blame] | 115 | At the end of the anonymous function inside `testChromeLogin`, add the following code: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 116 | |
| 117 | ```go |
Daniel Erat | f5b0258 | 2018-09-30 17:53:54 | [diff] [blame] | 118 | if _, err = cr.NewConn(ctx, "https://www.google.com/"); err != nil { |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 119 | s.Error("Failed to open page: ", err) |
| 120 | } |
| 121 | ``` |
| 122 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 123 | Back in your chroot, run `tast` again: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 124 | |
| 125 | ```sh |
Kevin Shelton | 4deb189 | 2018-05-18 19:40:41 | [diff] [blame] | 126 | tast -verbose run <test-device-ip> ui.ChromeLogin |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 127 | ``` |
| 128 | |
Daniel Erat | 69966c1 | 2017-09-29 23:39:17 | [diff] [blame] | 129 | This time, the test should additionally open a Google search page. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 130 | |
| 131 | Return to the test file and add the following statement at the end of the |
Paul Fagerburg | 6a6a4fa | 2020-04-17 17:34:21 | [diff] [blame] | 132 | anonymous function inside `testChromeLogin`: |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 133 | |
| 134 | ```go |
| 135 | s.Error("This is an intentional error") |
| 136 | ``` |
| 137 | |
| 138 | If you build and run the test again, you should see it fail. |
| 139 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 140 | ## Next steps |
| 141 | |
Ricardo Quesada | 1cd6205 | 2019-07-11 19:57:42 | [diff] [blame] | 142 | See [Writing Tests] for more information, and explore the |
| 143 | [tast-tests repository] to see existing tests and related packages. [Codelab #1] |
| 144 | walks through the creation of a simple test. |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 145 | |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 146 | Additional Tast documentation is available in the [tast repository]. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 147 | |
| 148 | Many 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 Erat | 396132f | 2018-09-23 15:46:43 | [diff] [blame] | 153 | * [Go at Google: Language Design in the Service of Software Engineering] - |
| 154 | High-level overview of Go's features and design philosophy. |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 155 | * [Community Learn wiki] - Links to external resources. |
| 156 | |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 157 | [Writing Tests]: writing_tests.md |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 158 | [tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/ |
Daniel Erat | ed7bffa | 2019-04-22 14:47:44 | [diff] [blame] | 159 | [Codelab #1]: codelab_1.md |
Daniel Erat | fe12369 | 2018-09-05 20:17:35 | [diff] [blame] | 160 | [tast repository]: https://chromium.googlesource.com/chromiumos/platform/tast/ |
Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame] | 161 | [A Tour of Go]: https://tour.golang.org/ |
| 162 | [Official Go documentation]: https://golang.org/doc/ |
Daniel Erat | 396132f | 2018-09-23 15:46:43 | [diff] [blame] | 163 | [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] | 164 | [Community Learn wiki]: https://github.com/golang/go/wiki/Learn |