Commit b296d423 authored by 17322369953's avatar 17322369953
Browse files

框架,登录案例推送

parent efe92e0d
# author:qinguanglei
# ddate:2023/11/14 16:47
# 购买多个序列号商品
import os
import time
from pip._internal.commands import inspect
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from guke.common.logger import log
from guke.common.read_yaml import get_value_by_filed_from_yaml
def test_buy_nonseq_commodities():
option = webdriver.ChromeOptions()
# option.add_experimental_option("detach", True) # 设置不要自动关闭浏览器
# 获取驱动器
driver = webdriver.Chrome(options=option)
# 最大化页面
driver.maximize_window()
driver.get("http://scdev.cmic.com.cn:8088/beta/")
driver.implicitly_wait(10)
# 获取公共信息,注意公共信息的内容在案例的同级目录下
# 获取本案例的绝对路径,绝对路径的目录就是该案例的同级目录
# 需要知道哪个文件名
direction = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/test_buy/data.yaml')
# 取文件中的user栏位
account = get_value_by_filed_from_yaml(direction, 'account')
# 取文件中的password栏位
password = get_value_by_filed_from_yaml(direction, 'password')
log.info('获取的密码为%s', password)
root_dir = os.path.abspath(os.sep)
print(root_dir)
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# user =
driver.find_element(By.ID, 'input1').clear()
driver.find_element(By.ID, 'input1').send_keys(account)
driver.find_element(By.ID, 'input2').clear()
driver.find_element(By.ID, 'input2').send_keys(password)
driver.find_element(By.ID, 'input2').send_keys(Keys.ENTER)
time.sleep(1)
# author:qinguanglei
# ddate:2023/11/14 16:47
# 购买一个非序列号商品
import allure
import pytest
from test_buy.steps_buy import StepsBuy
@allure.feature('采购模块')
class TestBuyOneNonseqCommodity(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
@allure.story('购买一个非序列号商品')
def test_buy_one_nonseq_commodity(self):
# 载入步骤集合
steps_buy = StepsBuy(self.driver)
# 打开浏览器
steps_buy.open_browser()
# 登录
steps_buy.login()
# 进入普通采购单页面
steps_buy.enter_buy_op_page()
# 进入新建单据界面
steps_buy.enter_new_op_frame()
# 输入供应商
steps_buy.input_supplier()
# author:qinguanglei
# ddate:2023/11/14 16:47
# 购买1个序列号商品
\ No newline at end of file
# author:qinguanglei
# ddate:2023/11/14 16:47
# 购买多个序列号商品
\ No newline at end of file
# author:qinguanglei
# ddate:2023/11/16 11:00
# author:qinguanglei
# ddate:2023/11/16 11:13
from selenium.webdriver.common.by import By
from page_class.base_page import BasePage
class PageLogin(BasePage):
# 收集页面元素信息
# 账号
_account_locator = (By.ID, 'input1')
# 密码
_pass_locator = (By.ID, 'input2')
# 验证码输入
_verify_code_locator = (By.ID, 'photoCode')
# 验证码图片
_verify_image_locator = (By.ID, 'canvas')
# 登录按钮
_login_button_locator = (By.ID, 'loginBtn')
# 输入信息后,登录结果,主要针对错误输入
_login_result_locator = (By.XPATH, '//div[@id="simplealert"]/div[@class = "msg"]')
'''获取账号'''
def get_account(self):
return self.get_element_wait_presence(self._account_locator)
'''获取密码'''
def get_password(self):
return self.get_element_wait_presence(self._pass_locator)
'''获取验证码'''
def get_verify_code(self):
return self.get_element_wait_presence(self._verify_code_locator)
'''获取验证码图片元素'''
def get_verify_image(self):
return self.get_element_wait_presence(self._verify_image_locator)
'''获取登录按钮元素'''
def get_login_button(self):
return self.get_element_wait_presence(self._login_button_locator)
'''输入用户密码验证码后,登录结果提示'''
def get_login_result(self):
return self.get_element_wait_presence(self._login_result_locator)
# author:qinguanglei
# ddate:2023/11/16 16:46
import datetime
import random
import time
import traceback
import allure
from common import constant
from common.logger import log
from common.read_yaml import get_filed_from_yaml
from common.save_screenshot import ScreenShot
from common.verifycode import VerifyCode
from test_login.page_login import PageLogin
module = 'test_login'
class StepsLogin(object):
def __init__(self, driver):
self.page_login = PageLogin(driver)
self.driver = driver
@allure.step("打开浏览器")
def open_browser(self):
try:
log.info('当前url: %s', get_filed_from_yaml(module, "data", "url"))
self.page_login.open_page(get_filed_from_yaml(module, "data", "url"))
except Exception as e:
log.error(f'打开浏览器问题:{e.__doc__}{traceback.format_exc()}')
# 截图
allure.attach.file(source=ScreenShot(self.driver, module, int(time.time())).screen_shot(), name='失败截图',
attachment_type=allure.attachment_type.PNG)
assert False
@allure.step("输入账号密码")
def enter_account_password(self, flag):
try:
# 获取账号输入元素
account_element = self.page_login.get_account()
# 获取密码输入元素
password_element = self.page_login.get_password()
# 获取账号与密码
account = get_filed_from_yaml(module, "data", "account")
password = get_filed_from_yaml(module, "data", "password")
# 输入账号与密码
# flag为0,1,2,0输入账号与密码,1输入账号,2输入密码
# 3账号输入错误,4密码输入错误
if flag == 3:
# 保证账号错误
account = '1' + account
if flag == 4:
# 保证密码错误
password = '1' + password
# 如下两条,前者保证1,只输入账号,后者保证2,只输入密码
if flag == 0 or flag == 1 or flag == 3 or flag == 4:
self.page_login.input_text(account_element, account)
if flag == 0 or flag == 2 or flag == 3 or flag == 4:
self.page_login.input_text(password_element, password)
except Exception as e:
log.error(f'账号密码输入过程出现问题:{e.__doc__}{traceback.format_exc()}')
# 截图
allure.attach.file(source=ScreenShot(self.driver, module, int(time.time())).screen_shot(), name='失败截图',
attachment_type=allure.attachment_type.PNG)
assert False
@allure.step('输入验证码')
def enter_verify_code(self, flag):
try:
# 获取验证码
# 先获取验证码图片元素
verify_code_element = self.page_login.get_verify_image()
# 获取验证码输入元素
verify_input_element = self.page_login.get_verify_code()
# 获取验证码中的文字信息
verify_code_text = VerifyCode(verify_code_element, self.driver).indentify_verify_image()
# 填充验证码文字
# flag为0,输入正确的验证码,为1输入错误的验证码,为2不输入验证码
if flag == 1:
verify_code_text = '4571'
if flag == 1 or flag == 0:
self.page_login.input_text(verify_input_element, verify_code_text)
log.info(f'输入的验证码为:{verify_code_text}')
except Exception as e:
log.error(f'获取验证码问题:{e.__doc__}{traceback.format_exc()}')
# 截图
allure.attach.file(source=ScreenShot(self.driver, module, int(time.time())).screen_shot(), name='失败截图',
attachment_type=allure.attachment_type.PNG)
assert False
@allure.step('点击登录')
def click_login_button(self):
try:
# 获取登录按钮
login_button_element = self.page_login.get_login_button()
# 点击登录
self.page_login.single_click(login_button_element)
except Exception as e:
log.error(f'点击登录动作出现问题:{e.__doc__}{traceback.format_exc()}')
# 截图
allure.attach.file(source=ScreenShot(self.driver, module, int(time.time())).screen_shot(), name='失败截图',
attachment_type=allure.attachment_type.PNG)
assert False
@allure.step('判断是否登录成功')
def judge_result(self):
try:
# 判断登录是否成功,登录成功会切换到另外一个页面,通过页面title来判断是否切换成功
if self.page_login.get_window_title() == constant.LOGIN_SUCCESS:
assert True
else:
log.error('案例执行失败')
log.error(f'self.page_login.get_window_title()={self.page_login.get_window_title()}')
log.error(f'constant.LOGIN_SUCCESS={constant.LOGIN_SUCCESS}')
log.error('self.page_login.get_window_title()与constant.LOGIN_SUCCESS不一致')
assert False
except Exception as e:
log.error(f'判断是否登录成功问题:{e.__doc__}{traceback.format_exc()}')
# 截图
allure.attach.file(source=ScreenShot(self.driver, module, int(time.time())).screen_shot(), name='失败截图',
attachment_type=allure.attachment_type.PNG)
assert False
@allure.step('登录错误结果校验')
def judge_result_error(self, flag):
try:
# 获取登录结果
login_result_element = self.page_login.get_login_result()
# 断言案例是否执行成功
# flag判断
# 登录验证码错误-----对应flag为0
# VERIFY_CODE_ERROR = "验证码错误!!"
# 登录用户名或者密码错误-----对应flag为1
# USER_PASSWORD_ERROR = "用户名或密码错误"
# 登录不输入用户名或者密码-----对应flag为2
# NO_USER_OR_PASSWORD = "不适当的用户名或口令,请重新确认"
# 登录不输入验证码-----对应flag为3
# NO_VERIFY_CODE = "请输入验证码后再登录!!"
# 结果值
result_value = ' '
if flag == 0:
result_value = constant.VERIFY_CODE_ERROR
if flag == 1:
result_value = constant.USER_PASSWORD_ERROR
if flag == 2:
result_value = constant.NO_USER_OR_PASSWORD
if flag == 3:
result_value = constant.NO_VERIFY_CODE
if result_value in self.page_login.get_text(login_result_element):
assert True
else:
log.error('登录错误结果校验,案例执行失败')
log.error(
f'self.page_login.get_text(login_result_element)={self.page_login.get_text(login_result_element)}')
log.error(f'result_value={result_value}')
log.error('self.page_login.get_text(login_result_element)与result_value不一致')
assert False
except Exception as e:
log.error(f'登录错误结果校验问题:{e.__doc__}{traceback.format_exc()}')
# 截图
allure.attach.file(source=ScreenShot(self.driver, module, int(time.time())).screen_shot(), name='失败截图',
attachment_type=allure.attachment_type.PNG)
assert False
# author:qinguanglei
# ddate:2023/11/17 15:54
import allure
import pytest
from test_login.steps_login import StepsLogin
@allure.feature('登录模块')
class TestLoginNoInputUserid(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
@allure.story('不输入用户名登录失败案例-点击登录')
def test_login_no_input_userid(self):
# 载入步骤集合
steps_login = StepsLogin(self.driver)
# 打开浏览器
steps_login.open_browser()
# 输入账号密码,只输入密码
steps_login.enter_account_password(2)
# 输入验证码,输入正确的验证码
steps_login.enter_verify_code(0)
# 点击登录
steps_login.click_login_button()
# 判断结果
steps_login.judge_result_error(2)
# author:qinguanglei
# ddate:2023/11/20 9:56
import allure
import pytest
from test_login.steps_login import StepsLogin
@allure.feature('登录模块')
class TestLoginNoInputVerifycode(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
@allure.story('不输入验证码案例-点击登录')
def test_login_no_input_verifycode(self):
# 载入步骤集合
steps_login = StepsLogin(self.driver)
# 打开浏览器
steps_login.open_browser()
# 输入账号密码,都输入正确的
steps_login.enter_account_password(0)
# 输入验证码,不输入验证码
steps_login.enter_verify_code(2)
# 点击登录
steps_login.click_login_button()
# 判断结果
steps_login.judge_result_error(3)
# author:qinguanglei
# ddate:2023/11/20 9:43
import allure
import pytest
from test_login.page_login import PageLogin
from test_login.steps_login import StepsLogin
@allure.feature('登录模块')
class TestLoginPasswordError(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
# 执行案例前统一获取页面元素操作方法
self.page_login = PageLogin(self.driver)
@allure.story('输入错误密码登录失败案例-点击登录')
def test_login_password_error(self):
# 载入步骤集合
steps_login = StepsLogin(self.driver)
# 打开浏览器
steps_login.open_browser()
# 输入账号密码,密码输入错误
steps_login.enter_account_password(4)
# 输入验证码,输入正确的验证码
steps_login.enter_verify_code(0)
# 点击登录
steps_login.click_login_button()
# 判断结果
steps_login.judge_result_error(1)
# author:qinguanglei
# ddate:2023/11/16 11:18
import pytest
import allure
from test_login.steps_login import StepsLogin
module = 'test_login'
@allure.feature('登录模块')
class TestLoginSuccess(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
@allure.story('登录成功案例-点击登录')
def test_login_success_click(self):
# 载入步骤集合
steps_login = StepsLogin(self.driver)
# 打开浏览器
steps_login.open_browser()
# 输入账号密码,账号与密码都输入
steps_login.enter_account_password(0)
# 输入验证码,正确的验证码
steps_login.enter_verify_code(0)
# 点击登录
steps_login.click_login_button()
# 判断结果
steps_login.judge_result()
# author:qinguanglei
# ddate:2023/11/20 9:23
import allure
import pytest
from test_login.steps_login import StepsLogin
@allure.feature('登录模块')
class TestLoginUseridError(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
@allure.story('登录用户名错误案例-点击登录')
def test_login_userid_error(self):
# 载入步骤集合
steps_login = StepsLogin(self.driver)
# 打开浏览器
steps_login.open_browser()
# 输入账号密码,用户名输入错误
steps_login.enter_account_password(3)
# 输入验证码,输入正确的验证码
steps_login.enter_verify_code(0)
# 点击登录
steps_login.click_login_button()
# 判断结果
steps_login.judge_result_error(1)
# author:qinguanglei
# ddate:2023/11/16 16:40
import allure
import pytest
from test_login.steps_login import StepsLogin
module = 'test_login'
@allure.feature('登录模块')
class TestLoginVerifyCodeError(object):
@pytest.fixture(scope='function', autouse=True)
def housework(self, driver_fixture):
# 驱动器从fixture传来
self.driver = driver_fixture
@allure.story('登录验证码错误案例-点击登录')
def test_login_verify_code_error(self):
# 载入步骤集合
steps_login = StepsLogin(self.driver)
# 打开浏览器
steps_login.open_browser()
# 输入账号密码,都输入正确的
steps_login.enter_account_password(0)
# 输入验证码,错误的验证码
steps_login.enter_verify_code(1)
# 点击登录
steps_login.click_login_button()
# 判断结果
steps_login.judge_result_error(0)
from testcase.test_scene1.scene1_mainflow import *
def test_scene1_mainflow():
def test_scene1_mainflow():
print('\n流程一:采购_采退开始!!!')
step1 = LoginSys()
step2 = PurchaseOrder()
step3 = Instore()
step4 = PurchaseReject()
step5 = Outstore()
step1.loginsys(SIT_URL,usr2,pwd2)#登录系统
step2.data_add_purchase()#填写表单数据
step2.button_click1()#1为保存,否则为提交
step2.switch_loggin(usr1,pwd1)#切换登录
step2.approve_order()#1为审核通过,否则为审核驳回
purchord = step2.return_pchno()#获取采购订单号
step3.switch_loggin(usr4,pwd4)
step3.take_over_goods(purchord)#仓库收货:1为收货单据撤回,2为提交,其余为保存
step1.loginsys(SIT_URL, usr2, pwd2) # 登录系统
step2.data_add_purchase() # 填写表单数据
step2.button_click1() # 1为保存,否则为提交
step2.switch_loggin(usr1, pwd1) # 切换登录
step2.approve_order() # 1为审核通过,否则为审核驳回
purchord = step2.return_pchno() # 获取采购订单号
step3.switch_loggin(usr4, pwd4)
step3.take_over_goods(purchord) # 仓库收货:1为收货单据撤回,2为提交,其余为保存
step3.switch_loggin(usr5, pwd5)
step3.goods_check(purchord)#仓库验收:1为保存,否则为提交
step3.goods_check(purchord) # 仓库验收:1为保存,否则为提交
step3.switch_loggin(usr4, pwd4)
step3.goods_grounding(purchord)#仓库上架:1为保存,否则为提交
step4.switch_loggin(usr2,pwd2)
step4.relate_order(purchord)#创建采退单1为保存,否则为提交
rejpurchord = step4.return_rejpchno()#获取采退单号
step4.switch_loggin(usr1,pwd1)
step4.approve_order(rejpurchord)#审核/驳回采退单:type=1为审核通过,否则为审核驳回
step4.switch_loggin(usr4,pwd4)
step5.deliver_goods(rejpurchord)#仓库发货
step5.picking_goods(rejpurchord)#仓库拣货
step5.switch_loggin(usr5,pwd5)
step5.outbound_review(rejpurchord)#出库复核
step3.goods_grounding(purchord) # 仓库上架:1为保存,否则为提交
step4.switch_loggin(usr2, pwd2)
step4.relate_order(purchord) # 创建采退单1为保存,否则为提交
rejpurchord = step4.return_rejpchno() # 获取采退单号
step4.switch_loggin(usr1, pwd1)
step4.approve_order(rejpurchord) # 审核/驳回采退单:type=1为审核通过,否则为审核驳回
step4.switch_loggin(usr4, pwd4)
step5.deliver_goods(rejpurchord) # 仓库发货
step5.picking_goods(rejpurchord) # 仓库拣货
step5.switch_loggin(usr5, pwd5)
step5.outbound_review(rejpurchord) # 出库复核
print('流程一:采购_采退结束!!!')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment