web自動化註冊登入 (7)主類

2021-10-09 17:44:49 字數 2365 閱讀 7671

承接上篇page類的編寫

全部準備好後,執行編寫執行主類,這部分寫的比較粗糙,因為沒打算做太正式的框架,僅僅是用來跑註冊登入的,所以將就看吧!
# _*_conding:utf-8_*_

# 檔案: run

import time

import os

from pages.register import register

from pages.login import login

from scripts.createphone import create

from scripts.mysqlconnect import mysqlhelper

from scripts.excelhelper import init_excel,write

from bases.base_function import basefunction

defrun

(n):

path =

'../'

+time.strftime(

'%y%y%d%h%m%s')if

not os.path.exists(path)

: os.mkdir(path)

excel_path = path +

'/log.xlsx'

inte***ce_path =

'' init_excel(excel_path)

# 建立手機號

phone_list = create(n)

num =

0 row_index =

2# 遍歷**號碼

try:

for phone in phone_list:

base = basefunction(

) num +=

1 result =

# 註冊業務

register(phone,base,path+

'/register.json'

,url)

result[

'phone'

]= phone

regtime = time.strftime(

'%y%y%d-%h:%m:%s'

) result[

'time_stamp']=

str(regtime)

# 註冊後,資料庫是否存在賬號

# 初始化資料庫物件

time.sleep(1)

mydb = mysqlhelper(

) find_result = mydb.get_data(phone)

print

(find_result)

# 資料庫斷言,一般不用這樣,只是我的專案有點特殊

ifnot find_result:

result[

'register_result'

]= f'第次註冊失敗'

elif

len(find_result)

>1:

result[

'register_result'

]= f'第次呼叫了次註冊介面'

else

: res = login(phone,base,path+

'/login.json'

,url)

# 斷言

if res ==

'****'

: result[

'login_result'

]= f'第次登入成功'

else

: result[

'login_result'

]= f'第次登入失敗'

row_index = write(excel_path,result,row_index)

except exception as e:

print

(e)print

(e.__traceback__.tb_frame.f_globals[

"__file__"])

# 發生異常所在的檔案

print

(e.__traceback__.tb_lineno)

# 發生異常所在的行數

finally

: base.driver_close(

)if __name__ ==

'__main__'

:# 可以設定執行次數

run(

1)

結束!!!

web自動化練習 登入

from selenium import webdriver import unittest,time class firecontroltest unittest.testcase def setup self self.driver webdriver.chrome self.driver.ma...

web自動化測試的登入處理

一.復用已有瀏覽器 應用場景 登入頁面需要使用者進行掃碼登入的 1.推出當前所有的谷歌瀏覽器 2.找到chrome的啟動路徑,並配置到環境變數中 3.啟動命令 windows chrome remote debugging port 9222 mac chrome remote debugging ...

自動化測試 web自動化測試

自動化 由機器裝置代替人為完成制定目標的過程 優點 提高工作效率 減少勞動力 產品規格同一標準 批量生產 自動化測試 讓程式代替人為去驗證程式功能的過程,即在預設條件下執行程式系統 流程確定 搭建自動化框架 編寫測試用例,將其轉化為soupui 介面 自動化測試指令碼 執行自動化測試指令碼 輸出執行...