Python+django+selenium build simple automated test

这篇文章主要介绍了python+django+selenium搭建简易自动化测试,
文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定
的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

The platform will integrate UI automation and api automation, and it will also involve some simple HTML and other front-ends, which of course are very basic things. In future blogs, I will try to write in detail little by little to help some testers grow together. Of course, I am also a little rookie.

The first chapter django build platform.

1.1 Setting up the environment

Django official website: https://www.djangoproject.com

Python official warehouse download address: https://pypi.python.org/pypi/Django

Here we install django through pip, and the version here is 1.10.3.

Python uses 3.5.

pip3 install django==1.10.3

I have both python2 and 3 installed on my computer. So here is pip3.

Insert picture description here
This prompts me to have installed django.

A django-admin.exe file will appear in the D:\python3\Scripts directory. Enter the D:\python3\Scripts directory in the cmd window, and then enter the "django-admin" command and press Enter.

The operation steps are as follows:

Insert picture description here
Here are all the commands provided by django. There are many ways to create a project, which can be created through pycharm. Here we use the "startproject" command to create.

1.2 Create a testplatform project.

In the cmd window, under the D:\python3\Scripts directory, execute django-admin startproject testplatform

D:\python3\Scripts>django-admin startproject testplatform

This successfully created the project. Then we use pycharm to open the project.

The project structure is shown in the figure:

Insert picture description here
Here is a brief explanation of the structure:

testplatform / the init .py: an empty file, which identifies a directory using the standard package for Python.

testplatform/settings.py: Django project configuration file, including Django module application configuration, database configuration, template configuration, etc.

testplatform/urls.py: The URL declaration of the Django project.

testplatform/wsgi.py: The entry point for a WSGI compatible Web server service project. manage.py: A command line tool that allows you to interact in different ways when using Django projects.

1.3 Create an application

In the cmd window, enter the testplatform project. We use the "startapp" command to create an application, a project can contain multiple applications.

D:\python3\Scripts>cd testplatform
 
D:\python3\Scripts\testplatform>python3 manage.py startapp sign

Create the "sign" app. The structure is as follows:

Insert picture description here
migrations/: used to record data changes in models.

admin.py: Map the data in models to the admin background that comes with Django.

apps.py: Added in the new Django version for application configuration.

models.py: Create application data table model (corresponding to database related operations).

tests.py: Create Django tests.

views.py: Control which data is displayed to the front end.

1.4 Run the project

Now we need to run the project. Django provides a web container. You only need to run the project through the "runserver" command.

D:\python3\Scripts\testplatform>python3 manage.py runserver
Performing system checks...
 
System check identified no issues (0 silenced).
 
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 10, 2019 - 21:45:55
Django version 1.10.3, using settings 'testplatform.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Django will start the project through port 8000 of the machine by default. If the port number is occupied in your current environment, you can also specify the IP address and port number when starting.

D:\python3\Scripts\testplatform>python3 manage.py runserver 127.0.0.1:8001
Performing system checks...
 
System check identified no issues (0 silenced).
 
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 10, 2019 - 21:49:15
Django version 1.10.3, using settings 'testplatform.settings'
Starting development server at http://127.0.0.1:8001/
Quit the server with CTRL-BREAK.

Among them, "127.0.0.1" is the IP address pointing to this machine, and "8001" is the port number set. Open the browser and visit: http://127.0.0.1:8001 /

Insert picture description here
So far, this article on python+django+selenium building simple automated testing is introduced. For more related python django selenium building automated testing content, please search for the previous articles of the server home or continue to browse the related articles below. Hope you all A lot of support for server home!

If you want to learn Python automation or are learning Python automation, there are a lot of Python automation tutorials, but are they the latest? Maybe you learned what others learned a year ago. Share the latest Python tutorials in 2020. Three people must have my teacher! Our resource technology exchange group 313782132 .

Software testing is the easiest subject in IT-related industries to get started~ It does not require the logical thinking of developers, and operations and maintenance personnel are not required to be on call 24 hours a day. What is needed is a careful attitude and a broad understanding of IT-related knowledge. The growth path of each tester from entering the industry to becoming a professional expert can be divided into three stages: software testing, automated testing, and test development engineers.

Guess you like

Origin blog.csdn.net/weixin_50271247/article/details/109391761