1 from selenium import webdriver 2 import time 3 import unittest 4 5 class OomTest (unittest.TestCase): 6 def setUp(self): #初始化登录 7 self.driver=webdriver.Chrome() 8 self.driver.get('http://10.30.14.5/admin/login#!/default/10/activityadmin/adsite-target/index') 9 self.driver.maximize_window()10 11 self.driver.find_element_by_xpath('//*[@id="email"]').send_keys('songxiaonan@sharkshopping.com')12 self.driver.find_element_by_xpath('//*[@id="password"]').send_keys('Songxiaonan111*')13 self.driver.find_element_by_class_name('login-btn-label').click()14 time.sleep(3)15 16 def tearDown(self): # 测试case执行完毕之后,清理现场17 self.driver.quit()23 24 def test_AddReCi(self): #新增一条广告位数据25 self.driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/ul/li[1]/span').click() # 活动管理26 time.sleep(2)27 self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div[2]/div[6]/ul/li[5]/span').click() # 广告位数据28 time.sleep(2)29 self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div/ul/li[2]/a').click() # 新增30 def test_Add_sp(self): #新增一条商品推荐数据31 self.driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/ul/li[1]/span').click() # 活动管理32 time.sleep(3)33 self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[1]/div[2]/div[4]/ul/li[2]/span').click() # 商品推荐数据34 time.sleep(2)35 self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div/ul/li[2]/a').click() # 新增36 37 38 if __name__=='__main__':39 #unittest.main()40 41 #构建测试集,实例化测试套件,添加测试用例到测试套件中42 suite=unittest.TestSuite()43 suite.addTest(OomTest('test_AddReCi'))44 #suite.addTest(OomTest('test_Add_sp'))45 46 #执行测试用例47 runer=unittest.TextTestRunner()48 runer.run(suite)