def login(): log.logging(msg='Initialize', level="INFO") driver_path = read_ini(file_path='/data.ini').read_elements_data( node="driver", key="path") driver = webdriver.Chrome(driver_path) driver.maximize_window() driver.get("https://mail.qq.com/") screenshot().save_rt_screenshot(driver=driver, file_name='打开qq邮箱登陆页.png') log_in = loginBusiness(driver) log_in.login_in() yield driver log.logging(msg='End of test! TearDown!', level='INFO') time.sleep(3) driver.close()
def setup_class(self): log.logging(msg='Initialize', level="INFO") self._case_name = " {}case:{}{}".format('<', Testlogin.test_login.__name__, '>') try: driver_path = read_ini(file_path='/data.ini').read_elements_data( node="driver", key="path") self.driver = webdriver.Chrome(driver_path) self.driver.maximize_window() self.driver.get("https://mail.qq.com/") screenshot().save_rt_screenshot(driver=self.driver, file_name='打开qq邮箱登陆页.png') except: log.logging(msg=traceback.format_exc(), level='ERROR')
def __init__(self, driver): self.driver = driver self.rdfile = read_ini(file_path="/data.ini") self.node = "Elements"
data = a.split('->') if data[0] == 'xpath': return self.driver.find_element_by_xpath(data[1]) if data[0] == 'id': pass def find_elements(self, key): a = self.rdfile.read_elements_data(node=self.node,key=key) data = a.split('->') if data[0] == 'xpath': return self.driver.find_elements_by_xpath(data[1]) if data[0] == 'id': pass def switch_to_frame(self, key): #login_frame return self.driver.switch_to.frame(key) def switch_to_parent_frame(self): return self.driver.switch_to.parent_frame() def get_driver(self): return self.driver if __name__ == '__main__': driver_path = read_ini(file_path='/data.ini').read_elements_data(node="Element", key='path') driver = webdriver.Chrome(executable_path=driver_path) driver.get("https://mail.qq.com/") a = find_elements(driver) a.find_element('login_frame')
a = self.fe.find_element('lgoin_verify_frame') self.fe.switch_to_frame(a) self.verify_frame_flag = 1 def get_username_element(self): self.__switch_to_login_frame__() return self.fe.find_element('login_name') def get_pwd_element(self): self.__switch_to_login_frame__() return self.fe.find_element('login_pwd') def get_login_btn_element(self): self.__switch_to_login_frame__() return self.fe.find_element('login_btn') def get_verify_element(self): self.__switch_to_verify_frame__() return self.fe.find_element('login_verify_slideBar') def get_driver(self): return self.fe.get_driver() if __name__ == '__main__': driver_path = read_ini(file_path='/driver.ini', node='driver').read_elements_data('path') driver = webdriver.Chrome(executable_path=driver_path) driver.get("https://mail.qq.com/") a = login(driver=driver)
def get_username(self): return read_ini(file_path="/data.ini").read_elements_data( node="mail_login", key='username')
def get_pwd(self): return read_ini(file_path="/data.ini").read_elements_data( node="mail_login", key='pwd')
log_in.send_username(self._username) log.logging(msg='input password' + case_name, level='INFO') log_in.send_pwd(self._pwd) screenshot().save_rt_screenshot(driver=self.driver, file_name='输入用户名密码.png') log.logging(msg='click login button' + case_name, level='INFO') log_in.click_login_btn() sleep(1) screenshot().save_rt_screenshot(driver=self.driver, file_name='点击登陆进入滑动验证页面.png') result = log_in.slide_verify_btn() screenshot().save_rt_screenshot(driver=self.driver, file_name='登陆成功.png') return result except: log.logging(msg=traceback.format_exc(), level="ERROR") return result if __name__ == '__main__': driver_path = read_ini(file_path='/data.ini').read_elements_data( node="driver", key="path") driver = webdriver.Chrome(executable_path=driver_path) driver.maximize_window() driver.get("https://mail.qq.com/") screenshot().save_rt_screenshot(driver=driver, file_name='打开qq邮箱登陆页.png') log_in = loginBusiness(driver) main_opera = mainBusiness(driver) log_in.login_in() main_opera.qc_empyt_all_deleted_mail(comfirm_flag=False, onebyone_flag=True)