class TestYiYao: def setup(self): # self.main = MainPage(types='debug') # self.main.write_cookie_for_json('../datas/cookie.json') self.main = MainPage( url='http://partner.zhyf.sfrog.cn/#/workbench/index') self.main.add_cookie('../datas/cookie.json') self.main.refresh() self.main.set_window_size(1920, 1080) def teardown(self): self.main.quit() @allure.story('测试用例:创建处方成功') def test_add_prescription_success(self): name = 'shen' res = self.main.goto_prescription_center().goto_prescription_create( ).add_prescription_success(patient_name=name, age='18', phone='17365372296', birthday='2011-03-08', detail_address='天台', medicinal_name='c', medicinal_num='2').query_prescription(name) pytest.assume(res == name)
class TestMain: def setup_class(self): work_path = os.path.split(os.path.realpath(__file__))[0] # work_path = os.getcwd() self.main_page = MainPage(work_path) self.public_page = PublicPage(work_path) logger.debug(f"test_main.py 当前运行进程为:{os.getpid()}") anchor = self.main_page.confirm_anchor() assert anchor == "关注" def teardown(self): self.main_page.start_activity() def test_switch_class(self): self.main_page.goto_attention().goto_recommended().goto_hot().goto_pk() # class TestMainHot: def test_hot_day(self): self.main_page.goto_hot().click_hot_logo().back().click_hot_message( ).back() def test_hot_stocks(self): self.main_page.goto_hot().goto_hot_all_stocks().hot_back_btn().goto_hot_stock_one().back()\ .goto_hot_stock_two().back().goto_hot_stock_three().back().goto_hot_stock_four().back()\ .goto_hot_stock_five().back().goto_hot_stock_six().back().goto_hot_stock_seven().back() def test_hot_topic(self): self.main_page.goto_hot().goto_hot_all_topic().topic_back_btn().click_hot_topic_one()\ .topic_msg_back_btn().click_hot_topic_two().topic_msg_back_btn() # class TestMainRecommended: def test_recommended_banner(self): self.main_page.goto_recommended() banner_icon_index = 1 while banner_icon_index < 6: self.main_page.choose_recommended_banner_icon(banner_icon_index)\ .click_recommended_banner().back() banner_icon_index += 1 def test_article_content(self): self.main_page.goto_recommended().click_recommended_author_portrait().back()\ .click_recommended_author_name().back().click_recommended_article_text().back() def test_article_action(self): self.main_page.goto_recommended().get_size().slide().click_recommended_article_retweet()\ .close().click_recommended_article_comment().back()\ .click_recommended_article_reward().close() # class TestMainAttention: def test_empty(self): self.main_page.goto_empty_btn().back() def teardown_class(self): self.main_page.quit()
class TestAddMember: def setup_class(self): self.main = MainPage() def test_add_member(self): # 1 添加成员,跳转至成员添加页面 # 2 填写成员信息 # 3 点击保存 # 4 断言是否添加成功 assert '李四' in self.main.goto_add_member().add_member().get_member() def test_add_member01(self): self.main = MainPage() # 1 添加成员,跳转至成员添加页面 # 2 填写成员信息 # 3 点击保存 # 4 断言是否添加成功 assert '李四' not in self.main.goto_add_member().add_member01( ).get_member() self.main.quit()
class TestYiYao: def setup(self): # self.main = MainPage(types='debug') # self.main.write_cookie_for_json('../datas/cookie.json') useinghandless = 'true' if useinghandless == 'true': moudle = '无界面' else: moudle = '有界面' loc1 = ("xpath", "//*[contains(text(),'登 录')]") loc2 = ("xpath", "//span[contains(text(),'处方中心')]") self.main = MainPage( url='http://partner.zhyf.sfrog.cn/#/workbench/index', userhadless=useinghandless) print('植入cookie前') print(f'检测未登录页面元素:{self.main.is_visibility_of_element_located(loc1)}') print(f'检测已登录页面元素:{self.main.is_visibility_of_element_located(loc2)}') time.sleep(1) self.main.get_screen_shot(f'{moudle}cookie前截图', '') self.main.add_cookie('../datas/cookie.json') self.main.refresh() # self.main.max_size() self.main.set_window_size(1920, 1080) print('植入cookie后') time.sleep(1) self.main.get_screen_shot(f'{moudle}cookie后截图', '') print(f'检测未登录页面元素:{self.main.is_visibility_of_element_located(loc1)}') print(f'检测已登录页面元素:{self.main.is_visibility_of_element_located(loc2)}') def teardown(self): self.main.quit() @allure.story('测试用例:创建处方成功') def test_add_prescription_success(self): pass
class TestWeiXin: def setup(self): self.mainPage = MainPage() @pytest.mark.parametrize( ("username", "othername", "id", "phone", "email", "position"), yaml.safe_load(open("../resouce/data.yml", encoding='utf-8'))) def test_weixin(self, username, othername, id, phone, email, position): assert self.mainPage.goto_add_members().add_members( username, othername, id, phone, email, position) def test_members(self): username = "******" members = self.mainPage.goto_address_book().get_members() assert username in members def teardown(self): self.mainPage.quit() @pytest.mark.skip def test_cookies(self): # option = Options() # option.debugger_address = "127.0.0.1:9222" # self.driver = webdriver.Chrome(options=option) self.driver = webdriver.Chrome() self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index") #cookies = self.driver.get_cookies() cookies = [{ 'domain': '.qq.com', 'expiry': 1620221528, 'httpOnly': False, 'name': '_gat', 'path': '/', 'secure': False, 'value': '1' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.refid', 'path': '/', 'secure': True, 'value': '29807030181260470' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'ww_rtkey', 'path': '/', 'secure': True, 'value': '8v5bqsk' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wxpay.vid', 'path': '/', 'secure': False, 'value': '1688850954847467' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.sid', 'path': '/', 'secure': True, 'value': 'GAcW9_16kP3sP9Y3_5UV7GfqYA4StuZhJNI0n9oBt6DF3nLAZAYKQnUyp5aPisWW' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wxpay.corpid', 'path': '/', 'secure': False, 'value': '1970325011434433' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.cs_ind', 'path': '/', 'secure': True, 'value': '' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.d2st', 'path': '/', 'secure': True, 'value': 'a7617125' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.c_gdpr', 'path': '/', 'secure': True, 'value': '0' }, { 'domain': '.qq.com', 'expiry': 1620307869, 'httpOnly': False, 'name': '_gid', 'path': '/', 'secure': False, 'value': 'GA1.2.871635060.1620200420' }, { 'domain': 'work.weixin.qq.com', 'expiry': 1620231955, 'httpOnly': True, 'name': 'ww_rtkey', 'path': '/', 'secure': False, 'value': '6i7qdku' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.ref', 'path': '/', 'secure': True, 'value': 'direct' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.vst', 'path': '/', 'secure': True, 'value': 'dc7mLDvc20hhczwLjKegaTE4YsdFK2oiYT33zpLsP7jBdcnq_Yf_DJ9A27NZKov7CGLqRtwNpk45pp3C9iQi-X9urzvD8r-g72RVcQPEZa-OEcQkiTrZ0obHP0GFfzV_xuB_o8fRgMTk6vLyHCrzpsXx01hzUrsftLGfGtcsPmqZaK_fj4Y9Ny_7SFdn8n7l0rxcjl8QXRbBgdIo7rI8M6FcXerS0kKNT9KbpxoUzL9cp8UNbnzXEFJ9JVcBHn4eOhYEVni0FBctEo84qi0Rag' }, { 'domain': '.qq.com', 'expiry': 1683293469, 'httpOnly': False, 'name': '_ga', 'path': '/', 'secure': False, 'value': 'GA1.2.2061398850.1620011906' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.vid', 'path': '/', 'secure': False, 'value': '1688850954847467' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.ltype', 'path': '/', 'secure': True, 'value': '1' }, { 'domain': '.work.weixin.qq.com', 'expiry': 1622813470, 'httpOnly': False, 'name': 'wwrtx.i18n_lan', 'path': '/', 'secure': False, 'value': 'zh' }] print(cookies) for cookie in cookies: if 'expiry' in cookie.keys(): cookie.pop('expiry') self.driver.add_cookie(cookie) self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index") sleep(10) @pytest.mark.skip def test_dbs(self): cookies = [{ 'domain': '.qq.com', 'expiry': 1620221528, 'httpOnly': False, 'name': '_gat', 'path': '/', 'secure': False, 'value': '1' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.refid', 'path': '/', 'secure': True, 'value': '29807030181260470' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'ww_rtkey', 'path': '/', 'secure': True, 'value': '8v5bqsk' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wxpay.vid', 'path': '/', 'secure': False, 'value': '1688850954847467' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.sid', 'path': '/', 'secure': True, 'value': 'GAcW9_16kP3sP9Y3_5UV7GfqYA4StuZhJNI0n9oBt6DF3nLAZAYKQnUyp5aPisWW' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wxpay.corpid', 'path': '/', 'secure': False, 'value': '1970325011434433' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.cs_ind', 'path': '/', 'secure': True, 'value': '' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.d2st', 'path': '/', 'secure': True, 'value': 'a7617125' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.c_gdpr', 'path': '/', 'secure': True, 'value': '0' }, { 'domain': '.qq.com', 'expiry': 1620307869, 'httpOnly': False, 'name': '_gid', 'path': '/', 'secure': False, 'value': 'GA1.2.871635060.1620200420' }, { 'domain': 'work.weixin.qq.com', 'expiry': 1620231955, 'httpOnly': True, 'name': 'ww_rtkey', 'path': '/', 'secure': False, 'value': '6i7qdku' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.ref', 'path': '/', 'secure': True, 'value': 'direct' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.vst', 'path': '/', 'secure': True, 'value': 'dc7mLDvc20hhczwLjKegaTE4YsdFK2oiYT33zpLsP7jBdcnq_Yf_DJ9A27NZKov7CGLqRtwNpk45pp3C9iQi-X9urzvD8r-g72RVcQPEZa-OEcQkiTrZ0obHP0GFfzV_xuB_o8fRgMTk6vLyHCrzpsXx01hzUrsftLGfGtcsPmqZaK_fj4Y9Ny_7SFdn8n7l0rxcjl8QXRbBgdIo7rI8M6FcXerS0kKNT9KbpxoUzL9cp8UNbnzXEFJ9JVcBHn4eOhYEVni0FBctEo84qi0Rag' }, { 'domain': '.qq.com', 'expiry': 1683293469, 'httpOnly': False, 'name': '_ga', 'path': '/', 'secure': False, 'value': 'GA1.2.2061398850.1620011906' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.vid', 'path': '/', 'secure': False, 'value': '1688850954847467' }, { 'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.ltype', 'path': '/', 'secure': True, 'value': '1' }, { 'domain': '.work.weixin.qq.com', 'expiry': 1622813470, 'httpOnly': False, 'name': 'wwrtx.i18n_lan', 'path': '/', 'secure': False, 'value': 'zh' }] db = shelve.open("../mydbs/cookies") db["cookies"] = cookies