class Testlogin(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.basecommon = BaseCommon(self.driver) self.mlogin = Mylogin(self.driver) self.data = Util().operateYaml( "../data/pageData/pageData.yaml") #取到yaml里边的所有数据 self.driver.get(self.data['login']['url']) def tearDown(self): filedir = "D:/test/screenshot/" if not os.path.exists(filedir): os.makedirs(os.path.join('D:/', 'test', 'screenshot')) screen_name = filedir + time.strftime( '%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) + ".png" self.basecommon.screenshot(screen_name) self.driver.quit() def testJenkins01_01(self): time.sleep(2) self.mlogin.login() print "success......." self.taskdata = Util().operateYaml( "../data/pageData/newTaskData.yaml") # 取到yaml里边的所有数据 self.driver.find_element_by_link_text( self.taskdata['newtask']['newtask_01']['task']).click() txt = self.driver.find_element_by_xpath( self.taskdata['newtask']['newtask_01']['taskHo']).text print txt self.assertEqual(txt, self.taskdata['newtask']['assert']['username'])
class TestDeleteItem(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.basecommon = BaseCommon(self.driver) self.mlogin = Mylogin(self.driver) self.data = Util().operateYaml( "../data/jkData/pageData.yaml") # 取到yaml里边的所有数据 self.driver.get(self.data['login']['url']) def tearDown(self): filedir = "D:/test/screenshot/" if not os.path.exists(filedir): os.makedirs(os.path.join('D:/', 'test', 'screenshot')) screen_name = filedir + time.strftime( '%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) + ".png" self.basecommon.screenshot(screen_name) self.driver.quit() def testJenkins01_02(self): time.sleep(2) self.mlogin.login() print "success......." self.taskdata = Util().operateYaml( "../data/jkData/newTaskData.yaml") # 取到yaml里边的所有数据 self.driver.find_element_by_link_text( self.taskdata['newtask']['newtask_01']['tasktitle']).click() self.driver.implicitly_wait(3) self.driver.find_element_by_xpath( self.taskdata['newtask']['newtask_02']['deletebutton']).click() alert1 = self.driver.switch_to.alert alert1.accept()
class Testlogin(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.baidu.com') self.basecommon = BaseCommon(self.driver) def tearDown(self): print time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) filedir = "D:/webtest/screenshot/" if not os.path.exists(filedir): os.makedirs(os.path.join('D:/', 'webtest', 'screenshot')) screen_name = filedir + time.strftime( '%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) + ".png" self.basecommon.screenshot(screen_name) self.driver.quit() def testBaidu01_01(self): self.driver.find_element_by_link_text(u'新闻').click() time.sleep(2) self.basecommon.back() time.sleep(2) self.basecommon.forward() time.sleep(2) print "111111" self.assertEqual("https://www.baidu.com", self.driver.current_url) def testBaidu01_02(self): time.sleep(2) self.basecommon.fresh() ele = self.basecommon.untilTime("ID", 'kw') ele.send_keys("123") print "test结束"