Http://blog.sina.com.cn/s/blog_68f262210102vx8o.html
Seventh test case access to Jenkins automatic operation
------Web Automation testing webdriver+testng--from zero to Proficient (series)
The ultimate goal of automated test cases is unattended automated regression testing, regardless of the language or framework in which the test cases are written, if you want to achieve this, you need to use Jenkins or Hudson. According to the industry's custom, we still use Jenkins. In my various automated test tutorials, has been introduced to the use of Jenkins, there are many corresponding tutorials on the web, not in this statement, we only explain how to testng written test cases into Jenkins.
7.1 Jenkins Configuration
Jenkins provides a very user-friendly configuration, depending on the needs, we can install the appropriate plug-ins, configure different functions to meet our needs.
The recommended six plugins installed in this scenario are "Extended Choice Parameter plugin", "Envinject plugin", "Build User Vars plugin", "Build Name Setter Plugin" , "HTML Publisher Plugin" and "Email-ext Plugin".
The method of installing the plug-in is very simple, follow the following steps:
(1) On the Jenkins page that opens, locate the "Manage Plugins" link, 7.1.1, and click the link.
Figure 7.1.1 find Manage Plugins links
(2) In the open page, find the plugin to add, tick the desired target plug-in, click the corresponding installation button at the bottom of the page. As shown in 7.1.2:
Figure 7.1.2 Tick the desired target plug-in
7.2 Connecting the testng to Jenkins
Through our efforts, we have completed the code coverage of the object being tested, and a single use case and a set of use cases have been debugged. Now we plug in the code into Jenkins and then configure it to perform regression testing as we need it.
(1) Upload the automated test code to SVN or git. To manage the automated test code, upload it to the Code management tool, such as uploading to git:[email protected]: Zhongchou/zcapitest.git.
Install the necessary software such as jdk,testng on the machine where Jenkins is configured.
(2) Open Jenkins and create the job. Open the Jenkins Web site, create a job such as: zhongchou-autotest-onlineenv, and configure the project description, discard the old build and enable project security accordingly, 7.2.1 shows:
Figure 7.2.1 Jenkins description and other configurations
(3) Source control and build triggers. In source control we choose git and fill in the Git address above. And when the trigger is built, we set it to timed execution. For detailed instructions see: http://blog.sina.com.cn/s/blog_68f262210102vmlx.html, specific configuration 7.2.2 shows:
7.2.2 Configuring source code and building triggers
(4) Fill in the Build command. The build command is the command line where we execute the automated test case, and if there is no such command line, Jenkins does not know how to perform the automated test, so the testng command line runs as follows:
Set Classpath=libs\testng.jar;libs\autotests.jar
Java org.testng.testng–testname testng.xml–d test-output\%build_id%
-testname accepts a comma-delimited list of test name, which is executed only by the test specified in the-testname options list in the Suite XML Script runtime.
-d Specifies the path to TestNG default report generation. Because different users may have requests that are executed in parallel, in order to prevent conflicts, each requested report is generated in a directory named after the environment variable build_id, build_id can uniquely indicate a different request.
Fill out the command in the Jenkins Configuration page, build à "Execute shell" à "command" box.
(5) After the script is executed, the resulting test report needs to be archived. This is a new configuration option with the plugin "HTML Publisher Plugin". First select "Publish HTML Reports" in the "Add post-build action", specify the path and file name of the HTML report generated by each request, tick "Keep past HTML reports", so that the history can be quickly Easily query the execution report of past requests in the menu.
Figure 7.2.3 Adding a report item
Figure 7.2.3 Report path and configuration
Figure 7.2.4 Viewing the test report
(6) Failed email notification. If the test case execution fails, we want the email to notify the person concerned, click "Post-Build Action", "e-mail Notification", and then fill in the email address to receive the email after recipients. Also select "Send mail notification for each unstable build".
(7) Save the configuration. When you click Save, the test case is plugged in to Jenkins, and is executed automatically once per hour.
(8) Manual execution. On the Jenkins page, open the job zhongchou-autotest-onlineenv you just created, and click Build now on the left side of the page to execute the automated test case immediately. As shown in 7.2.5:
Figure 7.2.5 Building an automated test case immediately
(9) Review the build results. Click the built task on the left side of the job to view the build, click Console Output on the left side of the open page, and open the console output on the right side to see the results of the test case execution.
The result of our execution is not very good at this point, because the results are not beautified with testng-results.xsl, so at the end of the command line above add: Ant Build.xml. Once saved and run again, you can beautify the report produced by TestNG, forming the report style we showed in the sixth chapter.
7.3 Summary of this chapter
In this chapter we explain how to configure Jenkins to meet the needs of testng, and then step through how to add our webdriver+testng code to Jenkins for automated execution or manual execution. If there is a problem with the test case, an email notification will be sent to the person concerned. We can also use the third-party interface to implement SMS notifications, we have explained in several other automated test cases, and third-party text messaging interface is not every company has, so not too common. In this will not do more introduction, there is a need to refer to my other relevant blog posts.
Jenkins performs automation use cases (verbose, useful, mark priority high)