class TestMerketFund: def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.market = MarketPage(self.driver) self.market_fund = MarketFundPage(self.driver) @pytest.fixture(scope='function') def clean(self): yield self.xueqiu.goto_xueqiu() def test_fund(self, clean): self.xueqiu.goto_market().goto_fund().goto_index_rank() increase_ranges = self.market_fund.all_increase_range() print(increase_ranges, end='11111\n') list_positive = sorted( [item for item in increase_ranges if not item.startswith('-')], reverse=True) list_negative = sorted( [item for item in increase_ranges if item.startswith('-')], reverse=False) sorted_list = list_positive + list_negative print(sorted_list, end='22222\n') assert increase_ranges == sorted_list
class TestLoginPage: def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.profile = ProfilePage(self.driver) @pytest.fixture(scope='function') def setting_for_login_by_phone(self): yield self.profile.close_msg() self.profile.goto_profile() def test_login_by_phone(self, setting_for_login_by_phone): self.xueqiu.goto_profile().login_by_phone('18312121212', '1212') assert '验证码已过期' in self.profile.pageSource() def test_login_by_wechat(self): self.profile.login_by_wechat() assert '您尚未安装微信,请先安装微信' in self.profile.get_toast()
class TestSearch: def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.search = SearchPage(self.driver) @pytest.fixture(scope='function') def pre_search(self): self.xueqiu.goto_search() yield self.search.cancel_search() @pytest.mark.parametrize('key, name, stockCode, price', [('alibaba', '阿里巴巴', 'BABA', 160), ('xiaomi', '小米', '01810', 8.0), ('google', '谷歌', 'GOOGL', 1000)]) def test_search(self, key, name, stockCode, price, pre_search): self.search.search(key).press_search() assert name in self.search.get_name(stockCode) assert price < self.search.get_price(stockCode)
class TestAddStock: def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.optional = OptionalPage(self.driver) self.search = SearchPage(self.driver) def teardown_class(self): self.xueqiu.goto_xueqiu() @pytest.fixture(scope="function") def pre_01(self): self.xueqiu.goto_optional().goto_search() yield self.search.cancel_search() @pytest.fixture(scope="function") def pre_02(self): self.optional.goto_search() yield self.search.cancel_search() @allure.story("添加股票") def test_01_add_stock(self, pre_01): self.search.search('pingan').press_search() self.search.add_searched_stock('平安银行') assert '已添加' == self.search.searched_stock_status('平安银行') @allure.story("搜索已添加的股票,显示为'已添加'") def test_02_search_again(self, pre_02): self.search.search('pingan').press_search() assert '已添加' == self.search.searched_stock_status('平安银行') @allure.story("删除股票") def test_03_delete_stock(self): self.optional.delete_stock("平安银行") assert '平安银行' not in self.optional.all_stockName_in_selected_list()
def __new__(cls, *args, **kwargs): if not XueqiuDriver._driver: # app未启动,则启动app print("首次启动app") XueqiuDriver._driver = super(XueqiuDriver, cls).__new__(cls, *args, **kwargs) else: # app已启动,则设置app回到首页 print("非首次启动app,回到雪球首页") # XueqiuDriver._driver.start_activity(Driver.APP, Driver.ACTIVITY) cls.driver.start_activity(Driver.APP, Driver.ACTIVITY) cls.xueqiu = XueqiuPage(cls.driver) cls.xueqiu.close_update().skip_ads().skip_tv().close_ib() WebDriverWait(cls.driver, 15, 0.5, ignored_exceptions=TimeoutException) \ .until(EC.presence_of_element_located((By.XPATH, '//*[@text="雪球"]'))) return XueqiuDriver._driver
class TestLogin: def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.profile = ProfilePage(self.driver) self.login = LoginPage(self.driver) def teardown_class(self): self.login.goto_profile() self.profile.goto_xueqiu() @pytest.fixture(scope='function') def close_msg(self): yield self.login.close_msg() def test_login_01_wrong_phone(self, close_msg): self.xueqiu.goto_profile().goto_login_more() self.login.login('1234567890', '888888') assert self.login.login_msg() == '手机号码填写错误' def test_login_02_wrong_psw(self, close_msg): self.login.login('18312121111', '888888') assert self.login.login_msg() == '用户名或密码错误'
def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.profile = ProfilePage(self.driver)
def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.optional = OptionalPage(self.driver) self.search = SearchPage(self.driver)
def setup_class(self): self.driver = XueqiuDriver() self.xueqiu = XueqiuPage(self.driver) self.market = MarketPage(self.driver) self.market_fund = MarketFundPage(self.driver)
return cls.driver class XueqiuDriver(Driver): _driver = None def __new__(cls, *args, **kwargs): if not XueqiuDriver._driver: # app未启动,则启动app print("首次启动app") XueqiuDriver._driver = super(XueqiuDriver, cls).__new__(cls, *args, **kwargs) else: # app已启动,则设置app回到首页 print("非首次启动app,回到雪球首页") # XueqiuDriver._driver.start_activity(Driver.APP, Driver.ACTIVITY) cls.driver.start_activity(Driver.APP, Driver.ACTIVITY) cls.xueqiu = XueqiuPage(cls.driver) cls.xueqiu.close_update().skip_ads().skip_tv().close_ib() WebDriverWait(cls.driver, 15, 0.5, ignored_exceptions=TimeoutException) \ .until(EC.presence_of_element_located((By.XPATH, '//*[@text="雪球"]'))) return XueqiuDriver._driver if __name__ == "__main__": a = XueqiuDriver() xue = XueqiuPage(a) xue.goto_profile() b = XueqiuDriver() XueqiuPage(b).goto_trade()
def goto_xueqiu(self): self.find_and_click(self._action_back) return XueqiuPage(self.driver)