def login(driver, url, username, password): login_page = LoginPage(driver) login_page.open_url(url) login_page.set_browser_max() login_page.input_username(username) login_page.input_password(password) login_page.click_login()
class LoginAction: def __init__(self, driver): self.login_page = LoginPage(driver) def login_action(self, username, password): self.login_page.input_username(username) self.login_page.input_password(password) self.login_page.click_login() def login_success(self, username, password): self.login_action(username, password) return MainPage(self.login_page.driver) #如果登录成功,跳转到mainpage页面 def login_fail(self, username, password): self.login_action(username, password) return self.login_page.get_login_fail_alert_content() #默认登录成功 def default_login(self): self.login_success(local_config.username, local_config.password) return MainPage(self.login_page.driver) #扩展 def login_by_cookie(self): pass
def __init__(self): login_page = LoginPage() login_page.input_username('test01') login_page.input_password('newdream123') login_page.click_login() self.driver = login_page.driver # 把login_page的对象转移到mainpage self.companyname_showbox = self.driver.find_element(By.XPATH,'//h1[@id="companyname"]') self.myzone_menu = self.driver.find_element(By.XPATH,'//li[@data-id="my"]') self.product_menu = self.driver.find_element(By.XPATH,'//li[@data-id="product"]') self.username_showspan = self.driver.find_element(By.XPATH,'//span[@class="user-name"]')
def __init__(self): login_page = LoginPage() login_page.input_username('admin') login_page.input_password('idontKNOW666') login_page.click_login() self.driver = login_page.dirver #把login_page的对象转移到main_page ,让下面可以使用元素识别 time.sleep(1) self.companyname_showbox = self.driver.find_element( By.XPATH, '//h1[@id="companyname"]') self.myzone_menu = self.driver.find_element(By.XPATH, '//li[@data-id="my"]') self.product_menu = self.driver.find_element( By.XPATH, '//li[@data-id="product"]') self.username_showspan = self.driver.find_element( By.XPATH, '//span[@class="user-name"]')
class LoginAction: def __init__(self, driver): self.login = LoginPage(driver) def login_first(self, username, password): self.login.input_username(username) self.login.input_password(password) self.login.click_login() def login_success(self, username, password): self.login_first(username, password) return MainPage(self.login.driver).get_user_menu() def login_fail(self, username, password): self.login_first(username, password) return self.login.alter_text() def login_success_default(self): self.login_success(local_config.get_username, local_config.get_password) return MainPage(self.login.driver)
#操作 def get_companyname(self): #获取公司名称 value = self.get_text(self.companyname_shwbox) return value def go_myzone(self): #进入我的地盘 self.cilck(self.go_myzone()) def goto_product(self): #进入产品模块 self.cilck(self.go_myzone()) def get_username(self): #获取用户名 value = self.get_text(self.username_showspan) return value if __name__ == '__main__': webdriver_path = os.path.join(os.path.dirname(__file__), '..', 'webdriver', 'chromedriver.exe') driver = webdriver.Chrome(executable_path=webdriver_path) login_page = LoginPage(driver) login_page.open_url( 'http://47.107.178.45/zentao/www/index.php?m=user&f=login') login_page.set_browser_max() login_page.input_username('test01') login_page.input_password('newdream123') login_page.click_login() companyname = MainPage(driver).get_companyname() username = MainPage(driver).get_username() print(companyname) print(username)
def test_login(url, username, password, driver): login = LoginPage(driver) login.input_username(username) login.input_password(password) login.click_login()
def __init__(self, driver): super().__init__(driver) login_page = LoginPage(driver) login_page.open_url( 'http://106.53.50.202:8999/zentao2/www/my-managecontacts.html') login_page.input_username('hanruqing') login_page.input_password('Aa234567') login_page.click_login() # self.calendar_href={'element_name':'日程链接', # 'locator_type':'xpath', # 'locator_value':'//li[@data-id="calendar"]', # 'timeout':5 # } # self.manageContacts_href = {'element_name': '联系人链接', # 'locator_type': 'xpath', # 'locator_value': '//li[@data-id="manageContacts"]', # 'timeout': 5 # } # self.newList_inputbox = {'element_name': '列表名称输入框', # 'locator_type': 'xpath', # 'locator_value': '//input[@id="newList"]', # 'timeout': 5 # } # self.users_chosen_combobox = {'element_name': '用户选择下拉框', # 'locator_type': 'xpath', # 'locator_value': '//div[@id="users_chosen"]', # 'timeout': 5 # } # self.choose_users_box = {'element_name': '选择用户', # 'locator_type': 'xpath', # 'locator_value': '//li[@title="陈江林"]', # 'timeout': 5 # } # self.save_button = {'element_name': '保存列表按钮', # 'locator_type': 'xpath', # 'locator_value': '//button[@id="submit"]', # 'timeout': 5 # } # self.delete_button = {'element_name': '删除列表按钮', # 'locator_type': 'xpath', # 'locator_value': '//a[@class="btn btn-danger btn-wide"]', # 'timeout': 5 # } # self.changepasswd_href={'element_name':'修改密码链接', # 'locator_type':'xpath', # 'locator_value':'//li[@data-id="changePassword"]', # 'timeout':5} # self.originalpasswd_inputbox={'element_name':'原始密码输入框', # 'locator_type':'xpath', # 'locator_value':'//input[@id="originalPassword"]', # 'timeout':5} # self.newpasswd_inputbox1 = {'element_name': '新密码输入框1', # 'locator_type': 'xpath', # 'locator_value': '//input[@id="password1"]', # 'timeout': 5} # self.newpasswd_inputbox2 = {'element_name': '新密码输入框2', # 'locator_type': 'xpath', # 'locator_value': '//input[@id="password2"]', # 'timeout': 5} # self.savepasswd_button = {'element_name': '密码保存按钮', # 'locator_type': 'xpath', # 'locator_value': '//button[@id="submit"]', # 'timeout': 5} elements = ElementdataUtils('myzone_page').get_element_info() # elements=ElementdataUtilsYaml().get_element_info_by_yaml() self.manageContacts_href = elements['manageContacts_href'] self.newList_inputbox = elements['newList_inputbox'] self.users_chosen_combobox = elements['users_chosen_combobox'] self.choose_users_box = elements['choose_users_box'] self.save_button = elements['save_button'] self.changepasswd_href = elements['changepasswd_href'] self.originalpasswd_inputbox = elements['originalpasswd_inputbox'] self.newpasswd_inputbox1 = elements['newpasswd_inputbox1'] self.newpasswd_inputbox2 = elements['newpasswd_inputbox2'] self.savepasswd_button = elements['savepasswd_button']
def login_success(): login_page = LoginPage(set_driver(conf.get_chandao_path)) login_page.input_username(conf.get_username) login_page.input_password(conf.get_password) login_page.click_login()