|
| 1 | +# Selenium Ruby Example |
| 2 | + |
| 3 | +[](https://percy.io/percy/example-percy-ruby-selenium) |
| 4 | + |
| 5 | +Example app showing integration of [Percy](https://percy.io/) visual testing |
| 6 | +into Ruby Selenium tests. |
| 7 | + |
| 8 | +Based on the [TodoMVC](https://github.com/tastejs/todomvc) [VanillaJS](https://github.com/tastejs/todomvc/tree/master/examples/vanillajs) |
| 9 | +app, forked at commit [4e301c7014093505dcf6678c8f97a5e8dee2d250](https://github.com/tastejs/todomvc/tree/4e301c7014093505dcf6678c8f97a5e8dee2d250). |
| 10 | + |
| 11 | +## Selenium Ruby Tutorial |
| 12 | + |
| 13 | +This tutorial assumes that you're already familiar with Ruby & Selenium and focuses on using them |
| 14 | +with Percy. You'll still be able to follow along if you're not familiar with Ruby & Selenium, but |
| 15 | +we won't spend time introducing concepts. |
| 16 | + |
| 17 | +This tutorial also assumes you have Ruby, Node, Make, and git installed. |
| 18 | + |
| 19 | +### Step 1 |
| 20 | + |
| 21 | +Clone the example application and install dependencies: |
| 22 | + |
| 23 | +``` shell |
| 24 | +$ git clone https://github.com/percy/example-percy-ruby-selenium.git |
| 25 | +$ cd example-percy-ruby-selenium |
| 26 | +$ make install |
| 27 | +``` |
| 28 | + |
| 29 | +The example app and it's tests will now be ready to go. You can explore the app by running `make |
| 30 | +serve` and then opening `localhost:8000` in a browser. |
| 31 | + |
| 32 | +### Step 2 |
| 33 | + |
| 34 | +Sign in to Percy and create a new project. You can name the project "todo" if you'd like. After |
| 35 | +you've created the project, you'll be shown a token environment variable. |
| 36 | + |
| 37 | +### Step 3 |
| 38 | + |
| 39 | +In the shell window you're working in, export the token environment variable: |
| 40 | + |
| 41 | +**Unix** |
| 42 | + |
| 43 | +``` shell |
| 44 | +$ export PERCY_TOKEN="<your token here>" |
| 45 | +``` |
| 46 | + |
| 47 | +**Windows** |
| 48 | + |
| 49 | +``` shell |
| 50 | +$ set PERCY_TOKEN="<your token here>" |
| 51 | + |
| 52 | +# PowerShell |
| 53 | +$ $Env:PERCY_TOKEN="<your token here>" |
| 54 | +``` |
| 55 | + |
| 56 | +Note: Usually this would only be set up in your CI environment, but to keep things simple we'll |
| 57 | +configure it in your shell so that Percy is enabled in your local environment. |
| 58 | + |
| 59 | +### Step 4 |
| 60 | + |
| 61 | +Check out a new branch for your work in this tutorial (we'll call this branch |
| 62 | +`tutorial-example`), then run tests & take snapshots: |
| 63 | + |
| 64 | +``` shell |
| 65 | +$ git checkout -b tutorial-example |
| 66 | +$ make test |
| 67 | +``` |
| 68 | + |
| 69 | +This will run the app's Selenium tests, which contain calls to create Percy snapshots. The snapshots |
| 70 | +will then be uploaded to Percy for comparison. Percy will use the Percy token you used in **Step 2** |
| 71 | +to know which organization and project to upload the snapshots to. |
| 72 | + |
| 73 | +You can view the screenshots in Percy now if you want, but there will be no visual comparisons |
| 74 | +yet. You'll see that Percy shows you that these snapshots come from your `tutorial-example` branch. |
| 75 | + |
| 76 | +### Step 5 |
| 77 | + |
| 78 | +Use your text editor to edit `index.html` and introduce some visual changes. For example, you can |
| 79 | +add inline CSS to bold the "Clear completed" button on line 32. After the change, that line looks |
| 80 | +like this: |
| 81 | + |
| 82 | +``` html |
| 83 | +<button class="clear-completed" style="font-weight:bold">Clear completed</button> |
| 84 | +``` |
| 85 | + |
| 86 | +### Step 6 |
| 87 | + |
| 88 | +Commit the change: |
| 89 | + |
| 90 | +``` shell |
| 91 | +$ git commit -am "Emphasize 'Clear completed' button" |
| 92 | +``` |
| 93 | + |
| 94 | +### Step 7 |
| 95 | + |
| 96 | +Run the tests with snapshots again: |
| 97 | + |
| 98 | +``` shell |
| 99 | +$ make test |
| 100 | +``` |
| 101 | + |
| 102 | +This will run the tests again and take new snapshots of our modified application. The new snapshots |
| 103 | +will be uploaded to Percy and compared with the previous snapshots, showing any visual diffs. |
| 104 | + |
| 105 | +At the end of the test run output, you will see logs from Percy confirming that the snapshots were |
| 106 | +successfully uploaded and giving you a direct URL to check out any visual diffs. |
| 107 | + |
| 108 | +### Step 8 |
| 109 | + |
| 110 | +Visit your project in Percy and you'll see a new build with the visual comparisons between the two |
| 111 | +runs. Click anywhere on the Build 2 row. You can see the original snapshots on the left, and the new |
| 112 | +snapshots on the right. |
| 113 | + |
| 114 | +Percy has highlighted what's changed visually in the app! Snapshots with the largest changes are |
| 115 | +shown first You can click on the highlight to reveal the underlying screenshot. |
| 116 | + |
| 117 | +If you scroll down, you'll see that no other test cases were impacted by our changes to the 'Clear |
| 118 | +completed' button. The unchanged snapshots appear grouped together at the bottom of the list. |
| 119 | + |
| 120 | +### Finished! 😀 |
| 121 | + |
| 122 | +From here, you can try making your own changes to the app and tests, if you like. If you do, re-run |
| 123 | +the tests and you'll see any visual changes reflected in Percy. |
0 commit comments