class PageLogin: # 初始化 def __init__(self, driver): self.base = Base(driver) # 输入用户名 def page_input_username(self, username): return self.base.find_css(page.tt_username).send_keys(username) # 输入验证码 def page_input_code(self, code): return self.base.find_css(page.tt_code).send_keys(code) # 点击登录按钮 def page_click_login_btn(self): return self.base.find_xpath(page.tt_login_btn).click() # 获取用户名称 def page_get_user_name(self): return self.base.find_xpath(page.tt_user_name).text # 执行业务操作 def page_login(self, username, code): self.page_input_username(username) self.page_input_code(code) time.sleep(1) self.page_click_login_btn()
def __init__(self): Base.__init__(self) self._query = '' self._template = '' self._sent = Sentence() self._entities = [] self._user_seg = CustomSegment()
class Test_searchBase: def setup_class(self): desired_caps = {} desired_caps['platformName'] = 'android' desired_caps['platformVersion'] = '5.1' desired_caps['deviceName'] = 'shoujiming' desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) #声明driver对象 self.base_obj = Base(self.driver) # 实例化base类,原驱动带self所以现在也带 # 抽出页面元素 self.search_btn = (By.ID, "com.android.settings:id/search") # 搜索按钮 # 输入框 self.search_input = (By.ID, "android:id/search_src_text") # 结果列表 self.results = (By.ID, "com.android.settings:id/title") def teardown_class(self): self.driver.quit() @pytest.fixture(scope='class', autouse=True) # 自动运行一次 def click_search_btn(self): self.base_obj.click_element(self.search_btn) # 调用base类中的点击方法 # 动态传入遍历执行数据 @pytest.mark.parametrize("search_data,search_value", [('1', '休眠'), ('m', 'MAC地址'), ('w', 'WLAN直连')]) def test_search_value(self, search_data, search_value): self.base_obj.send_element(self.search_input, search_data) # 输入内容 result_data = self.base_obj.search_elements(self.results) # 搜索结果列表 assert search_value in [i.text for i in result_data] # 与传入的预期文本对比断言
def underworld(self): template = Base.get_screen() img = Base.get_img(r'..\images\login\fight.png') while Base.match(img, template) < 0.9: Base.get_rand_time(2, 3) Base.get_screen() Base.click(*Base.get_rand_xy(self.fight_x, self.fight_y)) pass
def __init__(self): Base.__init__(self) self._user_info = None self._query_info = None self._semantic = SemanticFrame() self._topicid = TopicID.NullTopic # 子类必须自定义该成员变量 self._stateid = TopicStateID.Null # 状态id,子类自己定义stateid的含义 self._finished = False self._domain = None self._intent = None self.arguments = {}
def __init__(self, cont='', pos='', ner='', relate='', parent='', cont_ner=''): Base.__init__(self) self.cont = cont self.cont_ner = cont_ner self.pos = pos self.ner = ner self.relate = relate self.parent = parent
class PagePublishArticle: # 初始化 def __init__(self, driver): self.base = Base(driver) # 点击内容管理 def page_click_content_manage(self): return self.base.find_xpath(page.tt_content_manage).click() # 点击发布文章 def page_click_publish_article(self): return self.base.find_xpath(page.tt_publish_article).click() # 输入标题 def page_input_title(self, title): return self.base.find_css(page.tt_title).send_keys(title) # 输入内容 def page_input_content(self, content): return self.base.find_xpath(page.tt_content).send_keys(content) # 点击自动 def page_click_cover(self): return self.base.find_xpath(page.tt_cover).click() # 选择频道 def page_click_channel_1(self): return self.base.find_css(page.tt_channel_1).click() def page_click_channel_2(self): return self.base.find_xpath(page.tt_channel_2).click() # 点击发表 def page_click_publish(self): return self.base.find_xpath(page.tt_publish).click()
def setup_class(self): desired_caps = {} desired_caps['platformName'] = 'android' desired_caps['platformVersion'] = '5.1' desired_caps['deviceName'] = 'shoujiming' desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) #声明driver对象 self.base_obj = Base(self.driver) # 实例化base类,原驱动带self所以现在也带 # 抽出页面元素 self.search_btn = (By.ID, "com.android.settings:id/search") # 搜索按钮 # 输入框 self.search_input = (By.ID, "android:id/search_src_text") # 结果列表 self.results = (By.ID, "com.android.settings:id/title")
def init_func_test(): global driver, log driver.get(data.base_url) driver.maximize_window() Base(driver, log).wait_element(login_loc.username_loc) # 访问需要登陆的页面 yield driver, log
class TestTag(object): # 测试数据的测试驱动 data = Base.yaml_load("./config/test_tag_step.yaml") @classmethod def setup_class(cls): cls.tag = Tag() def test_add(self): r = self.tag.add("Tencent") assert r["errcode"] == 0 # 恢复环境:删除添加的标签 res = self.tag.jsonpath('$..[?(@.tagname=="Tencent")]', self.tag.get()) self.tag.delete(res[0]["tagid"]) def test_get(self): r = self.tag.get() assert r["errcode"] == 0 # def test_delete(self): # r = self.tag.delete(10) # assert r["errcode"] == 0 @pytest.mark.parametrize("tagname", data["test_add"]) def test_step_run(self, tagname): self.tag.step_run(tagname, self.data['steps']) self.tag.reset()
def get_content(self,site_file=None,site=None): title = Base.get_content(site_file, tag="title") company = Base.get_content(site_file, name="job_company", tag="class") content = Base.get_content(site_file, name="job_bt", tag="class") skill = Base.get_content(site_file, name="job_request", tag="class") salary = Base.get_content(site_file,name="red",tag="class").string company_link = company.find_all(r"a")[1].string company_req = skill.find_all("span") publish_time = skill.find("div") publish_time = str(publish_time)[5:len(str(publish_time))-6] address = str(company_req[1])[6:len(str(company_req[1]))-7] skill_time = str(company_req[2])[6:len(str(company_req[2]))-7] skill_education = str(company_req[3])[6:len(str(company_req[3]))-7] skill_tag = list() job_key = JobData.get_nedu_job_main_data(DBSession,job_key="job_key") for row in job_key.data: if row in title or row in content.text: skill_tag.append(row) company_info = company.text job_info = Job.add_data_from_lagou(DBSession, company=title, company_link=company_link, company_info=company_info, title=title, skill=skill_time+skill_education, salary=salary, info_link=site, address=address, content=content.text, content_rendered=str(content), publish_time=publish_time, tag=skill_tag) print("asdfasdf") print(skill_tag) for row in skill_tag: JobData.add_tag_content(DBSession,job_kye=row,content=job_info.id) JobData.add_tag_content(DBSession,tag=1)
def setUp(self) -> None: # 获取driver self.driver = GetDriver().get_driver() # 调用登录成功方法 PageLogin(self.driver).page_login_success() # 返回首页 Base(self.driver).base_back_homepage() # 实例化PageOrder self.order = PageOrder(self.driver)
def test_order(self): # 提交订单 try: self.order.page_order() # 断言提交订单是否成功 self.assertIn("提交成功", self.order.page_get_submit_success_info()) except Exception as e: log.error(e) Base(self.driver).base_get_image()
def init_test_quit_element_func(): global driver, log yield driver, log driver.get(data.base_url) driver.maximize_window() Base(driver, log).wait_element(login_loc.username_loc) lp = LoginPage(driver, log) lp.login("13133334444", "123456") time.sleep(3) driver.refresh()
def init_test_user_center_class(): global driver, log driver = webdriver.Chrome() driver.get(data.base_url) driver.maximize_window() Base(driver, log).wait_element(login_loc.username_loc) lp = LoginPage(driver, log) lp.login("13133334444", "123456") time.sleep(3) driver.refresh() yield driver.quit()
class TestShouYe(unittest.TestCase): def setUp(self): print('开始出事话') self.driver = Base().initDriver() print('初始化完成') def testshouye01_01(self): """验证首页导航栏文案显示是否正常""" LoginPage(self.driver).login( name=YamlUtils().getVlue(2, 'login', 'username'), passwd=YamlUtils().getVlue(2, 'login', 'passwd')) m = ShouyePage(self.driver) m.shouyeButttonClick self.assertEqual(m.getNaviContent[0].text, YamlUtils().getVlue(1, 'naviText', 'huati')) # def testshouye01_02(self): # """验证帖子列表内容""" # m = ShouyePage(self.driver) # m.forumListContentClick # self.assertEqual(m.forumDetailTitle,YamlUtils().getVlue(3,'forumDetail','title')) # # def testshouye01_03(self): # """验证评论帖子功能""" # m = ShouyePage(self.driver) # m.forumListContentClick # m.pinglunInput("testxuehai") # m.sendButtonClick # sendContent=m.sendContent # sendContentRawList=[] # for i in range(0,len(sendContent)): # sendContentRawList.append(sendContent[i].text) # sendContentList="".join(sendContentRawList) # self.assertIn("textxuehai",sendContentList) def tearDown(self): self.driver.quit()
def add_point(self, username: str) -> str: """ Register point. Args: username (str): Point username. Return: str: Authstr. """ if not self.search_point(username): authstr = Base.generate_authstr(username) open(self.path + "points.txt", "a").write("{}:{}\n".format(username, authstr)) return authstr return ""
def add_point(self, username: str) -> str: """ Register point. Args: username (str): Point username. Return: str: Authstr. """ if not self.search_point(username): connection, cursor = self.__connect() authstr = Base.generate_authstr(username) sql = "INSERT INTO points (username, authstr) VALUES (?, ?);" cursor.execute(sql, (username, authstr)) connection.commit() connection.close() return authstr return ""
def init_test_product_tail_page_class(): global driver, log driver = webdriver.Chrome() driver.get(data.base_url) driver.maximize_window() Base(driver, log).wait_element(login_loc.username_loc) lp = LoginPage(driver, log) lp.login("13133334444", "123456") time.sleep(3) driver.refresh() index = IndexPage(driver, log) index.click_element(index_loc.newgoods_fastbuy_1_img_loc) time.sleep(2) # # 切换窗口 # windows = driver.window_handles # # 转换到最新打开的窗口 # driver.switch_to.window(windows[-1]) yield driver.quit()
from base import log from base.base import Base from base.base_ims_member_list import MemberList from base.base_team_list import TeamList import re import pytest import allure base = Base() player = MemberList() teamlist = TeamList()
def initialize(self): Base.initialize(self)
def __init__(self): Base.__init__(self) self._words = []
def __init__(self, driver): Base.__init__(self, driver)
def __init__(self, driver): Base.__init__(self, driver) self.driver = driver
def __init__(self,driver): # 子类重写父类初始化方法,传入的还是父类的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.results = (By.ID,"com.android.settings:id/title") # 搜索结果列表
from base.base import Base from multithread.multithread import MultiThreadsP2 instance1 = Base(3) instance1.compute_all([2, 3, 4, 5]) instance1.print_all(True) instance2 = MultiThreadsP2() instance2.MultiThreadsCompute_all([2, 3, 4, 5])
def com2us_login(self, apk_path): """ :return: """ apk_info = self.info.get_package_and_activity(apk_path) # 初始化活动页面以及登录主页面 login = Base.get_img(r'..\images\login\login.png') login2 = Base.get_img(r'..\images\login\login2.png') # 打开app driver = Base(self.cap) driver.open_app(*apk_info) driver.implicitly_wait(50) # 第一次截图 template = Base.get_screen() Base.get_rand_time(3, 4) # 每30截一次图,直到进入登入界面,停止截图 while Base.match(login, template) < 0.9: template = Base.get_screen() Base.get_rand_time(10, 20) print(Base.match(login2, template)) if Base.match(login2, template) < 0.9: continue else: print('开始关闭活动页面') click = Base.get_rand_xy(self.login_activity_x, self.login_activity_y) Base.click(*click) Base.get_rand_time(1, 2) Base.click(*Base.get_rand_xy([460, 470], [430, 460])) print('进入主界面') print('关闭邮箱') Base.get_rand_time(1, 2) Base.click(*Base.get_rand_xy(self.mail_x, self.mail_y)) print('关闭限时优惠') Base.get_rand_time(1, 2) Base.click(*Base.get_rand_xy(self.price_x, self.price_y))
def __init__(self, corpsecret): self. token = Base.get_token(corpsecret)
def initialize(self): Base.initialize(self)
def enter_houtai(self,driver,login): Base(driver, node="houtai").click("houtai") print("登录后,进入后台") yield LoginPage(driver).logout()
def __init__(self, driver): """继承Base类""" Base.__init__(self, driver)
desired_caps["platformName"] = 'Android' desired_caps['platformVersion'] = '5.1' desired_caps['deviceName'] = 'emulator-5554' # desired_caps['appPackage'] = 'com.android.settings' # desired_caps['appActivity'] = '.HWSettings' desired_caps['appPackage'] = pages.app_package desired_caps['appActivity'] = pages.app_activity desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True cls.__app_driver = appium.webdriver.Remote( 'http://127.0.0.1:4723/wd/hub', desired_caps) return cls.__app_driver @classmethod def quit_app_driver(cls): if cls.__app_driver: cls.__app_driver.quit() cls.__app_driver = None if __name__ == '__main__': driver = GetDriver.get_app_driver() print(driver) el = Base(driver).base_get_element(pages.app_username) el.click() sleep(2) msg = "13812345678" input(msg, driver) sleep(5) GetDriver.quit_app_driver()