Daniel Erat | 1051336 | 2017-09-26 18:25:53 | [diff] [blame^] | 1 | # Tast Quickstart |
| 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
| 7 | You'll need a [Chrome OS chroot]. |
| 8 | |
| 9 | You'll also need a Chrome OS device running a system image built with the `test` |
| 10 | flag that's reachable from your workstation via SSH. An image running in a |
| 11 | [virtual machine] will also work. |
| 12 | |
| 13 | ## Run a test |
| 14 | |
| 15 | In your chroot, run the following: |
| 16 | |
| 17 | ```sh |
| 18 | tast -verbose run -build=false <test-device-ip> ui.ChromeSanity |
| 19 | ``` |
| 20 | |
| 21 | You should see output scroll by on your workstation, and on the Chrome OS |
| 22 | device, the test should log in and load a webpage. After the test is done, take |
| 23 | a look at the results in `/tmp/tast/results/latest` in your chroot. |
| 24 | |
| 25 | See [Running Tests] for more information. |
| 26 | |
| 27 | ## Modify a test |
| 28 | |
| 29 | In your Chrome OS checkout, go to |
| 30 | `src/platform/tast-tests/src/chromiumos/tast/local/tests/ui` and open |
| 31 | `chrome_sanity.go`. The `ChromeSanity` function here will run directly on the |
| 32 | test device. |
| 33 | |
| 34 | At the end of the function, add the following code: |
| 35 | |
| 36 | ```go |
| 37 | if _, err = cr.NewConn(s.Context(), "https://www.google.com/"); err != nil { |
| 38 | s.Error("Failed to open page: ", err) |
| 39 | } |
| 40 | ``` |
| 41 | |
| 42 | Back in your chroot, run the following: |
| 43 | |
| 44 | ```sh |
| 45 | tast -verbose run <test-device-ip> ui.ChromeSanity |
| 46 | ``` |
| 47 | |
| 48 | (Note how `-build=false` is omitted; as a result, the `tast` command will |
| 49 | rebuild tests locally and push them to the device. You may be prompted to |
| 50 | install some dependencies needed to build tests; if so, run the provided |
| 51 | `emerge` command and then re-run the `tast` command.) |
| 52 | |
| 53 | This time, the updated test should additionally open a Google search page. |
| 54 | |
| 55 | Return to the test file and add the following statement at the end of the |
| 56 | function: |
| 57 | |
| 58 | ```go |
| 59 | s.Error("This is an intentional error") |
| 60 | ``` |
| 61 | |
| 62 | If you build and run the test again, you should see it fail. |
| 63 | |
| 64 | See [Writing Tests] for more information. |
| 65 | |
| 66 | Many resources are available for learning more about Go. Here are a few: |
| 67 | |
| 68 | * [A Tour of Go] - In-browser introduction to Go's core features. |
| 69 | * [Official Go documentation] - Package documentation, specifications, blog |
| 70 | posts, and recorded talks. |
| 71 | * [Community Learn wiki] - Links to external resources. |
| 72 | |
| 73 | [virtual machine]: https://www.chromium.org/chromium-os/how-tos-and-troubleshooting/running-chromeos-image-under-virtual-machines |
| 74 | [Chrome OS chroot]: http://www.chromium.org/chromium-os/quick-start-guide |
| 75 | [Running Tests]: running_tests.md |
| 76 | [Writing Tests]: writing_tests.md |
| 77 | [A Tour of Go]: https://tour.golang.org/ |
| 78 | [Official Go documentation]: https://golang.org/doc/ |
| 79 | [Community Learn wiki]: https://github.com/golang/go/wiki/Learn |