欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

淘宝ui界面自动化代码

时间:2023-05-29

#导包from selenium import webdriverimport time#创建浏览器对象# def Enter():driver=webdriver.Chrome()driver.get('https://www.taobao.com/')#窗口最大化def window(): driver.maximize_window()#等待时间def shijian(s): time.sleep(s)if __name__=='__main__': pass

from shizhang.pulic import Enter_Taobao as afrom selenium.webdriver.common.by import Byimport unittesta.window()a.shijian(5)class Test_1(unittest.TestCase): @classmethod def setUpClass(cls): print("steUpClass方法") @classmethod def tearDownClass(cls): print("tearDownClass方法") def setUp(self): pass def test_1(self): a.driver.find_element(By.XPATH,"//*[@id='q']").click() a.driver.find_element(By.XPATH,"//*[@id='q']").send_keys("篮球") a.shijian(3) a.driver.find_element(By.XPATH,"//*[@id='J_TSearchForm']/div[1]/button").click() a.shijian(5) a.driver.find_element(By.XPATH,"//*[@id='J_Itemlist_Tlink_591003904006']").click() a.driver.switch_to.window(a.driver.window_handles[1]) a.shijian(5) a.driver.find_element(By.XPATH,"//*[@id='J_Detailmeta']/div[1]/div[1]/div/div[4]/div/div/dl[1]/dd/ul/li[1]/a/span").click() a.shijian(30) a.driver.find_element(By.XPATH,"//*[@id='J_Detailmeta']/div[1]/div[1]/div/div[4]/div/div/dl[2]/dd/ul/li[1]/a").click() a.driver.find_element(By.XPATH,"//*[@id='J_linkBasket']").click() #点击购物车 a.driver.find_element(By.XPATH,"//*[@id='J_MiniCart']/div[1]/a/span[2]").click() actVaule="witess旗舰店" expectVale=a.driver.find_element(By.XPATH,"//*[@id='J_Order_s_2912764766_1']/div[1]/div/a").text self.assertEqual(actVaule,expectVale,"预期结果不等于实际结果") def test_2(self): a.driver.find_element(By.XPATH, "//*[@id='q']").click() a.driver.find_element(By.XPATH, "//*[@id='q']").send_keys("袜子") a.shijian(3) a.driver.find_element(By.XPATH, "//*[@id='J_TSearchForm']/div[1]/button").click() a.shijian(5) a.driver.find_element(By.XPATH,"//*[@id='J_Itemlist_Tlink_645952688412']").click() a.driver.switch_to.window(a.driver.window_handles[1]) a.driver.find_element(By.XPATH,"//*[@id='J_Detailmeta']/div[1]/div[1]/div/div[4]/div/div/dl[2]/dd/ul/li[1]/a/span").click() a.driver.find_element(By.XPATH,"//*[@id='J_linkBasket']").click() # 点击购物车 a.driver.find_element(By.XPATH, "//*[@id='J_MiniCart']/div[1]/a/span[2]").click() actVale="playboy内衣旗舰店" expectVale=a.driver.find_element(By.XPATH,"//*[@id='J_Order_s_1743582420_1']/div[1]/div/a").text self.assertEqual(actVale,expectVale,"预期结果不等于实际结果") def tearDown(self): passif __name__=="__main__": unittest.main()

import unittestfrom HTMLTestRunner import HTMLTestRunnerimport osimport time#文件路径pathcase=os.path.dirname(__file__)+r"/test_case/"#测试报告路径pathrepor=os.path.dirname(__file__)+r"/test_report/"#报告文件命名filename=time.strftime("%Y-%m-%d-%H-%M-%S")+r".html"filename2=pathrepor+filenamedicover=unittest.defaultTestLoader.discover(pathcase,pattern="test01.py")#执行with open(filename2,"wb") as f: # runner = HTMLTestRunner(f, verbosity=2, title="ces", description=20) runner = HTMLTestRunner(f, verbosity=2, title="ces", description="xx") runner.run(dicover)

 由于界面元素变动无法导出自动化报告,故放上其他项目的报告

 

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。