Jenkins Continuous Integration Project setup and practice-based on Python selenium automated testing (Freestyle style)

Source: Internet
Author: User
Tags python script version control system jenkins ci

About Jenkins

Jenkins is a very popular continuous integration (CI) service written in Java, originating from the Hudson project. So Jenkins and Hudson function similarly.

Jenkins supports various versions of control tools, such as CVS, SVN, Git, Mercurial, perforce, and ClearCase, and can execute projects built with Apache Ant or Java maven. It can also use plug-ins, shell scripts, and Windows batch commands to build projects on other platforms.

In addition to building software functions, Jenkins can also be used to build automated test environments, such as implementing Python selenium tests unattended at scheduled times (such as at night), or automatically running every time code changes are committed to a version control system.

Below, I'll show you how to build Jenkins and create a free-style software project that automates testing at scheduled times (based on Python selenium automated tests) unattended.

Jenkins Environment Preparation  

To be able to successfully execute tests using Jenkins, we need to make some changes. The goal is to perform the tests on a per-plan basis on Jenkins, and then collect the test results and display them on the Jenkins dashboard page. For the sake of practice, I will reuse the Baidu smoke test I created before.

I used the UnitTest Testsuite runner to perform the tests in bulk and output the test results in the format JUnit reports. The xmlrunner Library under Python needs to be used here. Execute the following command to download and install Xmlrunner.

  Pip Install Xmlrunner

The Baidu smoke test script runs tests in homepagetests.py and searchtests.py two scripts through Testsuite runner. Finally with Xmlrunner. XML Testrunner to run smoke tests and generate JUnit test reports. This report is generated in XML format and is saved in the Test-reports subfolder. The code is as follows:

Building Jenkins

  Building Jenkins is simple. Download the Jenkins package for the system platform and install it. Below I will install and start Jenkins and then create a new build job to schedule the above script to run unattended at scheduled times (Baidu smoke test).

1) Download and install the Jenkins CI server. I downloaded the Jenkins Windows installation package and installed Jenkins on the Windows7.

2) Go to the Jenkins dashboard page from the browser (http://localhost:8080 by default).

3) on the Jenkins dashboard page, click the New Item link to create a new Jenkins job, as shown in:

4) in the project name (item name) text box, enter Baidu_smoke_test, and then select the build free-style software project (Freestyle Project) radio button, as shown in:

5) Click the OK button. A new job named after the specified name above is created successfully.

6) in the Build (Bulid) section, click Add Build Step (add build Step), and from the drop-down list, select the Execute Windows batch commands (execute Windows Batch command) option, as shown in:

7) in the command text box, enter the following command, as shown in. This command copies the smoke-tested Python script file to the Jenkins workspace and executes the smoketest.py.

8) The smoketest.py has been configured earlier to generate test results in junit format, and the test results are displayed on the Jenkins dashboard page. To integrate these reports in Jenkins, click Add post-build action, and then choose to publish the JUnit test Results report (Publish JUnit ) option, as shown in:

9) in the post-build operation (post-build aactions) section, add the Test-report/*.xml in the Test report XMLxmls text box as shown in. Every time Jenkins runs the test, it reads the test results from the Test-reports subfolder.

10) in the build Triggers section, select Periodic build (build periodically) as you need to automate testing on a scheduled time, and plan Enter the data as shown in the (Schedule) text box. So, every day 18:24 the build process will automatically trigger, and Jenkins will automatically perform the test as part of the unattended build process, so that you can see the results of the test execution the next morning when you arrive at the office.

11) Click the Save button to save the job configuration, and Jenkins will display the newly created job item page.

12) It is now possible to detect if all configurations are set and whether the tests will be executed successfully. Click the build now link to run the job as shown in:

13) In the Build History section, you can view the running state of the build, as shown in:

14) Click on the project that is running in the build History section to open the page as shown.

15) In addition to the execution status and progress bar on the Jenkins page, you can also view and execute the information by opening the console output link. The "Console output" page with command output information.

16) Once Jenkins finishes the build process, you will see a build page similar to the one shown below.

() Jenkins displays test results and other indicators on the page by reading the test files generated by the UnitTest framework. Click the Test Results link on the build page to view the test results that Jenkins saved.

18) The test results previously configured are generated in the JUnit format. When you click Test Results, Jenkins displays the JUnit test results, as shown in, showing a summary of the test results, where the failed test is highlighted.

19) We can also click the package name link to view detailed result information for each test, as shown in:

Jenkins also displays the final status information for all build jobs on the Dashboard home page in the format shown.

To summarize, run the Python selenium test by building Jenkins to automate the process of building programs and performing tests unattended every night. A simple continuous integration test is implemented.

Jenkins Continuous Integration Project setup and practice-based on Python selenium automated testing (Freestyle style)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.