tpshop商城后台登录+修改联系⼈⾃动化测试--代码封装
1. add_cookie({‘name’:’ ‘,‘value’:’ '})
在get登录页⾯后添加cookie,可以get到登录后的页⾯,⽽不需要使⽤⽤户名和密码登录
2. 在系统–》设置–》商城设置–》⽹页信息–》联系⼈
修改联系⼈的名字,点击保存
bage_page1.py
from selenium import webdriver
from time import sleep
class BagePage:
#打开浏览器
def open_browser(self):
self.driver=webdriver.Chrome()
global driver
driver=self.driver
#加载地址
def get(self,url):
(url)
#登录
def login(self):
self.open_browser()
<('shop/index.php/Admin/Admin/login')#登录页⾯
#添加登录后的cookie,F12--》application--》cookies
self.driver.add_cookie({'name':'admin_type','value':'1'})
self.driver.add_cookie({'name':'PHPSESSID','value':'l2kehcdal9bu2bh4cmflhl4153'})
sleep(2)
<('shop/index.php/Admin/Index/index')#登陆之后的页⾯
#定位元素
def locator_element(self,*args):
return self.driver.find_element(*args)
#切换frame
def goto_frame(self,frameName):
self.driver.switch_to.frame(frameName)
封装后的代码
bage_page_test.py
import unittest
from selenium import webdriver
from time import sleep
from selenium.webdrivermon.by import By
from unit_test.bage_page1 import BagePage
class Test_Tpshop(unittest.TestCase):
def test_01_login(self):
BagePage().login()
def test_02_contact(self):
bp=BagePage()
#登录
bp.login()
#点击“系统”
bp.locator_element(By.XPATH,'/html/body/div[1]/div[4]/ul/li[1]/a').click()
# 点击“设置”
bp.locator_element(By.XPATH,'//*[@id="admincpNavTabs_system"]/dl[1]/dt/a/span').click() #点击“商城设置”
bp.locator_element(By.XPATH,'//*[@id="admincpNavTabs_system"]/dl[1]/dd/ul/li[1]/a').click() #切换iframe
<_frame('workspace')
#点击“⽹站信息”
bp.locator_element(By.XPATH,'/html/body/div[3]/div[1]/div/ul/li[1]/a').click() #填写“联系⼈”
selenium获取cookie
bp.locator_element(By.XPATH,'//*[@id="contact"]').send_keys('⼩明')
#点击“确认提交”
bp.locator_element(By.XPATH,'//*[@id="handlepost"]/div/div/a').click()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。