class LoginPage(BasePage): """ 登录页面 """ # # 控件定位方式 # css = "xx" # id_ = "xx" # name = "xx" # xpath = "xx" # link_text = "xx" # partial_link_text = "xx" # tag = "xx" # class_name = "xx" username = Element(name="username", describe="用户名输入框") password = Element(name="password", describe="密码输入框") login_button = Element(id_="login_button", describe="登录按钮") forget_password = Element(id_="forget-password2", describe="忘记密码链接") get_phone_captcha = Element(id_="getPhoneCaptcha", describe="获取验证码按钮") def login(self, username, password): """ 用指定用户名、密码登录 :param username: :param password: """ self.username.send_keys(username) self.password.send_keys(password) self.login_button.click()
class BaiduPage(Page): search_input = Element(id_="kw", describe="搜索框") search_button = Element(id_="su", describe="搜索按钮") settings = Element(css="#s-usersetting-top", describe="设置") search_setting = Element(css="#s-user-setting-menu > div > a.setpref", describe="搜索设置") save_setting = Element(link_text="保存设置", describe="保存设置")
class HomePage(BasePage): """ 首页 """ menu_item_company_management = Element(xpath="//*[text()='企业管理']") menu_item_my_companies_list = Element(xpath="//*[text()='我的企业列表']") menu_item_company_settlement = Element(xpath="//*[text()='企业结算']")
class login(Page): """ 项目用户登录、退出定位元素""" # url url = Url.baseUrl # 示例 search_input_loc = Element(id_='kw') search_button_loc = Element(id_='su') # 操作方法封装 def search_input(self, key): self.search_input_loc.clear() self.search_input_loc.send_keys(key) def search_button(self): self.search_button_loc.click()
def test_page_element(self): elem_id = Element(id_='id') elem_name = Element(name='name') elem_class = Element(class_name='class') elem_tag = Element(tag='input') elem_link_text = Element(link_text='this_is_link') elem_partial_link_text = Element(partial_link_text='is_link') elem_xpath = Element(xpath='//*[@id="kk"]') elem_css = Element(css='#id') assert elem_id.k == 'id_' assert elem_name.k == "name" assert elem_class.k == "class_name" assert elem_tag.k == "tag" assert elem_link_text.k == "link_text" assert elem_partial_link_text.k == "partial_link_text" assert elem_xpath.k == "xpath" assert elem_css.k == "css"
class LoginPage(Page): a = "1111111111" company_name = Element( css= "div#app > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > p:nth-child(1)" ) body = Element(css="body") user_input = Element(css="form > div:nth-child(1) > div > div > input") password_input = Element(css="form > div:nth-child(2) > div > div > input") login_button = Element(css="form > button") forget_password_button = Element( css="form > div:nth-child(4) > span:nth-child(1)") register_button = Element( css="form > div:nth-child(4) > span:nth-child(1)") select_hospital = Element( css= "div.el-scrollbar__view > ul > li:nth-child(1) > div > div:nth-child(2) > div:nth-child(2) > button" ) select_ensure = Element( css="div.el-dialog__body > div > div:nth-child(3) > button") pass
def test_get_unattached(self): assert Element(css='bar').__get__(None, None) is None
class IndexPage(Page): body = Element(css="body") index_button = Element(css="ul.el-menu > li:nth-child(1) > a") user_name = Element(css="div.supName > span") hospital_name = Element(css="div.nuhName") change_hospital_button = Element(css="div.nuhName > span") close_hospital = Element(xpath=r"/html/body/div[2]/div/div[1]/button") zi_zhi_ti_xing_button = Element(css="div.head-right > a:nth-child(1)") jin_xiao_ti_xing_button = Element(css="div.head-right > a:nth-child(2)") ku_cun_yu_jing_button = Element(css="div.head-right > a:nth-child(3)") wei_chu_li_button = Element(css="div.head-right > a:nth-child(4)") wei_wan_jie_button = Element(css="div.head-right > a:nth-child(5)") tui_huo_dan_button = Element(css="div.head-right > a:nth-child(6)") order_button = Element( css= "div.main-content > div:nth-child(1) > div:nth-child(3) > div > div > " "div.card-header > span.card-header-title > button") order_quarter_button = Element( css= "div.main-content > div:nth-child(1) > div:nth-child(3) > div > div > " "div.card-header > div.card-header-type > span:nth-child(1)") order_month_button = Element( css= "div.main-content > div:nth-child(1) > div:nth-child(3) > div > div > " "div.card-header > div.card-header-type > span:nth-child(2)") order_report_button = Element( css= "div.main-content > div:nth-child(1) > div:nth-child(3) > div > div > " "div.card-table > div:nth-child(2) > svg") return_button = Element( css="div.main-content > div:nth-child(1) > div:nth-child(4) > div > " "div.card-header > span.card-header-title > button") return_quarter_button = Element( css="div.main-content > div:nth-child(1) > div:nth-child(4) > div > " "div.card-header > div.card-header-type > span:nth-child(1)") return_month_button = Element( css="div.main-content > div:nth-child(1) > div:nth-child(4) > div > " "div.card-header > div.card-header-type > span:nth-child(2)") return_report_button = Element( css="div.main-content > div:nth-child(1) > div:nth-child(4) > div > " "div:nth-child(2) > div.card-table > div:nth-child(2) > svg") market_button = Element( css= "div.ranking-row > div.card-header > span.card-header-title > button") market_year_button = Element( css="div.ranking-row > div.card-header > div.card-header-type > " "span:nth-child(1)") market_month_button = Element( css="div.ranking-row > div.card-header > div.card-header-type > " "span:nth-child(2)") market_quarter_button = Element( css="div.ranking-row > div.card-header > div.card-header-type > " "span:nth-child(3)") all_order_button = Element( css="div.order > div.card-header > div.card-header-type > " "span:nth-child(1)") wcl_order_button = Element( css="div.order > div.card-header > div.card-header-type > " "span:nth-child(2)") wwj_order_button = Element( css="div.order > div.card-header > div.card-header-type > " "span:nth-child(3)") ywc_order_button = Element( css="div.order > div.card-header > div.card-header-type > " "span:nth-child(4)") order_untreated = Element(css="div.order > div:nth-child(3) > svg") pass
class BaiduIndexPage(Page): search_input = Element(name='wd', describe="搜索框")
class BaiduPage(Page): login_button = Element(link_text="登录") register_link = Element(link_text="立即注册")
class BaiDuPage(Page): # timeout:元素超时时间,默认是10 # describe:描述,增加元素定义的可读性 shu_ru = Element(id_="kw", describe="输入操作") cha_xun = Element(id_="su")
class MyCompaniesList(BasePage): """ 我的企业列表 """ # 按钮 Inquire_button = Element(xpath="//*[text()='查询']") modify_button = Element(xpath="//*[text()='修改']") more_button = Element(xpath="//*[text()=' 更多']") company_configuration_button = Element(xpath="//*[text()='企业配置']") account_details_button = Element(xpath="//*/a[text()='账户详情']") account_details_close_button = Element(class_name="btn dark btn-outline") account_management_button = Element(xpath="//*/a[text()='账户管理']") stored_value_record_button = Element(xpath="//*/a[text()='储值记录']") company_transfer_record_button = Element(xpath="//*/a[text()='企业转账记录']") # 文本 company_list_text = Element(xpath="//*[text()='企业列表']") account_type_text = Element(xpath="//*[text()='账户类型']")
class SelectPage(Page): frame = Element(id_="iframeResult", describe="表单") select_elem = Element(xpath="//select", describe="选择框")
class RunoobPage(Page): iframe = Element(css="#iframeResult") div = CSSElement("html > body > div")
class LoginPage(Page): search_input = Element(name='wd', describe="搜索框") def search(self): self.search_input.send_keys("poium")
class DataTimePage(Page): frame = Element(id_="iframe") date = Element(id_="appDate") year = Element(css=".dwwo", index=0) mouth = Element(css=".dwwo", index=1) day = Element(css=".dwwo", index=2)
def test_page_element_bad_args(self): with pytest.raises(ValueError): Element() with pytest.raises(ValueError): Element(id_='foo', xpath='bar')
class BaiduPage(Page): """baidu page""" search_input = Element(id_="kw") search_button = Element(id_="su")
def test_setting_describe(self): elem = Element(name='wd', describe="this is search input") assert elem.k == "name"
class CalculatorPage(Page): number_1 = Element(id_="com.android.calculator2:id/digit_1") number_2 = Element(id_="com.android.calculator2:id/digit_2") add = Element(id_="com.android.calculator2:id/op_add") eq = Element(id_="com.android.calculator2:id/eq")
class BaiduPage(Page): setting = Element(css='#s-usersetting-top') search_setting = Element(css=".setpref") search_setting_hint = Element(css="#sugConf > span.item-desc")
def test_setting_time_out(self): elem = Element(css='foo', timeout=10) assert elem.k == "css"