rows = pe.get_all_rows()[1:] for id, row in enumerate(rows): if row[is_executed_col_no].value == 'y': username = row[username_col_no].value password = row[password_col_no].value driver = webdriver.Chrome( executable_path="D:\\soft\\chromedriver_win32\\chromedriver.exe") try: login(driver, username, password) visit_address_page(driver) pe.set_sheet_by_index(1) test_data_result_flag = True for id2, row in enumerate(pe.get_all_rows()[1:]): if row[7].value == 'y': try: add_contact(driver, row[1].value, row[2].value, row[3].value, row[4].value, row[5].value) pe.write_cell_content(id2 + 2, 9, date_time()) assert row[ assert_keyword_col_no].value in driver.page_source pe.write_cell_content(id2 + 2, 10, "pass") except Exception, e: pe.write_cell_content(id2 + 2, 9, date_time()) pe.write_cell_content(id2 + 2, 10, "fail") test_data_result_flag = False else: pe.write_cell_content(id2 + 2, 10, u"忽略") continue if test_data_result_flag == True: pe.set_sheet_by_index(0) pe.write_cell_content(id + 2, test_result_col_no, u"成功") else:
print row[2].value username = row[1].value password = row[2].value driver = driver=webdriver.Firefox(executable_path="c:\\geckodriver") try: result = True login(driver,username,password) visit_address_page(driver) pe.set_sheet_by_index(1) data_rows = pe.get_all_rows() for data_row in data_rows[1:]: if data_row[7].value.lower() == "y": try: print data_row[1].value,data_row[2].value,data_row[3].value,data_row[4].value,data_row[5].value add_contact(driver, name=data_row[1].value, email=data_row[2].value, is_star=data_row[3].value, mobile=data_row[4].value, other_info=data_row[5].value) #data_row[8].value = date_time_chinese() data_row[9].value = u"成功" except Exception,e: #data_row[8].value = date_time_chinese() data_row[9].value = u"失败" print e result = False else: #data_row[8].value = date_time_chinese() data_row[9].value = u"忽略" if result: pe.set_sheet_by_index(0) pe.write_cell_content(id + 2, 6, u"成功") assert data_row[6] in driver.page_source else:
def main(): pe = ParseExcel(test_data_excel_path) pe.setSheetByIndex(0) # 防止默认sheet不是要操作的sheet对象,下同 "获取第一个sheet的所有行" rows = pe.get_all_rows() for index, row in enumerate(rows[1:]): if row[4].value.lower() == "y": username = pe.get_cell_content(index + 2, 2) password = pe.get_cell_content(index + 2, 3) driver = webdriver.Chrome() try: login(driver, username, password) visit_address_page(driver) sheetName = pe.get_cell_content(index + 2, 4) pe.setSheetByName(sheetName) data_row = pe.get_all_rows() for id, row in enumerate(data_row[1:]): whether_execute = pe.get_cell_content(id + 2, 8) # print (whether_execute) if whether_execute.lower() == "y": name = pe.get_cell_content(id + 2, 2) email = pe.get_cell_content(id + 2, 3) is_star = pe.get_cell_content(id + 2, 4) mobile = pe.get_cell_content(id + 2, 5) other_info = pe.get_cell_content(id + 2, 6) assert_word = pe.get_cell_content(id + 2, 7) try: add_contact(driver, name=name, email=email, is_star=True, mobile=mobile, other_info=other_info) except Exception as e: pe.write_cell_content(id + 2, 10, "添加联系人失败", color=colors.RED) else: try: assert pe.get_cell_content( id + 2, 7) in driver.page_source except Exception as e: pe.write_cell_content(id + 2, 10, "断言失败", color=colors.RED) else: pe.write_cell_content(id + 2, 10, "成功", color=colors.GREEN) finally: pe.write_cell_content(id + 2, 9, dateTime()) pe.save_excel_file() else: pe.write_cell_content(id + 2, 9, dateTime()) pe.write_cell_content(id + 2, 10, "忽略") pe.save_excel_file() except Exception as e: print(e) pe.setSheetByName("126账号") pe.write_cell_content(index + 2, 6, "失败", color=colors.RED) else: pe.setSheetByName("126账号") # 之所以要加,是因为操作的sheet不同,否则会加错sheet pe.write_cell_content(index + 2, 6, "成功", color=colors.GREEN) finally: pe.save_excel_file() driver.quit() else: pe.setSheetByName("126账号") # print ("this case is ignored!") # row[5].value="忽略" # 往测试结果中写入 pe.write_cell_content(index + 2, 6, "忽略") # 调用内部写的方法写入结果 pe.save_excel_file() # 写入内容后保存文件
password =row[2].value info('登陆用户名和密码'+str(username)+' '+str(password)) try: login(driver,username,password) pe.write_cell_content_time(id+2,7) pe.write_cell_content(id+2,6,'登陆pass') pe.set_sheet_by_name('联系人') info(pe.get_sheet_name()) rows1 = pe.get_all_rows()[1:] info('当前的所有行'+str(rows1)) for id1,row in enumerate(rows1): if row[4].value == 'y': try: info('输入信息'+str(row[1].value)+str(row[2].value)+str(row[3].value)) add_contact(driver,row[1].value,row[2].value,row[3].value) pe.write_cell_content_time(id1+2,6) pe.write_cell_content(id1+2,7,'pass') except Exception as e: error('执行失败'+str(e)) pe.write_cell_content(id1+2,7,'fail') pe.write_cell_content_time(id1+2,6) else: pe.write_cell_content(id1+2,7,'忽略') pe.write_cell_content_time(id1+2,6) add_out_button(driver) except Exception as a: error('登陆失败'+str(a))