def test_quit_class(self,CaseId,Module,Title,Precondition,Steps, Data,ExpectedResult,ActualResult,TestResult): Data=replace(Data) logger.info('正在执行{}条用例,测试数据是{}'.format(CaseId,Data)) sleep(2) password=eval(Data)['password'] SubCalss().sub_class('python14期考核',password) if CaseId==1: ele=Login().wait(By.XPATH,"//*[@id='show-tip']") msg=ele.text try: self.assertEqual(ExpectedResult,msg) TestResult='pass' except AssertionError as e: TestResult='failed' raise e else: ele=Login().wait(By.XPATH,"//*[@id='error-tip']") msg=ele.text try: self.assertEqual(ExpectedResult,msg) TestResult='pass' except AssertionError as e: TestResult='failed' raise e Login().driver.save_screenshot('D:\ketangpai\Data\img\sub_class.png') DoExcel(project_path.excel_path).write_Excel('sub',CaseId+1,8,msg) DoExcel(project_path.excel_path).write_Excel('sub',CaseId+1,9,TestResult) logger.info('测试结果是:{}'.format(TestResult))
def sub_class(self, class_name, password): #定位三个点 ele = Login().wait( By.XPATH, "//*[@id='viewer-container-lists']//*[@title='%s']/parent::strong/following-sibling::a" % class_name) ele.click() #选择退课 # Login().wait(By.XPATH,"//*[@data-id='MDAwMDAwMDAwMLOsuZmHz9Fo']//a[text()='退课']").click() ac = ActionChains(Login().driver) ele = Login().wait( By.XPATH, "//*[@id='viewer-container-lists']//*[@title='%s']/parent::strong/following-sibling::ul//*[text()='退课']" % class_name) ac.move_to_element(ele).click(ele).perform() #输入密码 Login().wait(By.XPATH, "//*[@class='deletekccon']//input").send_keys(password) #点击退课 Login().wait(By.XPATH, "//*[@class='deletekt']//*[text()='退课']").click()
def add_calss(self, data): # 点击加入班级 Login().wait( By.XPATH, "//*[text()='加入班级' and contains(@class,'ktcon1l')]").click() # 定位输入框 ele = Login().wait(By.XPATH, "//*[@class='chuangjiankccon']/input") # 输入验证码 ele.send_keys(data) # 点击加入按钮 Login().wait(By.XPATH, "//*[@class='cjli2']/a").click()
def test_add_class(self, CaseId, Module, Title, Precondition, Steps, Data, ExpectedResult, ActualResult, TestResult): Data = replace(Data) ExpectedResult = replace(ExpectedResult) logger.info('正在执行{}条用例,测试数据是{}'.format(CaseId, Data)) #登录用户 Login().register('13541781424', '19931025') #添加班级 AddCalss().add_calss(data=eval(Data)['code']) sleep(2) self.driver.save_screenshot('D:\ketangpai\Data\img\\add_class.png') if CaseId == 1: #获取班级名称 ele = Login().wait( By.XPATH, "//*[@id='viewer-container-lists']//*[@class='jumptoclass']") class_name = ele.get_attribute('title') try: self.assertEqual(ExpectedResult, class_name) TestResult = 'pass' # 进入课堂 Login().wait(By.XPATH, "//a[@title='py14期考核']").click() sleep(2) Login().driver.save_screenshot( 'D:\ketangpai\Data\img\class.png') Login().driver.back() except AssertionError as e: TestResult = 'failed' raise e else: class_name = Login().wait(By.XPATH, "//*[@id='error-tip']").text try: self.assertEqual(ExpectedResult, class_name) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' raise e '''写回测试结果''' DoExcel(project_path.excel_path).write_Excel('add', CaseId + 1, 8, class_name) DoExcel(project_path.excel_path).write_Excel('add', CaseId + 1, 9, TestResult) logger.info('测试结果是:{}'.format(TestResult))
def tearDown(self): Login().driver.quit()
def setUp(self): Login().driver.implicitly_wait(30) Login().register('13541781424','19931025')