xpath路径:
x_sta_report_ftp_left_ip_ip = "//input[@id='ftp_server"
x_sta_report_ftp_right_ip_ip="']"
x_sta_report_ftp_left_port_ip = "//input[@id='ftp_port"
x_sta_report_ftp_right_port_ip ="']"
x_sta_report_ftp_left_name_ip = "//input[@id='ftp_uname"
x_sta_report_ftp_right_name_ip = "']"
x_sta_report_ftp_left_pass_ip = "//input[@id='ftp_pwd"
x_sta_report_ftp_right_pass_ip = "']"
x_sta_report_ftp_log_any_left_rd = "//input[@id='ftp_anonymous"
x_sta_report_ftp_log_any_right_rd = "' and @value='1']"
x_sta_report_ftp_log_nor_left_rd = "//input[@id='ftp_anonymous"
x_sta_report_ftp_log_nor_right_rd = "' and @value='0']"
x_sta_report_ftp_left_send_rd = "//a[@href='javascript:SendTestMail('ftp"
x_sta_report_ftp_right_send_rd = "');']"
x_sta_report_ftp_apply_bt = "//a/img[@name='Image4' and @alt='Apply']"
脚本:
def __set_ftp_server(self, type='', **kwargs):
# 索引值用来区分主备FTP设置;
index = '' if type == 'primary' else 2
# 获取当前的正常模式是否启用;
ele_normal = self.find_element(
value=(x_sta_report_ftp_log_nor_left_rd + '{}' + x_sta_report_ftp_log_nor_right_rd).format(index))
normal_selected = self.element_is_selected(ele_normal)
# 单独对用户名密码进行设置;
if 'ftp_username' in kwargs.keys() or 'ftp_password' in kwargs.keys():
if not normal_selected:
self.click(
value=(x_sta_report_ftp_log_nor_left_rd + '{}' + x_sta_report_ftp_log_nor_right_rd).format(index))
normal_selected = True
if 'ftp_username' in kwargs.keys():
self.ccs(value=(x_sta_report_ftp_left_name_ip + '{}' + x_sta_report_ftp_right_name_ip).format(index),
keys=kwargs.get('ftp_username'))
kwargs.pop('ftp_username')
if 'ftp_password' in kwargs.keys():
self.ccs(value=(x_sta_report_ftp_left_pass_ip + '{}' + x_sta_report_ftp_right_pass_ip).format(index),
keys=kwargs.get('ftp_password'))
kwargs.pop('ftp_password')
else:
self.click(
value=(x_sta_report_ftp_log_any_left_rd + '{}' + x_sta_report_ftp_log_any_right_rd).format(index))
# 对用户名密码之外的参数进行设置;
for param_key, parm_value in kwargs.items():
param_key = param_key.lower()
if 'ip_addr' == param_key:
self.ccs(value=(x_sta_report_ftp_left_ip_ip + '{}' + x_sta_report_ftp_right_ip_ip).format(index),
keys=parm_value)
if 'port' == param_key:
self.ccs(value=(x_sta_report_ftp_left_port_ip + '{}' + x_sta_report_ftp_right_port_ip).format(index),
keys=parm_value)
if 'test_send' == param_key:
self.click(value=(x_sta_report_ftp_left_send_rd + '{}' + x_sta_report_ftp_right_send_rd).format(index))
def ac_ftp_server_set(self, primary=None, second=None):
"""
通过FTP获取AC相关信息
:param primary: 传入字典,默认为None
:param second: 传入字典,默认为None
primary 和 second的子项完全相同,下面为共同的子项介绍,最终传入的值如
{"ip_addr": "10.1.10.10",
"port": 999,
"ftp_username": "zhangsan",
"ftp_password": "password"}
ip_addr : ftp ip 地址信息
port : ftp 端口信息
ftp_username : normal模式下使用的用户名,给定此参数,会将login模式设置为normal,否则为anonymous
ftp_password :normal模式下使用的密码,给定此参数,会将login模式设置为normal,否则为anonymous
:return:
"""
self.tab_enter('status', 'reporting', 'ftp_settings')
if primary is not None and bool(len(primary)):
self.__set_ftp_server('primary', **primary)
if second is not None and bool(len(second)):
self.__set_ftp_server('second', **second)
self.click(value=x_sta_report_ftp_apply_bt)
if __name__ == '__main__':
logging.basicConfig(level='INFO')
sta = Status()
sta.login(username='admin', password='Accton123', language='English')
primary = {
"ip_addr": "10.1.10.10",
"port": 999,
# "ftp_username": "zhangsan",
# "ftp_password": "password"
}
sencond = {
"ip_addr": "10.1.10.10",
"port": 999,
# "ftp_username": "zhangsan",
# "ftp_password": "password"
}
sta.ac_ftp_server_set(primary=primary, second=sencond)