class LoginPage(object): def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_login") print self.login_page_items def frame(self): locateType, locateExpression = self.login_page_items[ 'login_page.frame'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def username(self): locateType, locateExpression = self.login_page_items[ 'login_page.username'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def password(self): locateType, locateExpression = self.login_page_items[ 'login_page.password'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def loginbutton(self): locateType, locateExpression = self.login_page_items[ 'login_page.loginbutton'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression)
class HomePage(object): def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.home_page_items = self.parse_config_file.getElementsFromSection( "163mail_homepage") def address_book_page_link(self): locateType, locateExpression = self.home_page_items[ "home_page.addressbook"].split(">") return getElement(self.driver, locateType, locateExpression)
class LoginPage(object): def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_login") print self.login_page_items def frame(self): locateType, locateExpression = self.login_page_items[ 'login_page.frame'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def username(self): locateType, locateExpression = self.login_page_items[ 'login_page.username'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def password(self): locateType, locateExpression = self.login_page_items[ 'login_page.password'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def loginbutton(self): locateType, locateExpression = self.login_page_items[ 'login_page.loginbutton'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def login(self, username, password): self.driver.get("http://mail.126.com") self.driver.switch_to.frame(self.frame()) time.sleep(2) self.username_clear() self.username_input(username) self.password_input(password) self.loginbutton_click() time.sleep(4) def username_clear(self): self.username().clear() def username_input(self, value): self.username().send_keys(value) def password_input(self, value): self.password().send_keys(value) def loginbutton_click(self): self.loginbutton().click()
class HomePage(object): def __init__(self, driver): "初始化参数,加载配置文件,将'126mail_homepage'section内容读取出来" self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_homepage") def address_book_page_link(self): "点击通讯录" locateType, locateExpression = self.login_page_items[ "login_page.addressbook"].split(">") return getElement(self.driver, locateType, locateExpression)
class LoginPage(object): def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_login") print self.login_page_items def frame(self): locateType, locateExpression = self.login_page_items[ 'login_page.frame'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def username(self): locateType, locateExpression = self.login_page_items[ 'login_page.username'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def password(self): locateType, locateExpression = self.login_page_items[ 'login_page.password'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def loginbutton(self): locateType, locateExpression = self.login_page_items[ 'login_page.loginbutton'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def username_clear(self): self.username().clear() def username_input(self, value): self.username().send_keys(value) def password_input(self, value): self.password().send_keys(value) def loginbutton_click(self): self.loginbutton().click() def login(self): self.driver.switch_to.frame(self.frame()) self.username_clear() self.username_input('testman1980') self.password_input('wulaoshi1978') self.loginbutton_click()
class AddressPage(object): def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_addcontactspage") print self.login_page_items def add_contact_button(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.createcontactsbtn'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def contact_name(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.contactpersonname'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def contact_email(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.contactpersonemail'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def contact_is_star(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.starcontacts'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def contact_mobile(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.contactpersonmobile'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def contact_other_info(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.contactpersoncomment'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression) def contact_save_button(self): locateType, locateExpression = self.login_page_items[ 'addcontacts_page.savecontaceperson'].split(">") print locateType, locateExpression return getElement(self.driver, locateType, locateExpression)
class AddressPage(object): def __init__(self, driver): "初始化参数,加载配置文件,将'126mail_addcontactspage'section内容读取出来" self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_addcontactspage") def add_contact_button(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.createcontactsbtn"].split(">") return getElement(self.driver, locateType, locateExpression) def contact_name(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.contactpersonname"].split(">") return getElement(self.driver, locateType, locateExpression) def contact_email(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.contactpersonemail"].split(">") return getElement(self.driver, locateType, locateExpression) def contact_is_star(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.starcontacts"].split(">") return getElement(self.driver, locateType, locateExpression) def contact_mobile(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.contactpersonmobile"].split(">") return getElement(self.driver, locateType, locateExpression) def contact_other_info(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.contactpersoncomment"].split(">") return getElement(self.driver, locateType, locateExpression) def contact_save_button(self): locateType, locateExpression = self.login_page_items[ "addcontacts_page.savecontactperson"].split(">") return getElement(self.driver, locateType, locateExpression)
def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_login") print self.login_page_items
def __init__(self, driver): "初始化参数,加载配置文件,将'126mail_homepage'section内容读取出来" self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_homepage")
def __init__(self, driver): self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.address_page_items = self.parse_config_file.getElementsFromSection( "163mail_addcontactspage")
class LoginPage(object): def __init__(self, driver): "初始化参数,加载配置文件,将'126mail_login'section内容读取出来" self.driver = driver self.parse_config_file = ParsePageObjectRepositoryConfig() self.login_page_items = self.parse_config_file.getItemsFromSection( "126mail_login") def frame(self): "定位frame元素" locateType, locateExpression = self.login_page_items[ "login_page.frame"].split(">") return getElement(self.driver, locateType, locateExpression) def username(self): "定位账号输入框元素" locateType, locateExpression = self.login_page_items[ "login_page.username"].split(">") return getElement(self.driver, locateType, locateExpression) def password(self): "定位密码输入框元素" locateType, locateExpression = self.login_page_items[ "login_page.password"].split(">") return getElement(self.driver, locateType, locateExpression) def loginButton(self): "定位登陆按钮元素" locateType, locateExpression = self.login_page_items[ "login_page.loginbutton"].split(">") return getElement(self.driver, locateType, locateExpression) def login(self, userName, passWd): "封装登陆动作,这指定了访问网址" self.driver.get("http:mail.126.com") self.driver.implicitly_wait(10) self.driver.switch_to.frame(self.frame()) self.username().clear() self.username().send_keys(userName) self.password().clear() self.password().send_keys(passWd) self.loginButton().click() time.sleep(2) """下面方法是将每一步操作进一步封装""" def switchFrame(self): "切换frame操作" self.driver.switch_to.frame(self.frame()) def usernameClear(self): "清空账号输入框内容" self.username().clear() def usernameInput(self, value): "在账号输入框内输入指定内容" self.username().send_keys(value) def passwordInput(self, value): "在密码输入框内输入指定内容" self.password().send_keys(value) def loginButtonClick(self): "点击登陆按钮" self.loginButton().click() def loginAdvanced(self, username, password): "封装登陆进化版" self.driver.get("http:mail.126.com") self.driver.implicitly_wait(5) self.switchFrame() self.usernameClear() self.usernameInput(username) self.passwordInput(password) self.loginButtonClick() time.sleep(2)