from selenium import webdriver from common.login_page import LoginPage from common.read_excel import ExcelUtil import unittest import ddt import os login_url = "http://127.0.0.1:81/zentao/user-login-L3plbnRhby8=.html" # '''测试的数据''' # testdates = [ # {"user": "******", "psw": "123456", "expect": "admin"}, # {"user": "******", "psw": "", "expect": ""}, # {"user": "******", "psw": "123456", "expect": ""}, # ] propath = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # 工程路径 filepath = os.path.join(propath, "common", "datas.xlsx") data = ExcelUtil(filepath) testdates = data.dict_data() print(filepath) print(testdates) # filepath = "D:\\web_d\\common\\datas.xlsx" @ddt.ddt class LoginPageCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Firefox() cls.loginp = LoginPage(cls.driver) cls.driver.get(login_url)
import ddt from time import sleep import xlrd from selenium import webdriver import unittest from pages.login_page import LoginPage from common.read_excel import ExcelUtil path = xlrd.open_workbook( 'D:\\all_test_dir\\my_test_for_web_1\\common\\databases.xls') datas = ExcelUtil(path) testdatas = datas.dict_data() @ddt.ddt class Test_login(unittest.TestCase): def login_case(self, user, password, expect): self.login.send_user(user) self.login.send_password(password) self.login.click_submit() result = self.login.get_user_name() print(result) self.assertTrue(result == expect) @classmethod def setUpClass(cls): cls.driver = webdriver.Firefox() cls.login = LoginPage(cls.driver) def setUp(self): self.driver.get('https://leisongwei.5upm.com/my/')
def setUpClass(cls): if cls.__name__ != 'Base': sheet_name = cls.__name__ cls.data_list = ExcelUtil.excel_to_list(cls, './data/demodata.xls', sheet_name)
def get_case_data(self, case_name): return ExcelUtil.get_test_data(self, self.data_list, case_name)
from selenium import webdriver from page.loginpage import LoginPage import unittest import ddt from common.read_excel import ExcelUtil # d1 = [ # {"usr": "******", "psw": "666666", "except": True}, # {"usr": "******", "psw": "123456", "except": False} # ] file_path = r"D:\autopro\testcase\testdata.xlsx" sheet_name = "Sheet1" data = ExcelUtil(file_path, sheet_name) d1 = data.dict_data() @ddt.ddt class TestLogin(unittest.TestCase): """登录测试用例""" def setUp(self): self.driver = webdriver.Firefox() self.driver.maximize_window() self.stg = LoginPage(self.driver) @ddt.data(*d1) def test_login(self, test_data): """不同条件下的登录""" usr = test_data["usr"] psw = test_data["psw"] exp = test_data["except"]
import unittest from pages.login_page import LoginPage,login_url import ddt from common.read_excel import ExcelUtil import os # testdates = [ # {"user":"******","psw":"1234admin","expect":"admin"}, # {"user":"******","psw":"","expect":""}, # {"user":"******","psw":"1234admin","expect":""}, # ] propath = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) filepath = os.path.join(propath,"common","datas.xlsx") print(filepath) sheetName = "Sheet1" data = ExcelUtil(filepath,sheetName) testdates = data.dict_data() print(testdates) @ddt.ddt class LoginPageCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Firefox() cls.loginp = LoginPage(cls.driver) cls.driver.get(login_url) def setUp(self):
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author: Dang Kai # @Date: 2018-10-30 15:32:12 # @Last Modified time: 2018-11-10 11:20:35 # @E-mail: [email protected] # @Description: import sys import ddt sys.path.append('../') from common import case_init import unittest from config.globalparam import data_path_name, read_excel_sheetname from common.read_excel import ExcelUtil testdata = ExcelUtil(data_path_name, read_excel_sheetname).dict_data() from common.encapsulation import BasePage @ddt.ddt class Page_Login(case_init.Case_Test): # def test_success(self): # '''登陆成功,username名字 password密码''' # @unittest.skip("I don't want to run this case.") def success(self, param): '''登陆成功,username名字 password密码''' print(type(param["Element"])) if param["Action"] == 'send_key': if type(param["Input"]) is float: BasePage.send_key(self, param["Type"], param["Element"],
# -*- coding: utf-8 -*- from selenium import webdriver from common.read_excel import ExcelUtil from page.zentaopage import LoginBug from page.login import Login import os import unittest import ddt #用excle表格传入 propath = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) print(propath) filepath = os.path.join(propath,"common","data_excel.xlsx") print(filepath) data = ExcelUtil(filepath) datadict = data.dict_data() print (datadict) @ddt.ddt class TestE(unittest.TestCase): """登录页面测试案例""" def setUp(self): self.driver = webdriver.Firefox() self.linken = LoginBug(self.driver) self.linken1 = Login(self.driver) self.linken.is_alert() self.driver.delete_all_cookies() self.driver.refresh() def login_case(self,user,pswd,expect): """登录流程""" self.linken.loginpage(user,pswd) result = self.linken1.duanyan() print(result)
#encoding=utf_8 from selenium import webdriver from pages.loginpage import Logini4u from common.read_excel import ExcelUtil import unittest import os import ddt dirpath = os.path.realpath(__file__) curpath = os.path.dirname(dirpath) print(curpath) excelpath = os.path.join(curpath,'testdata.xlsx') print(excelpath) data = ExcelUtil(excelpath,sheetName='Sheet1') testdata = data.dict_data() print(testdata) @ddt.ddt class LoginDdt(unittest.TestCase): def setUp(self): self.driver =webdriver.Firefox() self.driver.get('http://dev.i4u.net.cn/Business/login.html') self.i4u = Logini4u(self.driver) def tearDown(self): self.driver.quit() @ddt.data(*testdata) def test_login(self,data):
from selenium import webdriver import unittest from pages.login_page import LoginPage, login_url from ddt import ddt, data from common.read_excel import ExcelUtil from common.dir_config import test_data_dir # test_data = [{"username": "******", "password": "******", "expected": "admin"}, # {"username": "******", "password": "", "expected": False}, # {"username": "******", "password": "******", "expected": False}, ] filepath = test_data_dir test_data = ExcelUtil(filepath) @ddt class LoginPageCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Chrome() cls.loginpage = LoginPage(cls.driver) cls.driver.get(login_url) def setUp(self): self.loginpage.is_alert_exist() self.driver.delete_all_cookies() # 退出登录 self.driver.refresh() self.driver.get(login_url) def login_case(self, username, password, expected): self.loginpage.input_username(username) self.loginpage.input_password(password) self.loginpage.click_login_button()
else: res["error"] = "" res["msg"] = "" if testdata["checkpoint"] in res["text"]: res["result"] = "pass" print("用例测试结果: %s---->%s" % (test_nub, res["result"])) else: res["result"] = "fail" return res except Exception as msg: res["msg"] = str(msg) return res def wirte_result(result, filename="result.xlsx"): # 返回结果的行数row_nub row_nub = result['rowNum'] # 写入statuscode wt = Write_excel(filename) wt.write(row_nub, 8, result['statuscode']) # 写入返回状态码statuscode,第8列 wt.write(row_nub, 9, result['times']) # 耗时 wt.write(row_nub, 10, result['error']) # 状态码非200时的返回信息 wt.write(row_nub, 12, result['result']) wt.write(row_nub, 13, result['msg']) # 抛异常 if __name__ == "__main__": data = ExcelUtil("debug_api.xlsx").dict_data() print(data[0]) s = requests.session() res = send_requests(s, data[0]) copy_excel("debug_api.xlsx", "result.xlsx") wirte_result(res, filename="result.xlsx")
import time from common.read_excel import ExcelUtil from page.czx_login_page import LoginPage from tomorrow import threads import os from common.read_config import Read_Conf as r_c from page.czx_task_page_demo import Task_Details from common.select_webdriver import Select_Webdriver import unittest, ddt real_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) data_path = os.path.join(os.path.join(real_path, "data"), "czx_user.xls") #获取数据文件路径 data_value = ExcelUtil(data_path, 'user2').dict_data() #由数据文件读取用户信息并转换为字典数据 @ddt.ddt class Test_vm_status(unittest.TestCase): '''批量登录查看vM开机状态''' @threads(30) @ddt.data(*data_value) def test_login(self, data_value): #加载登录时的账号密码数据 #打开浏览器至指定页面 driver = Select_Webdriver("Chrome", "no-head").webdriver_open() driver.get("https://192.168.50.66") #登录操作 Login = LoginPage(driver)
# {"user": "******", "psw": "", "expect": ""}, # {"user": "******", "psw": "123456", "expect": ""} # ] # 将测试数据存放到excel表格,然后定义一个方法将excel数据转换成dict并用list存储返回,然后调用该方法读取并获取测试数据 # 文件路径用参照物读取,以当前脚本为参照物来读取文件excel的路径 curpath = os.path.realpath(__file__) # 获取当前脚本的真实路径 # # 获取当前脚本的上一层路径case casepath = os.path.dirname(os.path.realpath(__file__)) # # 获取case的上一层路径web_auto propath = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # 以web_auto为参照物,获取路径common/data.xlsx,join连接工程路径+common+data.xlsx excelPath = os.path.join(propath, "common", "data.xlsx") print(excelPath) data = ExcelUtil(excelPath) testdata = data.dict_data() print(testdata) @ddt.ddt class LoginPageCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Firefox() cls.loginp = LoginPage(cls.driver) cls.driver.get(login_url) # 预置条件 def setUp(self): self.loginp.is_alert_exist()