Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()