Driven by someone’s desire to learn automated testing, I wrote this minimalist tutorial. Damn, I’m a JAVA backend developer… This tutorial is based on Windows System Jenkins stand-alone version, test code without version control of the essential compressed version of the tutorial, do not print

Premise: Automated tests performed by Jenkins are commonly referred to in this article as builds, which is a generic term. For this reason, we refer to Jenkins’ automated tests as builds below

Install Jenkins

If Jenkins and its RobotFramework plug-ins already exist, readers will skip them

1. Install the JAVA environment

Baidu…

2. Download the Jenkins

IO/en /download…

As shown, select the Windows version

After decompressing, open the MSI file and install it

Select install to D :\Jenkins and keep clicking Next to automatically install and start Jenkins service.

After finish, the browser will automatically open localhost:8080 and close the page

Jenkins service (huh?? You said you wouldn’t open the service?? Taskbar – Right mouse button – Task Manager – Services)

3. Jenkins port configuration and plug-in update source address

Configure port

D :\Jenkins\ root directory, find the Jenkins. XML file, change 8080 to another port, such as 9000.

The plugin updates the source address

Change this address to download and update plug-ins faster. To install directory d: \ Jenkins \ root directory to find d: \ Jenkins \ Hudson model. UpdateCenter. XML, change https://updates.jenkins.io/update-center.json to https://mi rrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

restartjenkinsservice

In service Management, select Jenkins Service and right-click it and choose Restart

4. Install basic plug-ins and initialize accounts

After the reboot, open your browser to localhost:9000 to access Jenkins and follow the prompts to D:\Jenkins\secrets\initialAdminPassword to view the password

Select the default recommended installation and wait for the installation to complete. If the installation fails, skip the installation until necessary

Set the default administrator account and password. The following uses user root and password 123456 as an example. After saving and finishing, fill in the default URL and save again

Now that initialization is complete, let’s log in

Note: It is possible that after initialization, the page opened is blank instead of the welcome page, as shown below

In this case, restart the system

After login is complete, the following image is shown

5. Install necessary plug-ins

Manage Jenkins-Manage Plugins- optional Plugins for searching install RobotFramework Plugins

Waiting for installation

Check to see if it is installed,Manage Jenkins-Manage Plugins- Installed ‘check to see if it is installed successfully

Install the robotframework environment

If the robotframework already exists, skip it

1. Install python2

To https://www.python.org/downloads/, download the latest version 2 series of the latest version

Select 32 or 64 bits based on the actual situation

Install it on drive D, as you did with Jenkins, and go next

Set installation directories D :\Python27 and D :\Python27\Scripts to environment variables.

Create a CMD window and check whether python -v is installed successfully

2. Installpipandsetuptools

PIP is an important tool for installing python third-party libraries, and SetupTools is a collection of python Distutils enhancements. If do not understand, install is.

Configure the domestic PIP source

PIP some domestic images

  • Ali cloud mirrors.aliyun.com/pypi/simple…
  • Pypi.mirrors.ustc.edu.cn/simple/ China university of science and technology
  • Douban (douban) pypi.douban.com/simple/
  • Tsinghua university pypi.tuna.tsinghua.edu.cn/simple/
  • University of science and technology of China pypi.mirrors.ustc.edu.cn/simple/

** Windows modify source: **

Create a PIP directory in the user directory, such as: C: Users\Administrator\ PIP, and create a new file pip.ini in the PIP folder with the following contents

   [global]
   index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy the code

Install the latest PIP

The PIP command was installed to D :\Python27\Scripts when python2 was installed, but the version is old and we need to upgrade to the latest version

C:\Users\oneisall>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.3)
setuptools (39.0.1)
You are using pip version 9.0.3, however version 19.2.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Copy the code

As prompted, we can upgrade to the latest version 19.2.3 using python -m PIP install –upgrade PIP

C:\Users\oneisall>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
    100% | █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ |1.4MB 541kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-19.2.3
Copy the code

PIP List check again

C:\Users\oneisall>pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 wonNot be maintained after that date. A future version of PIP will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Package Version ---------- ------- PIP 19.2.3 setupTools 39.0.1Copy the code

Install the latest versionsetuptools

Python -m PIP install –upgrade setuptools

C:\Users\oneisall>python -m pip install --upgrade setuptools
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 wonNot be maintained after that date. A future version of PIP will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Collecting setuptools Downloading https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41 . 2.0 py2. Py3 - none - any. WHL (576 KB) | █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ | 583 KB, 90 KB/s Installing collected packages: Setuptools Found Existing installation: SetupTools 39.0.1 Uninstalling SetupTools -39.0.1 Successfully uninstalled setuptools-39.0.1 Successfully installed setuptools-41.2.0Copy the code

3. Install important libraries

The library name Install command
robotframework pip install robotframework
wxPython pip install -U wxPython
robotframework-ride pip install robotframework-ride
selenium2library pip install robotframework-selenium2library
archivelibrary pip install robotframework-archivelibrary
SSHLibrary pip install robotframework-SSHLibrary
ftplibrary pip install robotframework-ftplibrary

4. Run the RIDE

After installation, no icon of the RIDE desktop is generated. You can solve the problem as follows: Failed to create a shortcut for the RIDE desktop

Exe -c “from robotide import main; d:\Python27\pythonw.exe -c “from robotide import main; main()”

After entering the path, click Next and enter the name of the shortcut you want to create, such as RIDE

Change icon: Right-click on the shortcut – Properties – Change icon and select your favorite icon in D:\Python27\Lib\site-packages\robotide\ Widgets

Double-click the icon on the desktop to run RIDE

5.RIDE runs import test cases

This article uses HelloWord to test. If you already have a test case on your computer, skip this section

Create a use case

Create a desktop folder named test and create the __init__. TXT and helloWorld.txt files init

__init__.txtFile, as follows:

*** Settings ***
Library           Selenium2Library
Copy the code

helloworld.txtFile, as follows:

*** Test Cases ***
02
${hi} Set Variable Hello, world!
log    ${hi}
Copy the code

Import and run use cases

As shown, Open RIDE and import the folder in file-open Directory

Select the HelloWorld use case and click Run to test

At this point, the presence of HelloWorld confirms that the use case has been run by RIDE, and the robot command is used to test it

6. Run the test instance on the CLI

Skip this section if the reader knows the relevant command

Create a CMD command line window, use robot -d report_dir target_dir to execute all the use cases of the target_dir folder and output the reports to report_dir folder If the command line executes all use cases in the test folder on the desktop, the report is output to the test_report folder on the desktop:

robot -d C:\Users\oneisall\Desktop\test_report C:\Users\oneisall\Desktop\test
Copy the code

The result is shown below:

7. View the report and specify the report location

As shown, three report files are generated, which can be opened with a text editor and a browser, respectively

  • log.html
  • output.xml
  • report.html

Create Jenkins Test JOB

In fact, the most important part of this chapter has been written, the next chapter is just how to create the commands that were executed in the command line under the robotframework in Jenkins. Personally, I think this chapter is the least challenging part. Just learn the Jenkins build. If you need to know more, you can search related articles for detailed explanation.

This section depends onJenkinsThe installation is correct and the necessary plug-ins are installed. For details, see [Install Necessary Plug-ins](#5. Install necessary plug-ins)

This section depends onrobotCommand to correctly execute the use case on the command line, see [Command Line Execution Test Example](#6. Command line execution test instance) section

1. Create a free-style project

Open the Jenkins home page and create a new free-style project

2. Set parameters

According to the configuration task parameter page,Jenkins configuration can be divided into the following nodes

  • General

  • Source code management

  • Build trigger

  • Build environment

  • build

  • Post build trigger

Analyze the relevant points based on the screenshot

General

As shown above, this is the General node configuration, which can be configured in only two places for the purposes of this tutorial: standalone + no version control + compact

describe

Describe the project, which will be displayed on the home page

Discard old builds

That is, discarding the old build. Obviously, automated tests (commonly known as builds, which is a generic name) are performed each time Jenkins is used. Therefore, we refer to Jenkins’ automated test execution as “build” below. Jenkins will save the results, analysis and other contents of each build, which also occupy the disk capacity of the host. Therefore, we adopt a discard policy, where we set the maximum number of builds that can be kept to 10

Source code management

This option refers to the source of the code that performs the build. Normal development requires code versioning. Because this tutorial is intended to be version-free, select None

Build trigger

So when does the build automatically trigger, this example does nothing, and then you go to Jenkins’ page and trigger it

Build environment

When running the build,Jenkins’ working environment, like some files, or log options, again, search for specific documents, it’s not difficult

build

In general, build builds, which compile a project’s source code into executable binaries or virtual machine executable packages, are also known as packaging

Java projects, for example, program workspace code (code for version control updates) into war or JAR packages using maven or Gradle commands

Since the purpose of this tutorial is only to execute automated test scripts, it refers to executing the robot target_dir command for automated tests in a Robot Framework environment.

Execute Windows Batch Command is used to Execute Windows Batch Command

Similarly, if you’re smart, select Execute Shell on Linux

Fill in the command, copy, according to your actual situation, use the relevant absolute path. Otherwise, the relative path is used to execute relevant commands from Jenkins’ working directory, leading to the failure of building because the file path cannot be found

Post-build operation

Tell Jenkins what to do once the build is done, such as sending email notifications, collecting test results, building other projects, deleting workspaces, etc

Therefore, we select Publish RobotFramework test Results to view the automated test report as an example

Mainly set the location of the report output and the size of the threshold (test case pass rate is related to the final build status)

Click Save to execute the build

3. Perform the build

Go to our configured TestCase project interface and click the Build Now button

Run the build automatically when you click (that is, run test commands to automate tests)

4. View the result

After execution, you can view the details in the build result

Because the output to the report is set, you cannot click the browser button to view it. You need to view it on the desktop

5. Check the report directory

Check the report in the test_Report directory on your desktop

Open the browser to view the test log report

6. Specify the output report directory and browse the report through the browser (production recommendation)

TODO advises readers to research and write when they have time

conclusion

The filtration process involves the use of each tool and the basic barrier-free construction environment.

Considering that this tutorial is aimed at young white learning, the purpose is to give young white feeling of affinity, rather than facing a bunch of tools without any clue where to do things here.

The tutorial is not suitable for production, so I suggest you learn more about Jenkins when setting up the production environment (distributed + multi-branch pipeline + multi-environment + automatic project construction + automated testing).

reference

RobotFramework environment build: https://blog.csdn.net/DaxiaLeeSuper/article/details/77568524

From zero to build Robot Framework + Jenkins continuous integration environment: https://www.jianshu.com/p/ef8d3109ac5f

Robot Framework installation configuration and simple examples: https://www.ibm.com/developerworks/cn/opensource/os-cn-robot-framework/index.html

Replace the PIP source to domestic mirror: https://blog.csdn.net/chenghuikai/article/details/55258957