久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

python+django+selenium搭建簡易自動化測試

瀏覽:7日期:2022-07-13 14:41:12

該平臺會集成UI自動化及api自動化,里面也會涉及到一些簡單的HTML等前端,當然都是很基礎(chǔ)的東西。在以后的博客里,我會一點點的盡量寫詳細,幫助一些測試小白一起成長,當然我也是個小菜雞。

第一章 django 搭建平臺。

1.1搭建環(huán)境

Django 官方網(wǎng)站:https://www.djangoproject.com/

Python 官方倉庫下載地址:https://pypi.python.org/pypi/Django

這里我們通過pip來安裝django ,這里版本用1.10.3。

Python 用3.5.

pip3 install django==1.10.3

我電腦同時安裝了python2 和3.所以這里的是pip3。

python+django+selenium搭建簡易自動化測試

這里提示我已經(jīng)安裝了django。

在D:python3Scripts目錄下會出現(xiàn)一個django-admin.exe 文件。在cmd窗口中進入D:python3Scripts目錄,然后輸入“django-admin”命令回車。

操作步驟如下圖:

python+django+selenium搭建簡易自動化測試

這里是django提供的所有命令。創(chuàng)建項目的方式有很多種,可以通過pycharm來創(chuàng)建。這里我們使用“startproject”命令來創(chuàng)建。

1.2創(chuàng)建testplatform項目。

cmd窗口中,D:python3Scripts目錄下,執(zhí)行 django-admin startproject testplatform

D:python3Scripts>django-admin startproject testplatform

這樣就成功創(chuàng)建了項目。然后我們用pycharm打開這個項目。

項目結(jié)構(gòu)如圖:

python+django+selenium搭建簡易自動化測試

這里對結(jié)構(gòu)簡單進行一下解釋:

testplatform/__init__.py:一個空的文件,用它標識一個目錄為 Python 的標準包。

testplatform/settings.py:Django 項目的配置文件,包括 Django 模塊應(yīng)用配置,數(shù)據(jù)庫配置,模板配置等。

testplatform/urls.py:Django 項目的 URL 聲明。

testplatform/wsgi.py:為 WSGI 兼容的 Web 服務(wù)器服務(wù)項目的切入點。 manage.py:一個命令行工具,可以讓你在使用 Django 項目時以不同的方式進行交互。

1.3創(chuàng)建應(yīng)用

在cmd窗口,進入testplatform項目。我們使用“startapp”命令創(chuàng)建應(yīng)用,一個項目可以包含多個應(yīng)用。

D:python3Scripts>cd testplatformD:python3Scriptstestplatform>python3 manage.py startapp sign

創(chuàng)建“sign”應(yīng)用。結(jié)構(gòu)如下:

python+django+selenium搭建簡易自動化測試

migrations/:用于記錄 models 中數(shù)據(jù)的變更。

admin.py:映射 models 中的數(shù)據(jù)到 Django 自帶的 admin 后臺。

apps.py:在新的 Django 版本中新增,用于應(yīng)用程序的配置。

models.py:創(chuàng)建應(yīng)用程序數(shù)據(jù)表模型(對應(yīng)數(shù)據(jù)庫的相關(guān)操作)。

tests.py:創(chuàng)建 Django 測試。

views.py:控制向前端顯示哪些數(shù)據(jù)。

1.4 運行項目

現(xiàn)在我們要把項目運行起來,Django 提供了 Web 容器,只需要通過“runserver”命令就可以把項目運行 起來。

D:python3Scriptstestplatform>python3 manage.py runserverPerforming 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:55Django 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 默認會通過本機的 8000 端口來啟動項目,如果你的當前環(huán)境該端口號被占用了,也可以在啟動 時指定 IP 地址和端口號。

D:python3Scriptstestplatform>python3 manage.py runserver 127.0.0.1:8001Performing 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:15Django version 1.10.3, using settings ’testplatform.settings’Starting development server at http://127.0.0.1:8001/Quit the server with CTRL-BREAK.

其中“127.0.0.1”為指向本機的 IP 地址,“8001”為設(shè)置的端口號。 打開瀏覽器,訪問:http://127.0.0.1:8001/

python+django+selenium搭建簡易自動化測試

到此這篇關(guān)于python+django+selenium搭建簡易自動化測試 的文章就介紹到這了,更多相關(guān)python django selenium搭建自動化測試 內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 嘉禾县| 长春市| 武城县| 怀化市| 台中市| 时尚| 鄂尔多斯市| 安塞县| 中西区| 石景山区| 绥芬河市| 额济纳旗| 福泉市| 潍坊市| 紫阳县| 富蕴县| 昌宁县| 重庆市| 鄂尔多斯市| 湾仔区| 石河子市| 介休市| 鄂托克前旗| 天门市| 镇巴县| 甘孜县| 靖州| 资阳市| 旺苍县| 吉安市| 民权县| 徐水县| 天津市| 当阳市| 建德市| 巴林左旗| 宜兰市| 胶州市| 富川| 新绛县| 广东省|