This article explains how to run MagicPod tests periodically using Jenkins, a CI (continuous integration) tool. As an example, it shows how to set up Jenkins on a Mac PC and run browser tests in the local PC environment.
Setup
-
Install Jenkins (LTS) using Homebrew. Run the following command in Terminal. The Java runtime that Jenkins requires is installed at the same time.
brew install jenkins-lts -
Start Jenkins with the following command.
brew services start jenkins-ltsFor details on installing and starting Jenkins, see macOS Installer for Jenkins LTS on the official Jenkins website.
- Open
http://localhost:8080in your browser, and complete the following three steps by following the post-installation setup wizard on the official Jenkins website.- On the “Unlock Jenkins” screen, enter the administrator password. The password is saved in
~/.jenkins/secrets/initialAdminPassword. - Click “Install suggested plugins” to install the suggested plugins.
- On the “Create First Admin User” screen, create the first administrator user, and click “Save and Finish”.
- On the “Unlock Jenkins” screen, enter the administrator password. The password is saved in
When the screen shown in Figure 1 appears, the setup is complete.
Figure 1. Jenkins dashboard
Create a MagicPod test execution job
Once the setup is complete, it is time to create a job that runs your tests.
Create the job
On the dashboard, click “New Item” and enter any name. Select “Freestyle project” and create the job.
Set up MagicPodDesktop
Place MagicPodDesktop on the same Mac PC as Jenkins, and launch it. On the MagicPod test case editing screen, select the “Local PC” environment and connect to MagicPodDesktop. Once connected, the authentication information is saved on the PC (you do not need to do this again).
After confirming the connection, quit MagicPodDesktop. If you leave it running, the test run will fail.
Edit the configuration file
Edit the configuration file, magic_pod_config.json, required for running the tests by following Run batch tests from the command line (Local PC environment). In addition, add the following two items.
- Set “xmlTestOutput” to
true. The test results will then be output to the working directory as an XML file that Jenkins can read. - For “workDir”, we recommend specifying
<Jenkins workspace>/magic-pod-work(example:/Users/<user name>/.jenkins/workspace/<job name>/magic-pod-work).
Add the build step “Execute shell”
Click “Configure” for the job you created to open the settings screen. Under “Build Steps”, select “Execute shell” from “Add build step” (figure 2).
Figure 2. Adding “Execute shell”
Then, enter a script like the following in the “Command” field (figure 3).
"<path to MagicPodDesktop.app>/Contents/MacOS/MagicPodDesktop" run --magic_pod_config="<path to magic_pod_config.json>"Figure 3. “Command” setting
Add the post-build action “Publish JUnit test result report”
In the same way, under “Post-build Actions”, select “Publish JUnit test result report” from “Add post-build action”. As shown in figure 4, enter <workDir location>/*.xml (example: magic-pod-work/*.xml) in “Test report XMLs” as a path relative to the workspace. If you have never run the tests, a warning that the directory does not exist may appear. Once you run the tests, the XML file is generated and the warning no longer appears.
Figure 4. “Publish JUnit test result report” setting
Run the job
Save the settings, and click “Build Now” to run the job. When the job completes, a “Latest Test Result” link appears on the job screen, where you can check whether each test passed or failed (figure 5).
To see the detailed test results in MagicPod, open the URL shown at the end of the build’s “Console Output” (Test result: https://app.magicpod.com/...).
Figure 5. Link to the test results
Email/chat notification of the test results
You can receive the test results by email, Slack, and so on.
To use MagicPod’s notification feature, see Notification of test results.
To send email notifications from Jenkins, configure the mail server in “E-mail Notification” under “Manage Jenkins” > “System”, following the Mailer plugin documentation. Then, add “E-mail Notification” to the job’s post-build actions. An email will then be sent when a test fails.
To send Slack notifications from Jenkins, configure Slack and Jenkins by following the Slack Notification plugin documentation.
Run the tests periodically
To run the tests periodically, select “Build periodically” under “Triggers” on the job’s settings screen, and enter the timing in “Schedule”. For the syntax, see Jenkins cron syntax on the official Jenkins website.
For example, to run the tests at around noon every day, enter H 12 * * * in “Schedule”. The date and time of the next run are shown below the field.
Further improvements
The settings introduced here are the most basic ones. For full-scale operation, consider the following improvements.
- Assign a fixed IP address to the Jenkins server so that anyone in your company can view it
- Use “Extended E-mail Notification” of the Email Extension plugin to customize when emails are sent, who receives them, and what they say