예제 #1
0
       def setUp(self):
           cfg = configuration.Configuration()
           cfg_file = "../config/common.ini"
           cfg.fileConfig(cfg_file)
           device_id = cfg.getValue('COMMON', 'device_id')
           app_package = cfg.getValue('COMMON', 'app_package')
           app_activity = cfg.getValue('COMMON', 'start_activity')
           login_btn = cfg.getValue('LOGIN', 'login_btn')
           img_path = cfg.getValue('COMMON', 'img_path')
           vpn_btn = cfg.getValue('INDEX', 'vpn_btn')
           img_device_path = cfg.getValue('COMMON', 'img_device_path')
           mylogger = logger.Log("debug")

           device = adbtools.AdbTools(device_id)
           l = device.get_device_state()
           self.assertNotIn('error', l, 'device connect error.')

           mylogger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>start install app")
           common.install_app(device_id)

           l = myuiautomator.shellPIPE('adb shell pm list packages %s' % app_package)
           self.assertIn(app_package, l, 'install failure')

           mylogger.debug(">>>>>>>>>>>>>>>>>>>>>>>>start open app")
           common.start_app(app_package, app_activity, device_id, vpn_btn, login_btn, img_device_path, img_path)

           mylogger.debug(">>>>>>>>>>>>>>>>>>>>>screenShot after login")
           common.click_i_know(device_id, img_path)

           el = myuiautomator.find_element_by_id(device_id, vpn_btn)
           self.assertIsNotNone(el, 'can not find vpn btn,this is not index page.')
예제 #2
0
def send_file(file_new):
    cfg = configuration.Configuration()
    cfg_file = "../config/common.ini"
    cfg.fileConfig(cfg_file)
    smtpserver = cfg.getValue('EMAIL', 'smtp_server')
    user = cfg.getValue('EMAIL', 'email_user')
    password = cfg.getValue('EMAIL', 'email_pwd')
    sender = cfg.getValue('EMAIL', 'sender')
    receiver = cfg.getValue('EMAIL', 'receiver')

    file = open(file_new, 'r').read()

    format_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    subject = '天梯VPN UI自动化测试报告--' + format_time
    att = MIMEText(file, "html", "utf-8")
    att["Content-Type"] = "application/octet-stream"
    att["ContenT-Disposition"] = "attachment;filename = 'report.html '"

    msgRoot = MIMEMultipart('related')
    msgRoot['Subject'] = subject
    msgRoot['From'] = _format_addr(u'天梯VPN测试组 <%s>' % sender)
    msgRoot['To'] = _format_addr(u'天梯VPN项目组 <%s>' % receiver)
    msgRoot.attach(att)

    smtp = smtplib.SMTP()
    smtp.connect(smtpserver)
    smtp.login(user, password)
    smtp.sendmail(sender, receiver, msgRoot.as_string())
    smtp.quit()
예제 #3
0
    def test_run_whenWorkoutInProgress_skips(self, mocker):
        # Setup
        workouts_data = self.loadTestData("peloton_workouts_01.json")
        workouts_data[0]["status"] = "IN PROGRESS"
        output_directory = self.getOutputDir()
        config = configuration.Configuration(argparse.ArgumentParser())

        pToG = pelotonToGarmin.PelotonToGarmin()
        pelotonApiMock = mocker.patch(
            'peloton-to-garmin.pelotonApi.PelotonApi').return_value
        pelotonApiMock.getXWorkouts.return_value = workouts_data

        tcx_builderMock = mocker.patch('peloton-to-garmin.tcx_builder')
        garminClientMock = mocker.patch('peloton-to-garmin.garminClient')

        config.numActivities = 1

        # Act
        pToG.run(config)

        # Assert
        pelotonApiMock.getXWorkouts.assert_called_once_with(
            config.numActivities)
        pelotonApiMock.getWorkoutById.assert_not_called()
        pelotonApiMock.getWorkoutSamplesById.assert_not_called()
        pelotonApiMock.getWorkoutSummaryById.assert_not_called()
        tcx_builderMock.workoutSamplesToTCX.assert_not_called()
        garminClientMock.uploadToGarmin.assert_not_called()
예제 #4
0
 def setUp(self):
     cfg = configuration.Configuration()
     cfg_file = "../config/common.ini"
     cfg.fileConfig(cfg_file)
     device_id = cfg.getValue('COMMON', 'device_id')
     device = adbtools.AdbTools(device_id)
     l = device.get_device_state()
     self.assertNotIn('error', l, 'device connect error.')
예제 #5
0
def sendEmailInfo():
    cfg = configuration.Configuration()
    cfg_file = "../config/common.ini"
    cfg.fileConfig(cfg_file)
    report_path = cfg.getValue('COMMON', 'report_path')
    print('report_path:' + report_path)
    latest_report = sendEmail.new_report(report_path)
    sendEmail.send_file(latest_report)
예제 #6
0
 def tearDown(self):
     cfg = configuration.Configuration()
     cfg_file = "../config/common.ini"
     cfg.fileConfig(cfg_file)
     device_id = cfg.getValue('COMMON', 'device_id')
     app_package = cfg.getValue('COMMON', 'app_package')
     #print 'uninstall app...'
     l = myuiautomator.shellPIPE('adb -s %s uninstall %s' % (device_id, app_package))
     self.assertIn('Success', l, 'uninstall failure')
예제 #7
0
       def test_vpn(self):
           cfg = configuration.Configuration()
           cfg_file = "../config/common.ini"
           cfg.fileConfig(cfg_file)
           device_id = cfg.getValue('COMMON', 'device_id')
           vpn_btn = cfg.getValue('COMMON', 'vpn_btn')
           img_device_path = cfg.getValue('COMMON', 'img_device_path')
           target_path = cfg.getValue('COMMON', 'img_path')
           connect_server_btn = cfg.getValue('VPN', 'connect_server_btn')
           choose_server_btn = cfg.getValue('VPN', 'choose_vpnline')
           choose_workmode_btn = cfg.getValue('VPN', 'choose_workmode')

           #点击 连接标签 后截图
           el = common.click_and_screenshot_by_id(device_id, vpn_btn, '01_VPNTestCase', img_device_path, target_path)
           self.assertIsNotNone(el, 'connect vpn button not found.')

           #选择流量源后,选择某一条线路
           common.click_and_screenshot_by_id(device_id, choose_server_btn, '02_VPNTestCase', img_device_path, target_path)
           time.sleep(1)
           server_el = myuiautomator.find_element_by_name(device_id, u"香港")
           self.assertIsNotNone(server_el, 'choose server failure')
           common.click_and_screenshot_by_name(device_id, u"我不是路飞", '03_VPNTestCase', img_device_path, target_path)
           time.sleep(2)
           #common.click_and_screenshot_by_name(device_id, u"返回", '04_VPNTestCase', img_device_path, target_path)
           #time.sleep(2)
           key_cmd = 'adb shell input keyevent 4'
           myuiautomator.shellPIPE(key_cmd)
           time.sleep(2)
           vpn_el = myuiautomator.find_element_by_name(device_id, u"香港")
           self.assertIsNotNone(vpn_el, 'choose vpn server line failure')

           #点击 选择工作模式 后截图
           common.click_and_screenshot_by_id(device_id, choose_workmode_btn, '05_VPNTestCase', img_device_path, target_path)
           workmode_el = myuiautomator.find_element_by_name(device_id, u"全局代理")
           self.assertIsNotNone(workmode_el, 'click choose_workmode failure')
           common.click_and_screenshot_by_name(device_id, u"全局代理", '06_VPNTestCase', img_device_path, target_path)
           time.sleep(2)
           common.click_and_screenshot_by_name(device_id, u"返回", '07_VPNTestCase', img_device_path, target_path)
           time.sleep(2)
           workmode_el2 = myuiautomator.find_element_by_name(device_id, u"全局代理")
           self.assertIsNotNone(workmode_el2, 'choose work mode failure')

           # 点击 连接服务器按钮 后截图
           common.click_and_screenshot_by_id(device_id, connect_server_btn, '08_VPNTestCase', img_device_path, target_path)
           pop_el = myuiautomator.find_element_by_name(device_id, u"确定")
           if pop_el is not None:
             common.click_and_screenshot_by_name(device_id, u"确定", '09_VPNTestCase', img_device_path, target_path)
             time.sleep(5)
             el3 = myuiautomator.find_element_by_name(device_id, '00:00:00')
             self.assertIsNone(el3, 'start connect server failure')
             common.click_and_screenshot_by_id(device_id, connect_server_btn, '10_VPNTestCase', img_device_path, target_path)
             time.sleep(5)
             el4 = myuiautomator.find_element_by_name(device_id, '00:00:00')
             self.assertIsNotNone(el4, 'stop server failure')
           else:
             print 'can not find button...'
예제 #8
0
def generateReport():
    cfg = configuration.Configuration()
    cfg_file = "../config/common.ini"
    cfg.fileConfig(cfg_file)
    report_path = cfg.getValue('COMMON', 'report_path')

    format_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    report_name = report_path + format_time + "_result.html"
    fp = open(report_name, 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'测试报告', description=u'用例执行结果')
    runner.run(createTestSuite())
    fp.close()
    time.sleep(5)
예제 #9
0
def createTestSuite():
    cfg = configuration.Configuration()
    cfg_file = "../config/common.ini"
    cfg.fileConfig(cfg_file)
    case_path = cfg.getValue('COMMON', 'cases_path')

    testunit = unittest.TestSuite()
    discover = unittest.defaultTestLoader.discover(case_path, pattern = 'test_*.py', top_level_dir = None)
    #discover = unittest.defaultTestLoader.discover(case_path, pattern = 'test_vpn.py', top_level_dir = None)
    for test_suite in discover:
        for test_case in test_suite:
            testunit.addTests(test_case)
            print(testunit)
    return testunit
                input("Press the <ENTER> key to quit...")
                raise e

        logger.info("Done!")
        logger.info(
            "Your Garmin TCX files can be found in the Output directory: " +
            config.output_directory)

        if config.pause_on_finish:
            input("Press the <ENTER> key to continue...")


##############################
# Program Starts Here
##############################
if __name__ == "__main__":
    config = configuration.Configuration(argparse.ArgumentParser())
    logger = config.logger

    if config.polling_enabled:
        logger.info(
            "Begin polling. Fetching {} activities, every {} seconds.".format(
                config.numActivities, config.polling_interval_seconds))
        while True:
            PelotonToGarmin.run(config)
            logger.info("Sleeping for: {}seconds".format(
                config.polling_interval_seconds))
            time.sleep(config.polling_interval_seconds)
    else:
        PelotonToGarmin.run(config)
예제 #11
0
#!/usr/bin/evn python
# -*- coding:utf-8 -*-
__author__ = 'admin'

import subprocess
import re
import time
import xml.etree.cElementTree as ET
from lib import configuration
from lib import logger

cfg = configuration.Configuration()
cfg_file = "../config/common.ini"
cfg.fileConfig(cfg_file)
ui_path = cfg.getValue('COMMON', 'ui_xml')
img_path = cfg.getValue('COMMON', 'img_path')
device_id = cfg.getValue('COMMON', 'device_id')
install_btn = cfg.getValue('INSTALL', 'install_btn')
mylogger = logger.Log("debug")


def shellPIPE(cmd):

    p = subprocess.Popen(cmd,
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    out, err = p.communicate()
    return out

예제 #12
0
    def testMine(self):
        cfg = configuration.Configuration()
        cfg_file = "../config/common.ini"
        cfg.fileConfig(cfg_file)
        device_id = cfg.getValue('COMMON', 'device_id')
        mine_id = cfg.getValue('INDEX', 'mine_btn')
        img_device_path = cfg.getValue('COMMON', 'img_device_path')
        target_path = cfg.getValue('COMMON', 'img_path')
        mykey_id = cfg.getValue('MINE', 'see_my_key')
        copykey_id = cfg.getValue('MINE', 'copy_my_key')
        myblock_id = cfg.getValue('MINE', 'see_my_block')
        close_block_id = cfg.getValue('MINE', 'close_my_block')
        myaccount_id = cfg.getValue('MINE', 'see_my_account')
        myflow_share_id = cfg.getValue('MINE', 'see_my_flow_share')
        myflow_share_confirm_id = cfg.getValue('MINE', 'myflow_share_confirm')
        mysetting_id = cfg.getValue('MINE', 'see_my_setting')

        # 点击我的图标
        el = common.click_and_screenshot_by_id(device_id, mine_id,
                                               '01_MineTestCase',
                                               img_device_path, target_path)
        self.assertIsNotNone(el, 'mine button not found.')
        time.sleep(2)
        mykey_el = myuiautomator.find_element_by_name(device_id, u"查看我的私钥")
        self.assertIsNotNone(mykey_el, 'into mine page failure.')

        # 点击 查看我的私钥
        common.click_and_screenshot_by_id(device_id, mykey_id,
                                          '02_MineTestCase', img_device_path,
                                          target_path)
        copykey_el = myuiautomator.find_element_by_name(device_id, u"备份私钥")
        self.assertIsNotNone(copykey_el, 'see mine key failure.')
        common.click_and_screenshot_by_id(device_id, copykey_id,
                                          '03_MineTestCase', img_device_path,
                                          target_path)
        time.sleep(2)

        # 点击 区块高度
        el1 = common.click_and_screenshot_by_id(device_id, myblock_id,
                                                '04_MineTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el1, 'block img not find.')
        block_el = myuiautomator.find_element_by_name(device_id, u"区块详情")
        self.assertIsNotNone(block_el, 'see my block failure.')
        common.click_and_screenshot_by_id(device_id, close_block_id,
                                          '05_MineTestCase', img_device_path,
                                          target_path)
        time.sleep(2)

        # 点击 我的账单
        el2 = common.click_and_screenshot_by_id(device_id, myaccount_id,
                                                '06_MineTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el2, 'my account img not find.')
        myaccount_el = myuiautomator.find_element_by_name(device_id, u"待结算账单")
        self.assertIsNotNone(myaccount_el, 'see my account failure.')
        # 点击 待结算账单
        common.click_and_screenshot_by_name(device_id, u"待结算账单",
                                            '07_MineTestCase', img_device_path,
                                            target_path)
        time.sleep(2)
        key_cmd = 'adb shell input keyevent 4'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(1)
        key_cmd = 'adb shell input keyevent 4'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(1)

        # 点击 转账
        el3 = common.click_and_screenshot_by_id(device_id, myflow_share_id,
                                                '08_MineTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el3, 'my flow share img not find.')
        common.click_and_screenshot_by_id(device_id, myflow_share_confirm_id,
                                          '09_MineTestCase', img_device_path,
                                          target_path)
        time.sleep(2)
        key_cmd = 'adb shell input keyevent 4'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(1)

        # 点击 设置
        el4 = common.click_and_screenshot_by_id(device_id, mysetting_id,
                                                '10_MineTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el4, 'setting button not find.')
        setting_el = myuiautomator.find_element_by_name(device_id, u"挖币设置")
        self.assertIsNotNone(setting_el, 'into setting page error.')

        key_cmd = 'adb shell input keyevent 4'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(1)
예제 #13
0
def get_ini_value(ini_file, ini_title, ini_key):
    cfg = configuration.Configuration()
    cfg.fileConfig(ini_file)
    ini_value = cfg.getValue(ini_title, ini_key)
    return ini_value
예제 #14
0
    def test_dig(self):
        cfg = configuration.Configuration()
        cfg_file = "../config/common.ini"
        cfg.fileConfig(cfg_file)
        device_id = cfg.getValue('COMMON', 'device_id')
        dig_id = cfg.getValue('INDEX', 'dug_btn')
        img_device_path = cfg.getValue('COMMON', 'img_device_path')
        target_path = cfg.getValue('COMMON', 'img_path')
        invite_friends_id = cfg.getValue('DIG', 'invite_friends_btn')
        evaluation_id = cfg.getValue('DIG', 'evaluation_btn')
        start_invite_id = cfg.getValue('DIG', 'start_invite_btn')
        cancel_invite_id = cfg.getValue('DIG', 'invite_cancel_btn')
        share_invite_id = cfg.getValue('DIG', 'share_invite_img')
        back_id = cfg.getValue('DIG', 'back_btn')
        start_dig_id = cfg.getValue('DIG', 'start_dig_btn')

        # 点击挖币图标
        el = common.click_and_screenshot_by_id(device_id, dig_id,
                                               '01_DigTestCase',
                                               img_device_path, target_path)
        self.assertIsNotNone(el, 'dig button not found.')
        time.sleep(2)
        # 点击邀请好友图标
        el1 = common.click_and_screenshot_by_id(device_id, invite_friends_id,
                                                '02_DigTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el1, 'invite friends button not found.')
        invite_el = myuiautomator.find_element_by_name(device_id, u"我的邀请码")
        self.assertIsNotNone(invite_el, 'invite friends failure.')
        # 点击立即邀请
        common.click_and_screenshot_by_id(device_id, start_invite_id,
                                          '03_DigTestCase', img_device_path,
                                          target_path)
        invite_el1 = myuiautomator.find_element_by_name(device_id, u"信息")
        self.assertIsNotNone(invite_el1, 'invite friends failure.')
        # 关闭邀请页面
        common.click_and_screenshot_by_id(device_id, cancel_invite_id,
                                          '04_DigTestCase', img_device_path,
                                          target_path)
        cancel_invite_el = myuiautomator.find_element_by_id(
            device_id, cancel_invite_id)
        self.assertIsNone(cancel_invite_el, 'cancel invite failure.')
        # 点击分享邀请页面
        el2 = common.click_and_screenshot_by_id(device_id, share_invite_id,
                                                '05_DigTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el2, 'share invite not find.')
        time.sleep(2)
        invite_el2 = myuiautomator.find_element_by_name(device_id, u"信息")
        self.assertIsNotNone(invite_el2, 'share invite failure.')
        # 关闭邀请页面
        common.click_and_screenshot_by_id(device_id, cancel_invite_id,
                                          '06_DigTestCase', img_device_path,
                                          target_path)
        cancel_invite_el1 = myuiautomator.find_element_by_id(
            device_id, cancel_invite_id)
        self.assertIsNone(cancel_invite_el1, 'cancel invite failure.')
        time.sleep(1)
        # 返回
        #el3 = common.click_and_screenshot_by_id(device_id, back_id, 'backdig', img_device_path, target_path)
        #self.assertIsNotNone(el3, 'back button not find.')
        key_cmd = 'adb shell input keyevent 4'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(2)
        back_el = myuiautomator.find_element_by_name(device_id, u"挖币")
        self.assertIsNotNone(back_el, 'back dig page failure.')

        # 点击能力评估
        el3 = common.click_and_screenshot_by_id(device_id, evaluation_id,
                                                '07_DigTestCase',
                                                img_device_path, target_path)
        self.assertIsNotNone(el3, 'evaluation button not find.')
        evaluation_el = myuiautomator.find_element_by_name(
            device_id, u"挖币评分解读")
        self.assertIsNotNone(evaluation_el, 'show evaluation info failure.')
        # 点击签到
        el4 = common.click_and_screenshot_by_name(device_id, u"签到",
                                                  '08_DigTestCase',
                                                  img_device_path, target_path)
        if el4 is not None:
            time.sleep(1)
            signin_el = myuiautomator.find_element_by_name(device_id, u"已签")
            self.assertIsNotNone(signin_el, 'sign in failure.')
        else:
            signin_el = myuiautomator.find_element_by_name(device_id, u"已签")
            self.assertIsNotNone(signin_el, 'sign in failure.')
        # 返回
        key_cmd = 'adb shell input keyevent 4'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(2)
        back_el2 = myuiautomator.find_element_by_name(device_id, u"挖币")
        self.assertIsNotNone(back_el2, 'back dig page failure.')
        time.sleep(2)

        # 点击开始按钮
        common.click_and_screenshot_by_id(device_id, start_dig_id,
                                          '10_DigTestCase', img_device_path,
                                          target_path)
        time.sleep(2)
        key_cmd = 'adb shell input keyevent 3'
        myuiautomator.shellPIPE(key_cmd)
        time.sleep(1)