AutoMagic-Open Source Automation Platform Construction Ideas

 

 

Recently, I saw that the AutoMagic automation platform is open source on github. When I was itchy, I tried to set up an environment. Now I will tell you the idea.

AutoMagic divides its work into two parts:

 1 : Web management platform

The management platform is developed based on Python Django framework + Mysql. It is mainly used to manage automated test cases, design automated test scenarios, store interface element identifiers, and store them in the database for management through interface entry. It is an automated original management platform purely based on Selenium keywords. .

2: The client executes the script (seleniumkeyword)

The execution effect display of AutoMagic is mainly reflected by it. Its execution depends on the use cases and scene data stored on the web platform. Seleniumkeyword does not need to be deployed on the server side, as long as it can connect to the database on the server side, it can be deployed on any platform. . (Convenient for distributed execution of test cases)

2.1: Client installation and running environment

Server: run in python, mysql-python, django environment

Client: run in python, selenium, mysqldb environment, other dependent packages and plug-ins are installed according to the requirements of the documentation.

2.2: Client Directory Script Description

The TestSuite.py test case execution script engine is that it can implement different execution methods through parameters

-t [taskid] Specifies the AutoMagic task to execute

-u [userid] specifies the user to execute the script

-r [runid] The TestRailRunid to be synchronized by executing the test case script, it will only take effect when the -t parameter is executed.

-c [caseid] specifies the number of a single case to execute

-p [projectid] Specifies the project id to be executed, which will execute all modules in the project and all use cases whose use case status is enabled in turn

-b [browser] Specifies the browser used to execute the use case process, the chrome browser is used by default, and can also be reset through the openbrowser keyword during the execution of the case process

Example :

python TestSuite.py -t 1 -u tsbc  -b chrome

zhufc用户在谷歌浏览器下启动id为1的测试任务

Base.py is our keyword maintenance script. Some methods of python selenium are redefined in class Action , and other parts are custom keywords.

AddCase.py synchronizes the use case to TestRail to the script, and connects to the mysql database on the platform side

-t [taskid] Specifies the AutoMagic task to perform synchronization

-u [userid] specifies the user to execute the script

-s [sctionid] The use case set that executes the synchronization case to TestRail (section_id represents the use case set)

HTMLTestRunner.py script file for generating reports

RestApiUtil.py and RestApiUtil.py are the interfaces for sending packets to MW to simulate security events and send pcap packets

testrail.py TestRail 's interface API

The result directory is the report interface directory

When the upload attachment keyword is executed in the data directory, the attachment storage directory

Directory Structure:

Generate test report effect:

 

 

Two: deployment plan

Scenario 1 Traditional Deployment

1: Server-side deployment

I am in the ubuntu environment. If it is a centos environment, the command needs to be adjusted slightly, and the apt-get command is changed to yum

1.1: Install mysql service

  apt-get install mysql-server

  apt-get isntall mysql-client

   sudo apt-get install libmysqlclient-dev

  netstat -tap | grep mysql to check if the installation was successful

  mysql –uroot –pXXX execute login

1.1: Generate the basic installation package

Create a new python folder in the usr directory:

  cd /usr

  mkdir python

  apt-get update

  apt-get install lrzsz

Execute the rz command and drag the local compressed package to the python folder

Execute python setup.py sdist in the main directory to generate the installation package

  cd dist

  pip install automagic-0.1.tar.gz to execute the installation

1.2: Install django dependencies 

         apt-get install python-dev python basic dependencies

         apt-get install python-pip install pip

         pip install -U setuptools 升级setuptools

         pip install django==1.11.1 install base diango

         pip install MySQL-Python==1.2.3 install mysql-python

    pip install django-users2==0.2.1 dependencies

         pip install django-cors-headers==2.0.2 dependencies

         pip install djangorestframework==3.6.3 dependencies

         pip install python-jenkins==0.4.14 dependencies

1.3: Install the seleniumkeyword dependency package

         pip install selenium dependencies

         pip install requests dependencies

         pip install paramiko==2.1.2 dependencies

         pip install scapy==2.3.3 dependencies

1.4: Exception Handling

If 404 appears during apt-get install, then execute apt-get update for source upgrade

 

If E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? appears in the process, then check the apt-get process and kill them all

  ps -A | grep apt

  sudo kill -9 XXX

The process reports that mysql-config and libmysqlclient.so.18 cannot be located, then configure the soft link

ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config 

ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18

 

1:5: Configure mysql connection

         Cd /usr/python/automagic-dev/automated

    We setting.py

         Modify the database configuration file

Ps: The NAME here is the table name, which needs to exist in the database

1.6: mysql user group ip assignment

         /usr/local/mysql/bin/mysql -uroot -pXXXXX

         grant all privileges  on *.* to root@'%' identified by "XXXXX";

         FLUSH PRIVILEGES;

1.7: Database initialization

         cd automagic-dev

         python manage.py makemigrations

    python manage.py migrate

1.8: Create an administrator

         python manage.py createsuperuser

  Follow the prompts to enter the user name, email, and password to be created (more than 8 characters, a combination of letters, characters, and numbers)

1.9: Start the service

  python manage.py runserver 0.0.0.0:8080

  Virtual machine execution: local host: 8080 access platform

2: PC-side deployment

       2.1: Install python2.7
       2.2: Install setuptooles
       2.3:pip install selenium
       2.4:pip install  MySQL_python‑1.2.5‑cp27‑none‑win_amd64.whl
  2.5:pip install mysql-python
  2.6: Configure mysqldb

Solution 2 Docker environment deployment

I have already containerized the Automagic platform, so I only need to install the docker tool locally to download the image for deployment

1: Install docker under the server

  sudo apt-get update

  sudo apt-get install docker

2: Download the mirror (the mirror is not yet public, and you need to add a group to get it)

  registry.cn-hangzhou.aliyuncs.com/zhufc/automagic:django-automagic

3: Build a container based on an image

  docker run -d --name automagic -p 4406:3306 -p 8080:8080 registry.cn-hangzhou.aliyuncs.com/zhufc/automagic:django-automagic

  3306 database port is mapped to 4406; 8080 container port is mapped to virtual machine 8080 for external access

4: Enter the container

  Docker ps –a View container id

  Docker exec –it d39c6648ebb0 bash goes inside the container

5: Enter the automagic directory to start the automation platform

  Cd /usr/python/automagic-dev

  Python manage.py runserver 0.0.0.0:8080 to start the service

If the port is in use, it means that the service has been started automatically with the container, and you can go directly to the platform to access it with the virtual machine ip.

Execute ctrl+p+q to exit but not stop the container

View virtual machine ipifconfig

6: The page executes localhost:8080 to start the service.

7: Precautions

My docker container has deployed the mysql service and configured it to follow the container to start automatically without restarting mysql.

Three: Basic use of the platform

1: Create a product

2: Click on the product name to create a project

3: Click the project name to create a module

4: Click the associated product under user management to link the product to the user

5: Add keywords under functional testing

The keyword source is under seleniumkeyword and can also be redefined.

 

6: Add use cases, fill in keywords, locate elements or enter text

7: Fill in the positioning method and positioning mark

8: Create a task and check the use case

9: Execute the script command in the seleniumkeyword directory, pay attention to the task number

python TestSuite.py -t 2 -u zhufc -b chrome means to execute task number 2 under Google Chrome

10: View the running results

11: View the details under the use case to see the detailed running process and debug log

12: You can view detailed operation reports and log files in the result directory

Note: Some third-party packages and exception handling will be involved in the deployment process. If you need help, please contact me!

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325166550&siteId=291194637
Recommended