def set_price(self,driver): self.locateUtil = LocateUtil(driver) # 获取当前交易对价格 current_price = self.locateUtil.text_handle( self.currentPriceId,"id") # 低于当前价格的10%挂单 buying_input_value = round(float(current_price) * (1 - 0.1),2) self.locateUtil.input_handle( self.priceInputId, buying_input_value,"id")
def set_buying_amount(self,driver): '''复用-购买数量输入框''' self.locateUtil = LocateUtil(driver) # 获取当前交易对价格 current_price = self.locateUtil.text_handle( self.currentPriceId,"id") # 按照15U买入 buying_amount = round(15 / float(current_price),3) self.locateUtil.input_handle(self.amountInputId, buying_amount,"id")
class TestMainTradeArea(unittest.TestCase): @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.main_tradeArea = MainTradeArea() def test_01_enter_trade_page(self): self.locateUtil.click_handle(self.main_tradeArea.btcPair) self.assertTrue( self.locateUtil.assert_find_ele(self.main_tradeArea.btcPair), '进入{pair}交易对页面失败'.format(pair=self.main_tradeArea.btcPair)) @classmethod def tearDownClass(self): time.sleep(20) App.quit()
class TestQuitLogin(unittest.TestCase): @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.switchUser = SwitchUser() globals()["alreadyLogin"] = False # 是否登录来控制执行不同的用例 unittest.skipIf(not EnvSwitch().is_online_env(),'测试环境跳过检测弹窗') def test_00_has_Toast(self): if self.locateUtil.assert_find_ele('close','id'): self.locateUtil.click_handle("close", "id") else: return True def test_01_enter_person_page(self): '''进入个人页面''' if self.locateUtil.assert_find_ele(self.login.leftHeaderId[0],"id"): globals()["alreadyLogin"] = False # self.locateUtil.click_handle(self.login.leftHeaderId[0], "id") self.assertTrue(self.locateUtil.assert_find_ele(self.login.title), '进入个人中心页面失败') # 已经登录 elif self.locateUtil.assert_find_ele(self.login.leftHeaderId[1],"id"): globals()["alreadyLogin"] = False print("用户已经登录") @classmethod def tearDownClass(self): time.sleep(10) App.quit()
class TradePairPage: def __init__(self): self.pair = "ETH/USDT" self.buyingBtnId = "btn_buy" self.optional = ('加自选','删自选') self.currEntrustAssertText = "当前委托" self.entrustSucAssertText = "成交均价/委托价" self.allCancelBtn = "撤销全部" self.cancelAffirmBtn = "确定" self.switchEntrustId = "orderType" self.marketEntrust = "市价委托" self.planEntrust = "计划委托" self.priceInputId = "inputEt" self.amountInputId = "transaction_quota" self.currentPriceId = "current_price" self.entrustMarkId = "tradeTypeTv" # 当前委托 下 订单的标签:如:计划委托 self.useableId = "useable" # 可用数 self.sumbitBtnId = "btn_handle" # 买入按钮 self.moneyPasswordId = "moneyPasswordEt" # 资金密码输入框 self.noPasswordId = "noPassword" # 免输入按钮 self.submitBtnId = "submitBtn" # 资金密码确认框 def set_price(self,driver): self.locateUtil = LocateUtil(driver) # 获取当前交易对价格 current_price = self.locateUtil.text_handle( self.currentPriceId,"id") # 低于当前价格的10%挂单 buying_input_value = round(float(current_price) * (1 - 0.1),2) self.locateUtil.input_handle( self.priceInputId, buying_input_value,"id") def set_buying_amount(self,driver): '''复用-购买数量输入框''' self.locateUtil = LocateUtil(driver) # 获取当前交易对价格 current_price = self.locateUtil.text_handle( self.currentPriceId,"id") # 按照15U买入 buying_amount = round(15 / float(current_price),3) self.locateUtil.input_handle(self.amountInputId, buying_amount,"id") def get_userInfo(self,fileName): '''获取用户文本信息''' path = self.filePath = os.path.abspath(os.path.join(__file__,"../../../..","userdata/{name}.json".format(name=fileName))) return JsonUtil().read_json(path)
class TestLogin(unittest.TestCase): @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.login = Login() globals()["alreadyLogin"] = False # 是否登录来控制执行不同的用例 unittest.skipIf(not EnvSwitch().is_online_env(),'测试环境跳过检测弹窗') def test_00_has_Toast(self): if self.locateUtil.assert_find_ele('close','id'): self.locateUtil.click_handle("close", "id") else: return True def test_01_enter_person_page(self): '''进入个人页面''' if self.locateUtil.assert_find_ele(self.login.leftHeaderId[0],"id"): globals()["alreadyLogin"] = False self.locateUtil.click_handle(self.login.leftHeaderId[0], "id") self.assertTrue(self.locateUtil.assert_find_ele(self.login.title), '进入个人中心页面失败') # 已经登录 elif self.locateUtil.assert_find_ele(self.login.leftHeaderId[1],"id"): globals()["alreadyLogin"] = True print("用户已经登录") def test_02_enter_login_page(self): '''进入登录页面''' if globals()["alreadyLogin"] == True : return True # 已经登录跳过测试 self.locateUtil.click_handle(self.login.enterLogin) self.assertTrue(self.locateUtil.assert_find_ele( self.login.assertLogin), '进入登录页面失败') def test_03_input_phone_with_password(self): '''输入邮箱和密码''' if globals()["alreadyLogin"] == True: return True # 已经登录跳过测试 info = self.login.get_userInfo('userInfo_online') if EnvSwitch().is_online_env() else self.login.get_userInfo('userInfo_sta') self.locateUtil.input_handle(self.login.phoneInput,info['account']) self.locateUtil.input_handle(self.login.passwordInputId, info['password'],"id") self.locateUtil.click_handle(self.login.sumbitLoginId,"id") input("滑块验证码操作完毕后请按Enter键") # self.assertTrue(self.locateUtil.assert_find_ele(self.login.assertGoogleText),"输入邮箱和密码失败") def test_04_input_email_verify(self): '''输入验证码,并提交''' if globals()["alreadyLogin"] == True: return True # 已经登录跳过测试 self.login.select_checkout_method(self.driver) # 验证码方式 self.assertTrue(self.locateUtil.assert_find_ele("账号保护"),"登录失败") @classmethod def tearDownClass(self): time.sleep(10) App.quit()
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.tradePairPage = TradePairPage() self.bottomNav = BottomNav()
class TestTradePair(unittest.TestCase): @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.tradePairPage = TradePairPage() self.bottomNav = BottomNav() def test_01_enter_tradePage(self): '''进入交易页面''' self.locateUtil.click_handle( self.bottomNav.navNameList[1]) self.assertTrue(self.locateUtil.assert_find_ele( "最新价"), '进入交易页面失败') def test_02_select_nav_inMiddle(self): '''选中中间导航栏的usdt''' self.locateUtil.click_handle(self.tradePairPage.pair[-4:],"xpath_accessbility") self.assertTrue(self.locateUtil.assert_find_ele( "/USDT"), '点击usdt导航失败') def test_03_enter_tradePairPage(self): '''点击交易对进入交易队页面''' self.locateUtil.click_handle( self.tradePairPage.pair) self.assertTrue(self.locateUtil.assert_find_ele( self.tradePairPage.buyingBtnId,"id"), '点击交易对进入k线界面失败') def test_04_click_buyingBtn(self): '''点击买入按钮,进入交易对交易页面''' self.locateUtil.click_handle( self.tradePairPage.buyingBtnId,"id") self.assertTrue(self.locateUtil.assert_find_ele( self.tradePairPage.currEntrustAssertText), '进入交易对买入界面失败') def test_05_buying_limit(self): '''限价单挂单''' self.tradePairPage.set_price(self.driver) self.tradePairPage.set_buying_amount(self.driver) self.locateUtil.click_handle( self.tradePairPage.sumbitBtnId, "id") # 资金密码 info = self.tradePairPage.get_userInfo('userInfo_alp01') self.locateUtil.input_handle(self.tradePairPage.moneyPasswordId,info["fundPassword"],"id") self.locateUtil.click_handle(self.tradePairPage.noPasswordId,"id") self.locateUtil.click_handle(self.tradePairPage.submitBtnId,"id") self.assertTrue(self.locateUtil.assert_find_ele( self.tradePairPage.entrustSucAssertText), '买入限价单提交失败') def test_06_cancal_all(self): '''撤销全部挂单''' self.locateUtil.click_handle( self.tradePairPage.allCancelBtn) self.locateUtil.click_handle(self.tradePairPage.cancelAffirmBtn) self.assertFalse(self.locateUtil.assert_find_ele( self.tradePairPage.entrustSucAssertText), '撤销全部-失败') def test_07_switch_market_entrust(self): '''切换市价委托类型''' self.locateUtil.click_handle( self.tradePairPage.switchEntrustId,"id") self.locateUtil.click_handle( self.tradePairPage.marketEntrust) self.assertTrue(self.locateUtil.assert_find_ele( self.tradePairPage.marketEntrust), '切换委托类型-失败') def test_08_buying_market(self): '''确认买入市价委托''' self.tradePairPage.set_buying_amount(self.driver) # 挂单前可用USDT pre_amount = self.locateUtil.text_handle(self.tradePairPage.useableId,"id") self.locateUtil.click_handle( self.tradePairPage.sumbitBtnId, "id") # 挂单后可用USDT now_amount = self.locateUtil.text_handle(self.tradePairPage.useableId,"id") print("挂单前可用{pre},现在可用{now}".format(pre=pre_amount,now=now_amount)) self.assertTrue(pre_amount != now_amount, '买入市价单-失败') def test_09_switch_plan_entrust(self): '''切换plan委托类型''' self.locateUtil.click_handle( self.tradePairPage.switchEntrustId,"id") self.locateUtil.click_handle( self.tradePairPage.planEntrust) self.assertTrue(self.locateUtil.assert_find_ele( self.tradePairPage.planEntrust), '切换委托类型-失败') def test_10_buying_plan(self): '''计划委托-买入''' self.tradePairPage.set_price(self.driver) # 写入触发价 current_price = self.locateUtil.text_handle( self.tradePairPage.currentPriceId,"id") self.locateUtil.input_handle("价格",round(float(current_price) * (1 - 0.15),2)) self.tradePairPage.set_buying_amount(self.driver) self.locateUtil.click_handle( self.tradePairPage.sumbitBtnId, "id") self.assertTrue(self.locateUtil.assert_find_ele( self.tradePairPage.entrustMarkId,"id"), '买入计划单失败') def test_11_cancal_all(self): '''撤销全部挂单''' self.locateUtil.click_handle( self.tradePairPage.allCancelBtn) self.locateUtil.click_handle(self.tradePairPage.cancelAffirmBtn) self.assertFalse(self.locateUtil.assert_find_ele( self.tradePairPage.entrustSucAssertText), '撤销全部-失败') @classmethod def tearDownClass(cls): time.sleep(10) App.quit()
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.staking_page = StakingPage() self.kingkong = KingKongDistrict()
class TestStaking(unittest.TestCase): @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.staking_page = StakingPage() self.kingkong = KingKongDistrict() def test_00_has_Toast(self): if self.locateUtil.assert_find_ele('close','id'): self.locateUtil.click_handle("close", "id") else: return True def test_01_enter_staking(self): '''进入锁仓挖矿页面''' self.locateUtil.click_handle( self.kingkong.staking) self.assertTrue(self.locateUtil.assert_find_ele( self.staking_page.title),'进入锁仓挖矿页面失败') def test_02_search_coin(self): '''搜索币种''' self.locateUtil.input_handle(self.staking_page.searchCoin,self.staking_page.searchCoinName) self.assertTrue(self.locateUtil.assert_find_ele("{coin}矿池".format(coin=self.staking_page.searchCoinName)),'搜索结果出错') def test_03_enter_lock_immediately(self): '''进入立即锁仓页面,查找-我的锁仓''' self.locateUtil.click_handle( self.staking_page.lockImmediately) self.assertTrue(self.locateUtil.assert_find_ele( self.staking_page.myLock), '进入锁仓页面失败') def test_04_assert_locked_amount(self): '''立即锁仓页面,断言 锁仓数量''' locked_amount = "0.1" self.locateUtil.input_handle( self.staking_page.lockedAmountInput,locked_amount, 'id') self.locateUtil.click_handle(self.staking_page.agreementRadio,"id") # 点击 我已阅读 点击2次才能生效 self.locateUtil.click_handle( self.staking_page.agreementRadio, "id") self.locateUtil.click_handle( self.staking_page.lockImmediately) self.assertEqual(locked_amount,self.locateUtil.text_handle(self.staking_page.sumbitLockedBtn,'id')) def test_05_sumbit_locked(self): '''检查确认锁仓是否成功''' self.locateUtil.click_handle("confirm_btn",'id') self.assertTrue(self.locateUtil.assert_find_ele( self.staking_page.lookupOrder), '确认锁仓失败') def test_06_enter_order_page(self): '''进入锁仓订单页面''' self.locateUtil.click_handle( '查看订单') self.assertTrue(self.locateUtil.assert_find_ele( self.staking_page.waitForLock), '进入锁仓订单页面失败') @classmethod def tearDownClass(self): time.sleep(10) App.quit()
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.recharge = RechargeWithdrawal()
class TestRechargeWithdrawal(unittest.TestCase): '''充提测试''' @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.recharge = RechargeWithdrawal() unittest.skipIf(not EnvSwitch().is_online_env(), '测试环境跳过检测弹窗') def test_00_has_Toast(self): if self.locateUtil.assert_find_ele('close', 'id'): self.locateUtil.click_handle("close", "id") else: return True def test_01_enter_recharge_page(self): '''进入充提币页面''' # 找一个金刚区节点,代表加载成功。 if self.locateUtil.assert_find_ele(self.recharge.staking): self.locateUtil.swipe_left(660, 640) # 滑动金刚区 self.locateUtil.click_handle(self.recharge.recharge) self.assertTrue( self.locateUtil.assert_find_ele(self.recharge.selectCoin), "进入充提页面失败") def test_02_search_coin(self): '''进入币种充币页面''' self.locateUtil.click_handle(self.recharge.searchData[0]) self.assertTrue( self.locateUtil.assert_find_ele(self.recharge.shareQRcodeId, "id"), "进入充币页面失败") def test_03_switch_withdrawal(self): '''切换到提币页面''' info = self.recharge.get_userInfo( 'userInfo_alp01' ) if self.recharge.isChain else self.recharge.get_userInfo( 'userInfo_alp02') self.locateUtil.click_handle(self.recharge.withdrawal) if self.recharge.isChain: # 测站内还是链上 self.locateUtil.input_handle( self.recharge.withdrawalAddressId, info['recharge'][self.recharge.searchData[0] + "_" + self.recharge.searchData[1]], "id") else: #站内转 self.locateUtil.click_handle(self.recharge.extractFromServer) self.locateUtil.input_handle(self.recharge.withdrawalAddressId, info['OtherUID'], 'id') self.locateUtil.input_handle(self.recharge.withdrawalAmountId, self.recharge.searchData[2], "id") self.locateUtil.click_handle(self.recharge.withdrawalSumbitId, "id") # 账户确认 self.locateUtil.click_handle(self.recharge.confirm) code = GoogleCodeBuilder().get_code(info['googleKey']) self.locateUtil.input_handle(self.recharge.fundPasswordId, info["fundPassword"], "id") self.locateUtil.input_handle(self.recharge.googlePasswordId, code, "id") self.locateUtil.click_handle(self.recharge.verifySumbitId, "id") self.assertTrue( self.locateUtil.assert_find_ele(self.recharge.withdrawalDetail), "提币失败,没有进入提币详情页面") @classmethod def tearDownClass(self): time.sleep(10) App.quit()
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.bottomNav = BottomNav()
class TestBottomNav(unittest.TestCase): @classmethod def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.bottomNav = BottomNav() def test_01_enter_tradepage(self): self.locateUtil.click_handle(self.bottomNav.navNameList[1]) self.assertTrue(self.locateUtil.assert_find_ele("最新价"), '进入交易页面失败') def test_02_enter_contractpage(self): '''进入交易页面''' self.locateUtil.get_ele_by_id("ll_tap").find_element_by_xpath( "//*[@text='合约']").click() self.assertTrue(self.locateUtil.assert_find_ele("永续合约"), '进入合约页面失败') def test_03_enter_financingpage(self): '''进入理财页面''' self.locateUtil.click_handle(self.bottomNav.navNameList[3]) self.assertTrue(self.locateUtil.assert_find_ele("理财资产"), '进入理财页面失败') def test_04_enter_propertypage(self): '''进入资产页面''' self.locateUtil.click_handle(self.bottomNav.navNameList[4]) self.assertTrue(self.locateUtil.assert_find_ele("钱包账户"), '进入资产失败') def test_05_enter_homepage(self): '''进入首页''' self.locateUtil.click_handle(self.bottomNav.navNameList[0]) self.assertTrue(self.locateUtil.assert_find_ele("币客精选"), '进入首页失败') @classmethod def tearDownClass(self): time.sleep(10) App.quit()
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.main_tradeArea = MainTradeArea()
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.switchUser = SwitchUser() globals()["alreadyLogin"] = False # 是否登录来控制执行不同的用例
def setUpClass(self): self.driver = App.start() self.locateUtil = LocateUtil(self.driver) self.segmentTab = SegmentTab()