Exemplo n.º 1
0
class App():
    def __init__(self):
        self.c = Controller()

    def case(self):
        # 通过导入测试类来实现生成测试集
        local.suite = unittest.TestLoader().loadTestsFromTestCase(ThreadDemo)

        # 生成空的结果集,用来存执行结果
        local.result = Result()

        # 运行case,并更新结果集,如执行状态
        local.res = local.suite.run(local.result)

        # 将结果通过测试手机名称进行区分
        logger.debug('当前线程的的名字:%s' % threading.current_thread().getName())
        # 当前线程的名称就是当前手机的名字
        result = {threading.current_thread().getName(): local.res}

        for deviceName, result in result.items():
            report_name = deviceName + '-' + time.strftime('%Y%m%d%H%M%S')
            html = HTMLTestAppRunner.HTMLTestRunner(stream=open(
                APP_REPORT.format('{}.html'.format(report_name)), 'wb'),
                                                    verbosity=2,
                                                    title='Test')
            # 这个方法就是生成报告的主要函数
            html.generateReport('', result)

    def run(self):
        threads = []
        self.c.server_start()
        if self.c.check_server():
            drivers = self.c.driver_start()
            logger.info('开始执行CASE!当前启动[%s]个DRIVER!' % drivers.qsize())
            # 根据driver的个数启动对应的case
            for driver in range((drivers.qsize())):
                # 根据driver启动多线程跑case,对每个线程通过手机名 命名
                t = threading.Thread(target=self.case,
                                     name=devices_name_queue.get())
                threads.append(t)
                t.start()
        for t in threads:
            t.join()

    def run_two(self):
        '''
        已经启动好 appium
        '''
        threads = []
        drivers = self.c.driver_start()
        logger.info('开始执行CASE!当前启动[%s]个DRIVER!' % drivers.qsize())
        # 根据driver的个数启动对应的case
        for driver in range((drivers.qsize())):
            # 根据driver启动多线程跑case,对每个线程通过手机名 命名
            t = threading.Thread(target=self.case,
                                 name=devices_name_queue.get())
            threads.append(t)
            t.start()
        for t in threads:
            t.join()
Exemplo n.º 2
0
class App(object):
    def __init__(self):
        self.controller = Controller()

    def case(self):
        #通过导入测试类来实现生成测试集
        suite = unittest.TestLoader().loadTestsFromTestCase(AppDemo)
        #实例化结果对象
        #生成一个空的结果集
        r = Result()

        #运行case,并更新结果集,记录正确的case 失败的case

        res = suite.run(r)

    def run(self):
        self.controller.server()
        driver = self.controller.driver()
        t = self.case()
Exemplo n.º 3
0
class App(object):
    def __init__(self):
        self.c = Controller()

    def case(self):
        # 通过导入测试类来实现生成测试集
        suite = unittest.TestLoader().loadTestsFromTestCase(QQDemo)
        # 生成一个空的结果集
        local.result = Result()

        # 运行case,并更新结果集,记录正确的case 失败的case
        res = suite.run(local.result)

        # 将结果通过测试手机名称进行区分
        logger.debug('当前线程的的名字:%s' % threading.current_thread().getName())
        # 当前线程的名字 就是当前运行手机的名字
        result = {threading.current_thread().getName(): res}

        for deviceName, result in result.items():
            html = HTMLTestAppRunner.HTMLTestRunner(stream=open(
                APPREPORT.format('{}.html'.format(deviceName)), "wb"),
                                                    verbosity=2,
                                                    title='测试')

            # 这个方法就是生成报告的主要函数
            html.generateReport('', result)

    def run(self):
        threads = []
        self.c.server()
        if self.c.test_server():
            drivers = self.c.driver()
            logger.info('开始执行CASE!当前启动[%s]个DRIVER!' % drivers.qsize())
            # 根据由多少个driver执行多少次case
            for case in range(drivers.qsize()):
                # 根据driver启动多线程跑case,对每个线程通过手机名 命名
                t = threading.Thread(target=self.case,
                                     name=device_name_queue.get())
                threads.append(t)
                t.start()
            for t in threads:
                t.join()
Exemplo n.º 4
0
class Run(object):
    def __init__(self):
        self.controller = Controller()
        self.name = self.controller.name

    def run(self):
        self.controller.start_server()
        if self.controller.test_server():
            self.controller.start_driver()
        suite = unittest.TestSuite()
        cases = unittest.defaultTestLoader.discover(CASEPATH)
        for case in cases:
            suite.addTest(case)
        f = open(REPORTPATH.format(self.name), 'wb')
        runner = HTMLTestRunner(f,
                                verbosity=1,
                                title=u'测试报告',
                                description=u'用例执行情况:')
        runner.run(suite)
        f.flush()
        f.close()
Exemplo n.º 5
0
 def __init__(self):
     self.controller = Controller()
Exemplo n.º 6
0

class ThreadDemo(unittest.TestCase):
    def __repr__(self):
        return 'appdemo'

    @classmethod
    def setUpClass(cls):
        cls.page = Page()

    def test_a_login(self):
        self.page.login_btn()
        self.page.account()
        self.page.password()
        self.page.login()
        self.assertTrue(self.page.check(self.test_a_login.__name__), 'msg')

    @classmethod
    def tearDownClass(cls):
        cls.page.quit()


if __name__ == '__main__':
    from lib.appController import Controller

    c = Controller()
    c.server_start()
    c.check_server()
    c.driver_start()
    unittest.main()
Exemplo n.º 7
0
 def __init__(self):
     self.controller = Controller()
     self.name = self.controller.name