论坛环境:http://discuz.e70w.com/
密码:xxxxx
练习:
1、将论坛的登录还有点击模块管理 通过类来进行封装(给实参)
2、将论坛的登录还有点击模块管理 用例封装(给形参)且通过类的传递完成调用
讲解论坛:
1、工作中验证码问题:
(1)工作中发会提供一个万能的验证 (比如:888888,6666666,11111)
(2)直接关闭验证,但是测试完以后还是测试验证
(3)ui自动化有碰到验证码,先手动,给他一个sleep,先跳过去
验证码解决方法:https://www.cnblogs.com/xiaolehua/p/13693695.html
发帖成功案例
案例1:
#注册步骤:
from selenium import webdriver
from time import sleep
driver=webdriver.Chrome()#通过对象谷歌浏览区且输入网址,在用
url=“http://discuz.e70w.com/”
driver.get(url)
driver.find_element_by_xpath(’//*[@id=“lsform”]/div/div/table/tbody/tr[2]/td[4]/a’).click()
driver.find_element_by_name(“Hc8CMB”).send_keys(‘123456’)
driver.find_element_by_id(“X44izK”).send_keys(‘123456789’)
driver.find_element_by_id(“xwh0wQ”).send_keys(‘123456789’)
#driver.find_element_by_id(“m9dDxO”).send_keys(‘468343126@qq.com’)
driver.find_element_by_id(‘registerformsubmit’).click()
登录步骤:
driver.find_element_by_name(‘username’).send_keys(‘123456’)
driver.find_element_by_id(‘ls_password’).send_keys(‘123456789’)
driver.find_element_by_xpath(’//*[@id=“lsform”]/div/div/table/tbody/tr[2]/td[3]tton’).click()
sleep(10)
driver.find_element_by_link_text(‘默认版块’).click()
driver.find_element_by_id(‘newspecial’).click()
driver.find_element_by_id(‘subject’).send_keys(‘测试帖’)
iframe=driver.find_element_by_id(‘e_iframe’) #定位文本框,先进入文本框然后再出去
driver.switch_to.frame(iframe)
driver.find_element_by_xpath(‘ml/body’).send_keys(“这是一首简单的小情歌”) #定位到文本输入区域的元素用body里面的xpath
driver.switch_to.default_content()
sleep(3)
driver.find_element_by_id(‘postsubmit’).click()
=============================================
from selenium import webdriver
from time import sleep
dr=webdriver.Chrome()
url=‘http://discuz.e70w.com/’
dr.get(url)
sleep(2)
dr.find_element_by_xpath(’//[@id=“lsform”]/div/div/table/tbody/tr[2]/td[4]/a’).click() #点击注册按钮
dr.find_element_by_id(“Z8lLIi”).send_keys(“dcs”) #注册框输入’dcs’
dr.find_element_by_id(“wkF7Ze”).send_keys(“123456”) #注册框输入’密码’
sleep(3)
q=dr.find_element_by_id(“chk_Z8lLIi”).text
if q==“该用户名已注册,请更换用户名或登录”:
dr.find_element_by_id(“ls_username”).send_keys(“dcs”) #顶部输入’用户名密码’
dr.find_element_by_name(“password”).send_keys(“123456”)
dr.find_element_by_xpath(’//[@id=“lsform”]/div/div/table/tbody/tr[2]/td[3]/button/em’).click()
# dr.find_element_by_name(“seccodeverify”).send_keys()
sleep(3)
dr.find_element_by_xpath(’//[@id=“category_1”]/table/tbody/tr[1]/td[2]/h2/a’).click() #点击默认板块
dr.find_element_by_xpath(’//[@id=“newspecial”]/img’).click() #点击发帖
dr.find_element_by_id(“subject”).send_keys(“123321”)
sleep(1)
a=dr.find_element_by_id(“e_iframe”)#进入iframe框
dr.switch_to.frame(a)
dr.find_element_by_xpath("/html/body").send_keys(“1234567891011”)#进入ifname框body输入内容
dr.switch_to.default_content()
sleep(3)
dr.find_element_by_xpath(’//*[@id=“postsubmit”]/span’).click()#点击发表帖子
#else:
dr.find_element_by_id(“G10tNe”).send_keys(“123456”) #确认密码
dr.find_element_by_id(“A6Un16”).send_keys(“123456789@qq.com”) #邮箱
dr.find_element_by_name(“seccodeverify”).send_keys() #验证码
sleep(8)
dr.find_element_by_id(“registerformsubmit”).click()
============================================
案例3:
from selenium import webdriver
from time import sleep
dr=webdriver.Chrome()
url=‘http://discuz.e70w.com/’
dr.get(url)
sleep(1)
dr.maximize_window()
sleep(1)
dr.find_element_by_xpath(’//[@id=“lsform”]/div/div/table/tbody/tr[2]/td[4]/a’).click()
b=dr.current_url
dr.find_element_by_id(“Z8lLIi”).send_keys(“dcs1234”)
dr.find_element_by_id(“wkF7Ze”).send_keys(“123456”)
dr.find_element_by_id(‘G9y99d’).send_keys(‘123456’)
dr.find_element_by_id(‘l33gY4’).send_keys(‘1234567896465@qq.com’)
dr.find_element_by_id(“registerformsubmit”).click()
sleep(3)
a = dr.current_url
if a==b:
dr.find_element_by_id(‘ls_username’).send_keys(‘dcs’)
dr.find_element_by_id(‘ls_password’).send_keys(‘123456’)
dr.find_element_by_xpath(’//[@id=“lsform”]/div/div/table/tbody/tr[2]/td[3]tton’).click()
sleep(3)
dr.find_element_by_link_text(‘默认版块’).click()
sleep(3)
js=‘window.scrollTo(0,1000)’
dr.execute_script(js)
sleep(3)
dr.find_element_by_id(‘subject’).send_keys(‘abc’)
sleep(3)
dr.find_element_by_id(‘fastpostmessage’).send_keys(‘abc123456789’)
dr.find_element_by_id(‘fastpostsubmit’).click()
else:
dr.find_element_by_link_text(‘默认版块’).click()
dr.find_element_by_id(‘subject’).send_keys(‘abc’)
sleep(3)
dr.find_element_by_id(‘fastpostmessage’).send_keys(‘abc123456789’)
dr.find_element_by_id(‘fastpostsubmit’).click()
========================================================
案例4:
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import Select
dr=webdriver.Chrome()#通过对象谷歌浏览区且输入网址,在用get方法打开浏览区
url=r"file:///D:/Users/41170/Desktop/table.html"
dr.get(url)
#最大化浏览器
dr.maximize_window()
sleep(1.5)
dr.find_element_by_name(“user”).send_keys(‘dcs003’)
dr.find_element_by_name(“passwd”).send_keys(‘123456’)
dr.find_element_by_name(“conpasswd”).send_keys(‘123456’)
sleep(1)
dr.find_element_by_xpath(’/html/body/form/table/tbody/tr[5]/td[2]/input[1]’).click()
sleep(1)
ckbox=dr.find_elements_by_css_selector(’[type=“checkbox”]’)
for i in ckbox:
i.click()
sleep(2)
s=dr.find_element_by_xpath(’/html/body/form/table/tbody/tr[7]/td[2]/select’)
s.click()
Select(s).select_by_visible_text(‘多测师大学’)
sleep(1)
dr.find_element_by_css_selector(’[value=“提交”]’).click()
================================
from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import Select
dr=webdriver.Chrome()
url=‘file:///D:/Users/Desktop/%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%A4%B9/table.html’
dr.get(url)
sleep(2)
dr.maximize_window()
sleep(3)
dr.find_element_by_css_selector(’[name=“user”]’).send_keys(‘dcs’)
dr.find_element_by_css_selector(’[name=“passwd”]’).send_keys(‘123456’)
dr.find_element_by_css_selector(’[name=“conpasswd”]’).send_keys(‘123456’)
dr.find_element_by_css_selector(’[value=“boy”]’).click()
dr.find_element_by_css_selector(’[value=“html”]’).click()
dr.find_element_by_css_selector(’[value=“python”]’).click()
dr.find_element_by_css_selector(’[value=“linux”]’).click()
dr.find_element_by_css_selector(’[value=“rfs”]’).click()
sleep(3)
s=dr.find_element_by_xpath(‘ml/body/form/table/tbody/tr[7]/td[2]lect’)
Select(s).select_by_visible_text(‘清华大学’)
sleep(3)
dr.find_element_by_css_selector(’[value=“重置”]’).click()