def group_add(self, group_data): try: self.login_page = login_page(group_data) self.driver = self.login_page.login() self.AST = self.login_page.login_pass() if self.AST == "AST": self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.navigation).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.asset_menu).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.group_menu).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.group_button).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.server_group).send_keys( self.server_group_data) self.driver.find_element_by_xpath(self.describe).send_keys( self.describe_data) self.driver.find_element_by_xpath( self.choice_server).send_keys(self.host_name_data) self.driver.find_element_by_xpath(self.server_right).click() self.driver.find_element_by_xpath(self.submit_button).click() else: self.driver.get_screenshot_as_file(screenshot()) print('登录有误!!!') except Exception as e: self.driver.get_screenshot_as_file(screenshot()) print('主机添加页面有误!!!', e)
def computer_update(self, computer_data): try: self.login_page = login_page(computer_data) self.driver = self.login_page.login() self.AST = self.login_page.login_pass() if self.AST == 'AST': self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.navigation).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.asset_menu).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.computer_menu).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.update_button).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.sign).clear() self.driver.find_element_by_xpath(self.sign).send_keys( self.sign_data) self.driver.find_element_by_xpath(self.computer_name).clear() self.driver.find_element_by_xpath( self.computer_name).send_keys(self.computer_name_data) self.driver.find_element_by_xpath(self.address).clear() self.driver.find_element_by_xpath(self.address).send_keys( self.address_data) self.driver.find_element_by_xpath(self.computer_phone).clear() self.driver.find_element_by_xpath( self.computer_phone).send_keys(self.computer_phone_data) self.driver.find_element_by_xpath(self.manager).clear() self.driver.find_element_by_xpath(self.manager).send_keys( self.manager_data) self.driver.find_element_by_xpath(self.phone).clear() self.driver.find_element_by_xpath(self.phone).send_keys( self.phone_data) self.driver.find_element_by_xpath(self.cabinet).clear() self.driver.find_element_by_xpath(self.cabinet).send_keys( self.cabinet_data) self.driver.find_element_by_xpath(self.ip).clear() self.driver.find_element_by_xpath(self.ip).send_keys( self.ip_data) self.driver.find_element_by_xpath(self.bandwidth).clear() self.driver.find_element_by_xpath(self.bandwidth).send_keys( self.bandwidth_data) self.driver.find_element_by_xpath(self.remarks).clear() self.driver.find_element_by_xpath(self.remarks).send_keys( self.remarks_data) self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.submit_button).click() else: self.driver.get_screenshot_as_file(screenshot()) except Exception as e: self.driver.get_screenshot_as_file(screenshot()) self.tearDown() print(e)
def login_user_ps_null_error(self): try: user_ps_null_error = self.driver.find_element_by_xpath( self.AdminSet).text return user_ps_null_error except Exception as e: self.driver.get_screenshot_as_file(screenshot())
def computer_add_error(self): try: self.driver.implicitly_wait(10) add_fail = self.driver.find_element_by_xpath(self.add_fail).text return add_fail except Exception as e: self.driver.get_screenshot_as_file(screenshot()) self.tearDown() print(e)
def login(self): try: self.driver = driver(browser='Chrome') adminset = self.driver.find_element_by_xpath(self.AdminSet).text if adminset == 'AdminSet': self.driver.find_element_by_name(self.username).send_keys( self.username_data) self.driver.find_element_by_name(self.password).send_keys( self.password_data) self.driver.find_element_by_xpath(self.denglu).click() return self.driver else: current_url = self.driver.current_url print('地址可能有误!!!', adminset, self.AdminSet, current_url) self.driver.get_screenshot_as_file(screenshot()) self.driver.quit() except Exception as e: self.driver.get_screenshot_as_file(screenshot())
def pulic_add_pass(self): # 增加成功! try: self.driver.implicitly_wait(10) add_pass = self.driver.find_element_by_xpath(self.add_pass).text return add_pass except Exception as e: self.driver.get_screenshot_as_file(screenshot()) self.tearDown() print(e)
def computer_update_pass(self): try: self.driver.implicitly_wait(10) get_remarks = self.driver.find_element_by_xpath( self.get_remarks).text print('get_remarks', get_remarks) return get_remarks except Exception as e: self.driver.get_screenshot_as_file(screenshot()) self.tearDown() print(e)
def host_update(self, host_data): try: self.login_page = login_page(host_data) self.driver = self.login_page.login() self.AST = self.login_page.login_pass() if self.AST == 'AST': self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.navigation).click() self.driver.find_element_by_xpath(self.asset_menu).click() self.driver.find_element_by_xpath(self.host_menu).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.update_button).click() self.driver.implicitly_wait(10) host_update = self.driver.find_element_by_xpath( self.host_update_news).text assert '修改主机信息' == host_update # self.driver.switch_to.default_content() iframe = self.driver.find_element_by_xpath(self.iframe) self.driver.switch_to.frame(iframe) self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.host_name).clear() self.driver.find_element_by_xpath(self.host_name).send_keys( self.host_name_data) self.driver.find_element_by_xpath(self.ip).clear() self.driver.find_element_by_xpath(self.ip).send_keys( self.ip_data) # Select(self.driver.find_element_by_xpath(self.number).send_keys(self.number_data)) Select(self.driver.find_element_by_xpath( self.computer)).select_by_visible_text(self.computer_data) self.driver.find_element_by_xpath(self.other_ip).clear() self.driver.find_element_by_xpath(self.other_ip).send_keys( self.other_ip_data) self.driver.find_element_by_xpath(self.asset_number).clear() self.driver.find_element_by_xpath(self.asset_number).send_keys( self.asset_number_data) Select(self.driver.find_element_by_xpath( self.device_type)).select_by_visible_text( self.device_type_data) Select(self.driver.find_element_by_xpath( self.device)).select_by_visible_text(self.device_data) self.driver.find_element_by_xpath(self.system).clear() self.driver.find_element_by_xpath(self.system).send_keys( self.system_data) self.driver.find_element_by_xpath(self.equipment).clear() self.driver.find_element_by_xpath(self.equipment).send_keys( self.equipment_data) self.driver.find_element_by_xpath(self.upper_time).clear() self.driver.find_element_by_xpath(self.upper_time).send_keys( self.upper_time_data) self.driver.find_element_by_xpath(self.cpu_type).clear() self.driver.find_element_by_xpath(self.cpu_type).send_keys( self.cpu_type_data) self.driver.find_element_by_xpath(self.cpu_number).clear() self.driver.find_element_by_xpath(self.cpu_number).send_keys( self.cpu_number_data) self.driver.find_element_by_xpath(self.memory).clear() self.driver.find_element_by_xpath(self.memory).send_keys( self.memory_data) self.driver.find_element_by_xpath(self.disk).clear() self.driver.find_element_by_xpath(self.disk).send_keys( self.disk_data) self.driver.find_element_by_xpath(self.sn_number).clear() self.driver.find_element_by_xpath(self.sn_number).send_keys( self.sn_number_data) self.driver.find_element_by_xpath(self.position).clear() self.driver.find_element_by_xpath(self.position).send_keys( self.position_data) self.driver.find_element_by_xpath(self.remarks).clear() self.driver.find_element_by_xpath(self.remarks).send_keys( self.remarks_data) self.driver.implicitly_wait(10) self.driver.find_element_by_xpath( self.preservation_button).click() else: self.driver.get_screenshot_as_file(screenshot()) print('登录有误!!!') except Exception as e: self.driver.get_screenshot_as_file(screenshot()) print('页面元素定位或者测试数据有误!!!', e)
def host_add(self, host_data): try: self.login_page = login_page(host_data) self.driver = self.login_page.login() self.AST = self.login_page.login_pass() if self.AST == 'AST': self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.navigation).click() self.driver.find_element_by_xpath(self.asset_menu).click() self.driver.find_element_by_xpath(self.host_menu).click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.add_button).click() self.driver.implicitly_wait(10) add_host_content = self.driver.find_element_by_xpath( self.add_host_content).text assert '添加主机条目' == add_host_content self.driver.find_element_by_xpath(self.host_name).send_keys( self.host_name_data) self.driver.find_element_by_xpath(self.ip).send_keys( self.ip_data) # Select(self.driver.find_element_by_xpath(self.number).send_keys(self.number_data)) Select(self.driver.find_element_by_xpath( self.computer)).select_by_visible_text(self.computer_data) self.driver.implicitly_wait(10) self.driver.find_element_by_xpath(self.other_ip).send_keys( self.other_ip_data) self.driver.find_element_by_xpath(self.asset_number).send_keys( self.asset_number_data) Select(self.driver.find_element_by_xpath( self.device_type)).select_by_visible_text( self.device_type_data) Select(self.driver.find_element_by_xpath( self.device)).select_by_visible_text(self.device_data) self.driver.find_element_by_xpath(self.system).send_keys( self.system_data) self.driver.find_element_by_xpath(self.equipment).send_keys( self.equipment_data) self.driver.find_element_by_xpath(self.upper_time).send_keys( self.upper_time_data) self.driver.find_element_by_xpath(self.cpu_type).send_keys( self.cpu_type_data) self.driver.find_element_by_xpath(self.cpu_number).send_keys( self.cpu_number_data) self.driver.find_element_by_xpath(self.memory).send_keys( self.memory_data) self.driver.find_element_by_xpath(self.disk).send_keys( self.disk_data) self.driver.find_element_by_xpath(self.sn_number).send_keys( self.sn_number_data) self.driver.find_element_by_xpath(self.position).send_keys( self.position_data) self.driver.find_element_by_xpath(self.remarks).send_keys( self.remarks_data) self.driver.find_element_by_xpath(self.submit_button).click() return self.host_name_data else: self.driver.get_screenshot_as_file(screenshot()) print('登录有误!!!') except Exception as e: self.driver.get_screenshot_as_file(screenshot()) print('主机添加页面有误!!!', e)
def login_pass(self): try: AST = self.driver.find_element_by_xpath(self.AST).text return AST except Exception as e: self.driver.get_screenshot_as_file(screenshot())