jpress⾃动化测试脚本记录初始版
Jpress ⼯程⽬录
⼀、⽤户注册
from lenium import webdriver
from lenium.webdriver.support import expectedbraum_conditions as EC
from lenium.webdriver.support.wait import WebDriverWait
from Utils import Utils
from time import sleep
# ⽤户注册
class TestUrRigster(object):
def __init__(lf):
lf.driver = webdriver.Chrome()
lf.driver.get("xxx/jpress/ur/register")
lf.driver.maximize_window()
def urRegister_code_err(lf):
urname = 'test01'
email = 'test@163.com'
pwd = '123456'
confirmPwd = '123456'
captcha = '666'
expected iqs='验证码不正确'
lf.driver.find_element_by_name('urname').nd_keys(urname)
lf.driver.find_element_by_name('email').nd_keys(email)
lf.driver.find_element_by_name('pwd').nd_keys(pwd)
lf.driver.find_element_by_name('confirmPwd').nd_keys(confirmPwd)
lf.driver.find_element_by_name('captcha').nd_keys(captcha)
lf.driver.find_element_by_class_name('btn').click()
WebDriverWait(lf.driver,5).until(EC.alert_is_prent())
alert = lf.driver.switch_to.alert
asrt alert.text == expected
alert.accept()
sleep(5)
def urRegister_code_sucess(lf):
urname = 'test01'
email = 'test@163.com'
pwd = '123456'
confirmPwd = '123456'
captcha = ''
expected = '哈利波特 mp3注册成功,点击确定进⾏登录。 '
lf.driver.find_element_by_name('urname').clear()
lf.driver.find_element_by_name('urname').nd_keys(urname)
lf.driver.find_element_by_name('email').clear()
lf.driver.find_element_by_name('email').nd_keys(email)
lf.driver.find_element_by_name('pwd').clear()
lf.driver.find_element_by_name('pwd').nd_keys(pwd)
lf.driver.find_element_by_name('confirmPwd').clear()
lf.driver.find_element_by_name('confirmPwd').nd_keys(confirmPwd)
captcha = Utils.get_code(lf.driver,'captchaimg')
lf.driver.find_element_by_name('captcha').clear()
lf.driver.find_element_by_name('captcha').nd_keys(captcha)
lf.driver.find_element_by_class_name('btn').click()
WebDriverWait(lf.driver,5).until(EC.alert_is_prent欧美经典爱情电影())
alert = lf.driver.switch_to.alert
asrt alert.text == expected
alert.accept()
sleep(5)
⼆、管理员登录
from lenium import webdriver
from lenium.webdriver.support import expected_conditions as EC
from lenium.webdriver.support.wait import WebDriverWait
from Utils import Utils
from time import sleep
# 管理员登录
class TestAdminLogin(object):
def __init__(lf):
lf.driver = webdriver.Chrome()
lf.driver.get("xxx/jpress/admin/couchsurfinglogin")
lf.driver.maximizetracert_window()
def test_admin_login_err(lf):
urname = 'admin'
pwd = '123456'
captcha = '666'
excepted = 验'证码不正确,请重新输⼊'
lf.driver.find_element_by_name('urname').nd_keys(urname)
lf.driver.find_element_by_如果我在天堂遇见你name('pwd').nd_keys(英文论坛pwd)
lf.driver.find_element_by_name('captcha').nd_keys(captcha)
lf.driver.find_element_by_class_name('btn').click()
WebDriverWait(lf.driver,5).until(EC.alert_is_prent())
alert = lf.driver.switch_to.alert
asrt alert.text == excepted
alert.accept()
sleep(3)
def test_admin_login_success(lf):
urname = 'admin'
pwd = 'admin'
captcha = '666'
excepted = 'JPress后台'
lf.driver.find_element_by_name('urname').clear()
lf.driver.find_element_by_name('urname').nd_keys(urname)
lf.driver.find_element_by_name('pwd').clear()
lf.driver.find_element_by_name东莞商务英语培训('pwd').nd_keys(pwd)
# 登录验证码的识别应该修改为Xpath //*[@id="form"]/div[3]/img
captcha = Utils.get_code(lf.driver, 'captchaimg')
lf.driver.find_element_by_name('captcha').clear()
lf.driver.find_element_by_name('captcha').nd_keys(captcha)
lf.driver.find_element_by_class_name('btn').click()
WebDriverWait(trottlf.driver, 5).until(EC.alert_is_prent())