def __init__(self, driver): self.objbase = Base(driver) self.add_sms = ( By.ID, "com.android.messaging:id/start_new_conversation_button") self.sms_accept = (By.XPATH, "//*[contains(@text,'To')]") self.add_accept = (By.XPATH, "//*[contains(@text,'ALL')]") self.write_msg = (By.CLASS_NAME, "android.widget.EditText")
class Test_Dome: def setup(self): desired_caps = {} # 设备信息 desired_caps['platformName'] = 'Android' # 知道确切版本时填写,不确定不填写 # desired_caps['platformVersion'] = '4.4.4' # adb自动获取设备号 adb devices desired_caps['deviceName'] = '127.0.0.1:62005' # app信息 desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' # 发送中文服务端需配置两个参数, desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) self.base_data=Base(self.driver) def teardown(self): self.driver.quit() print("测试结束") def test_a(self): s_b={By.ID,"com.android.settings:id/search"} i_b={By.ID,"android:id/search_src_text"} self.base_data.click_element(s_b) self.base_data.input_data(i_b,"afbdd")
def __init__(self, driver): Base.__init__(self, driver) # 搜索按钮 self.search_btn = (By.ID, "com.android.settings:id/search") # 搜索输入框 self.search_input = (By.ID, "android:id/search_src_text") # 搜索结果列表 self.search_result = (By.ID, "com.android.settings:id/title")
def __init__(self, driver): Base.__init__(self, driver) #定位搜索按钮 self.search_btn_by_id = (By.ID, "com.android.settings:id/search") #定位搜索框 self.search_input_by_id = (By.ID, "android:id/search_src_text") #获取列表 self.search_res_by_ids = (By.ID, "com.android.settings:id/title")
def __init__(self, driver): # 搜索按钮 self.s_b = (By.ID, "com.android.settings:id/search") # 搜索输入框 self.s_i = (By.ID, "android:id/search_src_text") # 返回按钮 self.s_r = (By.CLASS_NAME, "android.widget.ImageButton") # 实例化Base类 self.base_obj = Base(driver)
def __init__(self, driver): # 实例化Base self.base_obj = Base(driver) # 添加信息按钮 self.add_sms = (By.ID, "com.android.mms:id/action_compose_new") # 接受者 self.accept_user = (By.ID, "com.android.mms:id/recipients_editor") # 输入信息 self.input_sms = (By.ID, "com.android.mms:id/embedded_text_editor") # 发送按钮 self.send_button = (By.ID, "com.android.mms:id/send_button_sms")
class Send_Sms: def __init__(self, driver): # 实例化Base self.base_obj = Base(driver) # 添加信息按钮 self.add_sms = (By.ID, "com.android.mms:id/action_compose_new") # 接受者 self.accept_user = (By.ID, "com.android.mms:id/recipients_editor") # 输入信息 self.input_sms = (By.ID, "com.android.mms:id/embedded_text_editor") # 发送按钮 self.send_button = (By.ID, "com.android.mms:id/send_button_sms") def add_sms_btn(self): # 添加信息按钮 self.base_obj.click_element(self.add_sms) def accept_user_input(self, phone): # 输入接收人 self.base_obj.input_element(self.accept_user, phone) def send_sms_input(self, text): # 输入发送内容 self.base_obj.input_element(self.input_sms, text) # 点击发送按钮 self.base_obj.click_element(self.send_button)
class Login(Base): def __init__(self, driver): # 搜索按钮 self.s_b = (By.ID, "com.android.settings:id/search") # 搜索输入框 self.s_i = (By.ID, "android:id/search_src_text") # 返回按钮 self.s_r = (By.CLASS_NAME, "android.widget.ImageButton") # 实例化Base类 self.base_obj = Base(driver) # 使用方法,业务操作 def click_search(self): # 点击搜索按钮 self.base_obj.click_element(self.s_b)
def setup(self): desired_caps = {} # 设备信息 desired_caps['platformName'] = 'Android' # 知道确切版本时填写,不确定不填写 # desired_caps['platformVersion'] = '4.4.4' # adb自动获取设备号 adb devices desired_caps['deviceName'] = '127.0.0.1:62005' # app信息 desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' # 发送中文服务端需配置两个参数, desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) self.base_data=Base(self.driver)
def setup(self): desired_caps = {} desired_caps["platformVersion"] = "6.0.1" # 允许输入中文 desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True desired_caps["deviceName"] = "192.168.2.168:5555" desired_caps["platformName"] = "Android" desired_caps["appPackage"] = "com.android.settings" desired_caps["appActivity"] = ".GridSettings" self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.base_ojb = Base(self.driver)
def setup(self): # 启动参数 desired_caps = {} # 设备信息 desired_caps["platformName"] = "Android" desired_caps["platformVersion"] = "9" desired_caps["deviceName"] = '192.168.56.101:5555' # "huawei" # app信息 desired_caps["appPackage"] = "com.android.settings" desired_caps["appActivity"] = ".Settings" # 中文输入允许 desired_caps["unicodeKeyboard"] = True desired_caps["resetKeyboard"] = True # 声明手机驱动对象 self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.objbase = Base(self.driver)
def setup(self): desired_caps = {} # 设备信息 # 平台的名称 desired_caps['platformName'] = 'Android' # 设备系统版本号 desired_caps['platformVersion'] = '6.0' # 设备号 Android: adb devices desired_caps['deviceName'] = '192.168.17.101:5555' # app信息 启动的Activity desired_caps['appPackage'] = 'com.android.settings' # appPackage启动的包 desired_caps['appActivity'] = '.Settings' # unicodeKeyboard unicode设置(允许中文输入) desired_caps['unicodeKeyboard'] = True # resetKeyboard 键盘设置(允许中文输入) desired_caps['resetKeyboard'] = True self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) # 实例化 self.base_obj = Base(self.driver)
class Search_Page: def __init__(self, driver): # 搜索按钮 self.search_btn = (By.ID, "com.android.settings:id/search") # 搜索输入框 self.search_input = (By.ID, "android:id/search_src_text") # 搜索结果列表 self.search_result = (By.ID, "com.android.settings:id/title") # 实例化Base类 self.base_obj = Base(driver) def search_text(self, text_value): # 搜索内容 # 点击搜索按钮 self.base_obj.click_element(self.search_btn) # 定位搜索输入框 self.base_obj.input_element(self.search_input, text_value) # 获取搜索结果列表 result_list = self.base_obj.search_elements(self.search_result, timeout=5) return [i.text for i in result_list]
class Test_search: def setup(self): desired_caps = {} desired_caps["platformVersion"] = "6.0.1" # 允许输入中文 desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True desired_caps["deviceName"] = "192.168.2.168:5555" desired_caps["platformName"] = "Android" desired_caps["appPackage"] = "com.android.settings" desired_caps["appActivity"] = ".GridSettings" self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.base_ojb = Base(self.driver) def test_po001(self,): #点击搜索按钮 self.base_ojb.click_element(By.CLASS_NAME,"android.widget.Button") # 搜索框输入 self.base_ojb.input_element(By.ID,"android:id/search_src_text","123") # 点击返回 self.base_ojb.click_element(By.ID,"android:id/up") def teardown(self): self.driver.quit()
class Test_search: def setup(self): desired_caps = {} # 设备信息 # 平台的名称 desired_caps['platformName'] = 'Android' # 设备系统版本号 desired_caps['platformVersion'] = '6.0' # 设备号 Android: adb devices desired_caps['deviceName'] = '192.168.17.101:5555' # app信息 启动的Activity desired_caps['appPackage'] = 'com.android.settings' # appPackage启动的包 desired_caps['appActivity'] = '.Settings' # unicodeKeyboard unicode设置(允许中文输入) desired_caps['unicodeKeyboard'] = True # resetKeyboard 键盘设置(允许中文输入) desired_caps['resetKeyboard'] = True self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) # 实例化 self.base_obj = Base(self.driver) def test_po001(self): # 点击搜索按钮 self.base_obj.click_element(By.ID, "com.android.settings:id/search") # 输入搜索框 self.base_obj.input_element(By.ID, "com.android.settings:id/search", "123") # 点击返回按钮 self.base_obj.click_element(By.CLASS_NAME, "android.widget.ImageButton")
class Test_A: def setup(self): # 启动参数 desired_caps = {} # 设备信息 desired_caps["platformName"] = "Android" desired_caps["platformVersion"] = "9" desired_caps["deviceName"] = '192.168.56.101:5555' # "huawei" # app信息 desired_caps["appPackage"] = "com.android.settings" desired_caps["appActivity"] = ".Settings" # 中文输入允许 desired_caps["unicodeKeyboard"] = True desired_caps["resetKeyboard"] = True # 声明手机驱动对象 self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.objbase = Base(self.driver) def test_001(self): s_b = (By.XPATH, "//*[contains(@text,'Network')]") self.objbase.find_element(s_b) s_r = (By.ID, "com.android.settings:id/search_action_bar") s_t = (By.ID, "android:id/search_src_text",) self.objbase.click_element(s_r) self.objbase.input_element(s_t, "123") def teardown(self): self.driver.quit()
def setup_class(self): # server 启动参数 desired_caps = {} # 设备信息 desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5.1.1' desired_caps['deviceName'] = '127.0.0.1:5555 devices' # app信息 desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = 'com.android.settings.Settings' desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) self.base_obj = Base(self.driver)
class Send_Msg: def __init__(self, driver): self.objbase = Base(driver) self.add_sms = ( By.ID, "com.android.messaging:id/start_new_conversation_button") self.sms_accept = (By.XPATH, "//*[contains(@text,'To')]") self.add_accept = (By.XPATH, "//*[contains(@text,'ALL')]") self.write_msg = (By.CLASS_NAME, "android.widget.EditText") def add_click_button(self): self.objbase.click_element(self.add_sms) def add_sms_contact(self, phone): self.objbase.input_element(self.sms_accept, phone) self.objbase.click_element(self.add_accept) def sms_write_msg(self, msg): self.objbase.input_element(self.write_msg, msg)
class SearchPage(object): def __init__(self, driver): self.s_search = (By.ID, 'com.android.settings:id/search') self.s_text = (By.ID, 'android:id/search_src_text') self.s_back = (By.CLASS_NAME, 'android.widget.ImageButton') self.base_obj = Base(driver) def click_search(self): self.base_obj.click_element(self.s_search) def search_input(self, input_text): self.base_obj.input_element(self.s_text, input_text) def click_return(self): self.base_obj.click_element(self.s_back)
class Search_page(): def __init__(self, driver): self.obj = Base(driver) print("search page check point,after Base init") self.driver = driver print("search page check point,after self.driver") def click_search_btn(self): self.obj.click_element(test_yaml.search_txt) def search_input(self, text): self.obj.input_element(test_yaml.search_btn, text) def search_return(self): self.obj.click_element(test_yaml.search_rtn)
class Test: def setup(self): desired_caps = {} desired_caps["platformVersion"] = "6.0.1" # 允许输入中文 desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True desired_caps["deviceName"] = "192.168.2.168:5555" desired_caps["platformName"] = "Android" desired_caps["appPackage"] = "com.android.settings" desired_caps["appActivity"] = ".GridSettings" self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.base_ojb = Base(self.driver) def test1(self): s_b = (By.XPATH, "//*[contains(@text,'应用程序')]") s_b1 = (By.XPATH, "//*[contains(@text,'我的文件')]") s_b2 = (By.XPATH, "//*[contains(@text,'图片')]") time.sleep(2) self.driver.keyevent(4) time.sleep(2) self.base_ojb.cl_el(s_b) self.base_ojb.cl_el(s_b1) self.base_ojb.cl_el(s_b2) TouchAction(self.driver).long_press(x=375,y=559,property=5)\ .release().perform() self.driver.keyevent(3) def teardown(self): self.driver.quit()
def __init__(self, driver): Base.__init__(self, driver)
def __init__(self, driver): # 初始化BASE类 Base.__init__(self, driver)
def __init__(self, driver): self.s_search = (By.ID, 'com.android.settings:id/search') self.s_text = (By.ID, 'android:id/search_src_text') self.s_back = (By.CLASS_NAME, 'android.widget.ImageButton') self.base_obj = Base(driver)
def __init__(self, driver): Base.__init__(self, driver) # 获取屏幕宽高 'width', 'height' self.screen_size = self.driver.get_window_size()
class Search_Page: def __init__(self, driver): # 搜索按钮 self.s_b = (By.ID, "com.android.settings:id/search") # 搜索输入框 self.s_i = (By.ID, "android:id/search_src_text") # 返回按钮 self.s_r = (By.CLASS_NAME, "android.widget.ImageButton") # 实例化Base类 self.base_obj = Base(driver) def click_search(self): # 点击搜索按钮 self.base_obj.click_element(self.s_b) def search_input(self, input_text): # 输入搜索内容 self.base_obj.input_element(self.s_i, input_text) def click_return(self): # 点击返回按钮 self.base_obj.click_element(self.s_r) def search_text(self, text): # 点击搜索按钮 self.base_obj.click_element(self.s_b) # 输入内容 self.base_obj.input_element(self.s_i, text) # 点击返回按钮 self.base_obj.click_element(self.s_r)
def pre_run_initialization(self, driver): self.obj = Base(driver) self.hua = Huadong(driver) self.driver = driver
class Login: @pytest.fixture(autouse=True) def pre_run_initialization(self, driver): self.obj = Base(driver) self.hua = Huadong(driver) self.driver = driver def goto_login(self): update = self.obj.find_element_x(page.app_update) assert update, 'no update' self.driver.get_screenshot_as_file( "./Screenshots/login/update_window.png") self.obj.click_element(page.app_update_cancel) self.driver.get_screenshot_as_file( "./Screenshots/login/main_scene.png") time.sleep(2) self.obj.click_element(page.leaderboard) self.driver.get_screenshot_as_file( "./Screenshots/main_page/main_leaderboard.png") self.obj.click_element(page.plaza) self.driver.get_screenshot_as_file( "./Screenshots/main_page/main_plaza.png") self.obj.click_element(page.my_interest) self.driver.get_screenshot_as_file( "./Screenshots/main_page/main_community.png") self.obj.click_element(page.my_games) self.driver.get_screenshot_as_file( "./Screenshots/main_page/main_games.png") self.obj.click_element(page.game_recom) self.driver.get_screenshot_as_file( "./Screenshots/main_page/main_market.png") self.obj.click_element(page.go_to_setting) time.sleep(2) def register_failture(self): assert self.obj.find_element_x( page.login_has_account), 'goto setting page failed' time.sleep(2) #注册用例 #空号码点击注册 self.obj.click_element(page.login_regis) #输入号码注册 assert self.obj.find_element_x( page.login_cellnum), 'cant find input text' self.obj.input_element(page.login_cellnum, page.login_data) time.sleep(5) self.driver.get_screenshot_as_file( "./Screenshots/login/login_cellnum.png") self.obj.click_element(page.login_regis) #输入验证码界面,不输入直接关闭,输入错误的关闭 self.obj.click_element(page.login_verfi_close) self.obj.click_element(page.login_regis) self.obj.input_element(page.login_verfi_text, page.verfi_code) assert self.obj.find_element_x(page.verfi_error), 'verify error' self.driver.get_screenshot_as_file('./Screenshots/login/verfiy_error') self.obj.click_element(page.login_verfi_close) time.sleep(5) def login_failture(self): #切换登录方式页签,使用邮箱登录 self.obj.click_element(page.login_has_account) self.driver.get_screenshot_as_file('./Screenshots/login/login_page') self.obj.click_element(page.login_account_email) time.sleep(2) self.obj.click_element(page.login_account_cellnum) self.obj.click_element(page.account_ver) self.obj.input_element(page.account_cellnum, page.account_num) self.driver.get_screenshot_as_file( './Screenshots/login/phonenumber_login') self.obj.click_element(page.account_ver) self.obj.input_element(page.account_ver_code, page.verfi_code) assert self.obj.find_element_x(page.verfi_error), 'verify error' # #重新发送验证码,点击重新发送按钮失败,为啥 # cc = self.obj.find_element_x(Page.account_ver_code) # cc.clear() # self.obj.click_element(Page.veri_resend) # print("checkpoint:send message again") # assert self.obj.find_element_x(Page.verfi_code1).text is None,'resend verify code error' self.obj.click_element(page.login_verfi_close) time.sleep(2) #修改密码 def get_need_element_down(self, ele_na, need_ele): """ :param ele_name: class_name :param need_element: 待查找的text :return: """ i = 20 while i >= 0: ele = self.driver.find_elements_by_class_name(ele_na) for e in ele: if e.text == need_ele: e.click() return self.hua.huadong_down() i -= 1 def change_pwd(self): self.obj.click_element(page.per__set) need_element = '密码安全' self.get_need_element_down(page.set_class, need_element) self.obj.input_element(page.input_pwd_old, page.pwd_old) self.obj.input_element(page.input_pwd_new, page.pwd_new) self.obj.input_element(page.input_pwd__new_again, page.pwd_new) self.obj.click_element(page.pwd_eye) self.driver.get_screenshot_as_file('./Screenshots/login/set_pwd.png') self.obj.click_element(page.check_button) time.sleep(5)
def setup_class(self): self.driver = init_driver() self.tongxun_obj = Page_Zong(self.driver).tongxun() self.base_obj = Base(self.driver)
def __init__(self, driver1): # 调用父类初始化方法,将接收到的driver传给父类 Base.__init__(self, driver1)