|
| 1 | +### Building a browser-based test automation server with [Jenkins on Azure](https://azuremarketplace.microsoft.com/en-au/marketplace/apps/azure-oss.jenkins) by using [SeleniumBase](https://github.com/seleniumbase/SeleniumBase) |
| 2 | + |
| 3 | + |
| 4 | +### Step 0. Fork the [SeleniumBase](https://github.com/seleniumbase/SeleniumBase) repo on GitHub to get started quickly. |
| 5 | + |
| 6 | +* **(You'll be using your own repository eventually.)** |
| 7 | + |
| 8 | + |
| 9 | +### Step 1. Get Jenkins from the Azure Marketplace |
| 10 | + |
| 11 | +#### Go to [https://azuremarketplace.microsoft.com/en-au/marketplace/apps/azure-oss.jenkins](https://azuremarketplace.microsoft.com/en-au/marketplace/apps/azure-oss.jenkins) to get Jenkins. |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +### Step 2. Launch a Jenkins instance |
| 17 | + |
| 18 | +#### Click "Create" and follow the steps... |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +#### Continue to "Additional Settings" when you're done with "Basic Settings". |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +#### On the "Additional Settings" section, set the Size to "B2s": |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +#### Once you've reached Step 5, click "Create" to complete the setup. |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +### Step 3. Inspect your new Jenkins instance to SSH into the new machine |
| 36 | + |
| 37 | +#### Once your new Jenkins instance has finished launching, you should be able to see the main page: |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +#### On the main page, you should be able to find the Public IP Address. |
| 42 | +* **Use that IP Address to SSH into the machine:** |
| 43 | + |
| 44 | +```bash |
| 45 | +ssh USERNAME@IP_ADDRESS |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +### Step 4. Clone the SeleniumBase repository from the root ("/") directory. |
| 52 | + |
| 53 | +```bash |
| 54 | +cd / |
| 55 | +sudo git clone https://github.com/seleniumbase/SeleniumBase.git |
| 56 | +``` |
| 57 | + |
| 58 | + |
| 59 | +### Step 5. Enter the "linux" folder |
| 60 | + |
| 61 | +```bash |
| 62 | +cd SeleniumBase/integrations/linux/ |
| 63 | +``` |
| 64 | + |
| 65 | +### Step 6. Give the "jenkins" user sudo access (See [jenkins_permissions.sh](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/linux/jenkins_permissions.sh) for details) |
| 66 | + |
| 67 | +```bash |
| 68 | +./jenkins_permissions.sh |
| 69 | +``` |
| 70 | + |
| 71 | +### Step 7. Become the "jenkins" user and enter a "bash" shell |
| 72 | + |
| 73 | +```bash |
| 74 | +sudo su jenkins |
| 75 | +bash |
| 76 | +``` |
| 77 | + |
| 78 | +### Step 8. Install dependencies (See [Linuxfile.sh](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/linux/Linuxfile.sh) for details) |
| 79 | + |
| 80 | +```bash |
| 81 | +./Linuxfile.sh |
| 82 | +``` |
| 83 | + |
| 84 | +### Step 9. Start up the headless browser display mechanism: Xvfb (See [Xvfb_launcher.sh](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/linux/Xvfb_launcher.sh) for details) |
| 85 | + |
| 86 | +```bash |
| 87 | +./Xvfb_launcher.sh |
| 88 | +``` |
| 89 | + |
| 90 | +### Step 10. Go to the SeleniumBase directory |
| 91 | + |
| 92 | +```bash |
| 93 | +cd /SeleniumBase |
| 94 | +``` |
| 95 | + |
| 96 | +### Step 11. Install the [requirements](https://github.com/seleniumbase/SeleniumBase/blob/master/requirements.txt) for SeleniumBase |
| 97 | + |
| 98 | +```bash |
| 99 | +sudo pip install -r requirements.txt --upgrade |
| 100 | +``` |
| 101 | + |
| 102 | +### Step 12. Install SeleniumBase (Make sure you already installed the requirements above) |
| 103 | + |
| 104 | +```bash |
| 105 | +sudo python setup.py develop |
| 106 | +``` |
| 107 | + |
| 108 | +### Step 13. Install chromedriver |
| 109 | + |
| 110 | +```bash |
| 111 | +sudo seleniumbase install chromedriver |
| 112 | +``` |
| 113 | + |
| 114 | +### Step 14. Run an [example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) in Chrome to verify installation (May take up to 10 seconds) |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +```bash |
| 119 | +pytest examples/my_first_test.py --headless --browser=chrome |
| 120 | +``` |
| 121 | + |
| 122 | +### Step 15. Secure your Jenkins machine |
| 123 | + |
| 124 | +#### Navigate to http://JENKINS_IP_ADDRESS/jenkins-on-azure/ |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +#### You'll notice that Jenkins is currently set to use only ``http``, which makes it less secure. |
| 129 | + |
| 130 | +#### You'll need to set up SSH Port Forwarding in order to make it secure. |
| 131 | + |
| 132 | +* **To do this, copy/paste the string and run it in a command prompt, swapping out the username with the one you set up when creating the Jenkins instance in Azure.** |
| 133 | + |
| 134 | + |
| 135 | +### Step 16. Login to Jenkins |
| 136 | + |
| 137 | +#### If you've correctly set up SSH Port Forwarding, the url will be ``http://127.0.0.1:8080/`` |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +#### You'll need to get the password from the SSH terminal on the Linux machine to log in: |
| 142 | + |
| 143 | +```bash |
| 144 | +sudo cat /var/lib/jenkins/secrets/initialAdminPassword |
| 145 | +``` |
| 146 | + |
| 147 | + |
| 148 | +### Step 17. Customize Jenkins |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +### Step 18. Create an Admin user |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +#### Once Jenkins has finished loading, the top left of the page should look like this: |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +### Step 19. Create a new Jenkins job |
| 163 | + |
| 164 | +* **Click on "New Item"** |
| 165 | +* **Give your new Jenkins job a name (ex: "Test1")** |
| 166 | +* **Select "Freestyle project"** |
| 167 | +* **Click "OK"** |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | +### Step 20. Setup your new Jenkins job |
| 173 | + |
| 174 | +* **Under "Source Code Management", select "Git".** |
| 175 | +* **For the "Repository URL", put: ``https://github.com/seleniumbase/SeleniumBase.git``. (You'll eventually be using your own clone of the repository here.)** |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | +* **Under "Build", click the "Add build step" dropdown.** |
| 180 | +* **Select "Execute shell".** |
| 181 | +* **For the "Command", paste:** |
| 182 | +```bash |
| 183 | +pytest examples/my_first_test.py --headless --browser=chrome |
| 184 | +``` |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | +#### Click "Save" when you're done. |
| 189 | + |
| 190 | +* **You'll see the following page after that:** |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | +### Step 21. Run your new Jenkins job |
| 196 | + |
| 197 | +* **Click on "Build Now"** |
| 198 | +* **(If everything was done correctly, you'll see a blue dot appear after a few seconds, indicating that the test job passed.)** |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | +### Step 22. See the top Jenkins page for an overview of all jobs |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | +### Step 23. Future Work |
| 209 | + |
| 210 | +If you have a web application that you want to test, you'll be able to create SeleniumBase tests and add them to Jenkins as you saw here. You may want to create a Deploy job, which downloads the latest version of your repository, and then kicks off all tests to run after that. You could then tell that Deploy job to auto-run whenever a change is pushed to your repository by using: "Poll SCM". All your tests would then be able to run by using: "Build after other projects are built". |
| 211 | + |
| 212 | +#### Congratulations! You're now well on your way to becoming a build & release / automation engineer! |
0 commit comments