def __init__(self): self.login_page = LoginPage() self.login_page.input_username('test01') self.login_page.input_password('newdream123') self.login_page.click_login() self.companyname_showbox = self.login_page.driver.find_element( By.XPATH, '//h1[@id="companyname"]') self.myzone_menu = self.login_page.driver.find_element( By.XPATH, '//li[@data-id="my"]') self.product_menu = self.login_page.driver.find_element( By.XPATH, '//li[@data-id="product"]') self.username_showspan = self.login_page.driver.find_element( By.XPATH, '//span[@class="user-name"]')
class login(object): def __init__(self): self.driver = Config().driver def login_success(self): self.login_page = LoginPage(self.driver) self.login_page.open_url(Config().url) self.login_page.input_username(Config().username) self.login_page.input_password(Config().password) self.login_page.click_login()
class LoginAction: """ 功能层,实现登录成功、登录失败、默认登录流程 :param 传入浏览器驱动,用户名,密码 """ 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) def default_login(self): self.login_success(username=config.user_name, password=config.pass_word) def login_fail(self, username, password): self.login_action(username, password) value = self.login_page.get_login_fail_alert(type='yes', selector='alert') return value def login_by_cookie(self): pass
class LoginAction: def __init__(self, driver): self.login_page = LoginPage(driver) self.main_page = MainPage(driver) def login_action(self, username, password, url=config.zantao_url): 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) # 登录失败 def login_fail(self, username, password): self.login_action(username, password) return self.login_page.switch_to_alert() # 默认登录 def default_login(self): self.login_success(config.user_name, config.password) # 通过cookie登录 def login_by_cookie(self): pass
class MainPage: def __init__(self): self.login_page = LoginPage() self.login_page.input_username('test01') self.login_page.input_password('newdream123') self.login_page.click_login() self.companyname_showbox = self.login_page.driver.find_element( By.XPATH, '//h1[@id="companyname"]') self.myzone_menu = self.login_page.driver.find_element( By.XPATH, '//li[@data-id="my"]') self.product_menu = self.login_page.driver.find_element( By.XPATH, '//li[@data-id="product"]') self.username_showspan = self.login_page.driver.find_element( By.XPATH, '//span[@class="user-name"]') def get_companyname(self): #获取公司名称 value = self.companyname_showbox.get_attribute('title') logger.info('获取公司名称:' + value) return value def goto_myzone(self): #进入我的地盘菜单 self.myzone_menu.click() logger.info('进入我的地盘菜单') def goto_product(self): #进入产品菜单 self.product_menu.click() logger.info('进入产品页面菜单') def get_username(self): #获取用户名 value = self.username_showspan.text logger.info('获取登录用户名:' + value) return value
def __init__(self, driver): # elements = ElementdataUtils('main_page').get_element_info() 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"]')
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) def default_login(self): return self.login_success(config.get_user_name, config.get_password) def login_fail(self, username, password): self.login_action(username, password) return self.login_page.get_login_fail_alert_content()
# driver = webdriver.Chrome() # driver.maximize_window() # driver.get(config.get_url) # test=Test(driver) # test.login(driver) driver=set_driver() base_page = BasePage(driver) driver.maximize_window() driver.get(config.get_url) # driver.find_element(By.XPATH, '//input[@name="account"]').send_keys("admin") # driver.find_element(By.XPATH, "//input[@class='form-control'][@name='password']").send_keys("201314ANQIER2") # driver.find_element(By.XPATH, "//button[@type='submit'][@class='btn btn-primary']").click() login = LoginPage(driver) login.input_username("admin") # login.ctrl_a(login.username_inputbox) # time.sleep(2) # login.ctrl_x(login.username_inputbox) # time.sleep(2) # login.ctrl_v(login.username_inputbox) # login.back_space(login.username_inputbox) ##删除 # login.clear_input(login.username_inputbox) #清空 login.input_password('201314ANQIER1') login.enter(login.login_button) ##回车登录 time.sleep(2) driver.find_element(By.XPATH,"//div[@class='input-group-btn']").click() # 识别OK time.sleep(1) # driver.find_element(By.XPATH,'//a[@data-value="project"]').click()
def __init__(self, driver): self.login_page = LoginPage(driver)
def goto_project(self): # 进入项目菜单 self.click(self.project_menu) self.wait(1) def goto_organization(self): self.click(self.organization_menu) self.wait(1) def get_username(self): # return self.get_text(self.username_showspan) if __name__ == "__main__": driver = Browser().get_driver() # 登录 login_page = LoginPage(driver) login_page.open_url('http://127.0.0.1/zentao/user-login.html') login_page.set_browser_max() login_page.input_username('admin') login_page.input_password('admin123456') login_page.click_login() login_page.wait(2) # 主页操作 main_page = MainPage(login_page.driver) text = main_page.get_username() print(text) # main_page.goto_myzone() # main_page.goto_product() # main_page.goto_project() # main_page.goto_organization()
def quit(self): self.main_page.click_username() self.main_page.click_quit_button() return LoginPage( self.main_page.driver )
def quit(self): self.main_page.click_username() print("点击用户名成功") self.main_page.click_quit_button() print("点击退出按钮成功") return LoginPage( self.main_page.driver )
def quit_action(self): self.main_page.logout() return LoginPage(self.main_page.driver)
import time from common.chrome_driver import chromedriver from selenium.webdriver.common.by import By from element_infos.login.login_page import LoginPage driver = chromedriver.get_driver loginPage = LoginPage(driver) loginPage.open_url( 'http://106.53.50.202:8999/zentao2/www/user-login-L3plbnRhbzYvd3d3Lw==.html' ) loginPage.input_username('chenjuan') loginPage.input_password('1q2w3e4r,') loginPage.click_login() time.sleep(1) driver.find_element(By.XPATH, '//li[@data-id="project"]').click() driver.find_element(By.XPATH, '//li[@data-id="team"]').click() driver.find_element(By.XPATH, '//button[@id="currentItem"]').click() driver.find_element(By.XPATH, '//a[@title="公共研发组sprint1"]').click() # driver.find_element(By.XPATH, '//div[@class="btn-toolbar pull-right"]').click() # driver.find_element(By.XPATH, '//tr[2]/td/div[@id="accounts_chosen"]').click() # driver.find_element(By.XPATH, '//tr[2]/td/div/div/ul/li[@title="D:开发人员02"]').click() # time.sleep(1) # driver.find_element(By.XPATH, '//tr[3]/td/div[@id="accounts_chosen"]').click() # driver.find_element(By.XPATH, '//tr[3]/td/div/div/ul/li[@title="T:测试人员02"]').click()
def login_success(self): self.login_page = LoginPage(self.driver) self.login_page.open_url(Config().url) self.login_page.input_username(Config().username) self.login_page.input_password(Config().password) self.login_page.click_login()
def test_login(url, username, password, driver): login = LoginPage(driver) login.open_url(url) login.input_username(username) login.input_password(password) login.click_login()
def goto_product(self): #进入产品菜单 self.click(self.product_menu) def goto_project(self): #进入项目菜单 self.click(self.project_menu) def get_usename(self): #获取用户名 value = self.text(self.username_showspan) return value def click_username(self): self.click(self.username_showspan) def click_quit_button(self): self.click(self.quit_button) if __name__ == "__main__": driver = Browser().get_driver() login_page = LoginPage(driver) login_page.open_url(conf.get_chandao_path) main_page = MainPage(driver) login_page.input_username('admin') login_page.input_password('Lrh19960912') login_page.click_login() main_page.get_companyname('title') main_page.goto_project() main_page.goto_product() main_page.get_usename()
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()
def __init__(self,driver): login_page = LoginPage(driver) login.test_login(config.get_url, config.get_user_name, config.get_password, driver) self.driver = login_page.driver # 把login_page的对象转移到filepage time.sleep(1) ##这里一定要加上等待时间,否则获取不到元素 self.file_menu = self.driver.find_element(By.XPATH,'//a[@href="/zentao/doc/"]')