def get_suite(i):
    print("get_suite里的", i)
    suite = unittest.TestSuite()
    suite.addTest(CaseTest("test_01", param=i))
    suite.addTest(CaseTest("test_02", param=i))
    suite.addTest(CaseTest("test_03", param=i))
    # unittest.TextTestRunner().run(suite)

    write_file = WriteUserCommand()
    device = write_file.get_value('user_info_' + str(i), 'deviceName')
    html_file = "../report/testReport" + str(i) + ".html"
    with open(html_file, "wb") as fp:
        HTMLTestRunner.HTMLTestRunner(stream=fp,
                                      title="自动化测试",
                                      description=device +
                                      "的自动化测试结果").run(suite)
Exemple #2
0
 def Android_driver(self, i):
     write_file = WriteUserCommand()
     devices = write_file.Get_value('user_info_{}'.format(i), 'deviceName')
     port = write_file.Get_value('user_info_{}'.format(i), 'port')
     # print(devices,port)
     capabilites = {
         "platformName": "Android",
         # "automationName":"UiAutomator2",
         "deviceName": devices,  #//模拟器0
         "app": "../Test_APK/fxjc-app-prod-20180911-debug-signed-new.apk",
         "appWaitActivity": "com.mapass.example.activity.MainActivity_",
         "noReset": "true",  #//关闭每次运行脚本都重新安装APP
         "newCommandTimeout": "0",
         # "chromedriverExecutable": "Code_Keyword/appium-chromedriver/chromedriver/win/chromedriver.exe",
         # 这个用于系统默认的chromedriver无法正常使用的情况下,手动指定一个chromedriver
     }
     driver = webdriver.Remote("http://127.0.0.1:{}/wd/hub".format(port),
                               capabilites)
     return driver
     sleep(5)
Exemple #3
0
def get_suite(i):
    # test_dir = '../Case/'  # ./ 表示当前目录
    # test_report = '../report/'  # ../表示上一目录
    # suite = unittest.defaultTestLoader.discover(test_dir, pattern='test_*.py', top_level_dir=None)

    suite = unittest.TestSuite()

    suite.addTest(ParametrizedTestCase.parametrize(test_case.CaseTest,
                                                   param=i))
    suite.addTest(
        ParametrizedTestCase.parametrize(test_case2.CaseTest, param=i))
    print("this is suite", suite)
    now = time.strftime('%Y-%m-%d %H_%M_%S')
    write_file = WriteUserCommand()
    device = write_file.get_value('user_info_' + str(i), 'deviceName')
    html_file = "../report/testReport" + str(i) + now + ".html"
    with open(html_file, "wb") as fp:
        HTMLTestRunner.HTMLTestRunner(stream=fp,
                                      title="自动化测试",
                                      description=device +
                                      "的自动化测试结果").run(suite)
Exemple #4
0
def get_suite(i):
    # test_dir = '../Case/'  # ./ 表示当前目录
    # test_report = '../report/'  # ../表示上一目录
    # suite = unittest.defaultTestLoader.discover(test_dir, pattern='test_*.py', top_level_dir=None)

    suite = unittest.TestSuite()
    # myLists = [eval("test_case.CaseTest"), eval("test_case1.CaseTest")]
    # # suite.addTest(ParametrizedTestCase.parametrize(test_case.CaseTest, param=i))
    # for myList in myLists:
    #     suite.addTest(ParametrizedTestCase.parametrize(myList, param=i))
    myLists = GetSuiteList().get_list()
    for myList in myLists:
        suite.addTest(ParametrizedTestCase.parametrize(eval(myList), param=i))
    now = time.strftime('%Y-%m-%d %H_%M_%S')
    write_file = WriteUserCommand()
    device = write_file.get_value('user_info_' + str(i), 'deviceName')
    html_file = "./report/testReport" + '_deviceNum-' + str(
        i) + "-" + now + ".html"
    with open(html_file, "wb") as fp:
        HTMLTestRunner.HTMLTestRunner(stream=fp,
                                      title="自动化测试",
                                      description=device +
                                      "的自动化测试结果").run(suite)
def get_count():
    write_user_file = WriteUserCommand()
    return write_user_file.get_file_lines()
Exemple #6
0
def get_count():
    # 获取数据的行数
    write_file = WriteUserCommand()
    count = write_file.get_file_lines()
    return count
Exemple #7
0
 def __init__(self):
     self.cmd = DOScmd()
     self.port = Port()
     self.write_file = WriteUserCommand()
     self.device_list = self.get_devices()
Exemple #8
0
class Server:
    def __init__(self):
        self.cmd = DOScmd()
        self.port = Port()
        self.write_file = WriteUserCommand()
        self.device_list = self.get_devices()

    def get_devices(self):
        # """
        # 	通过adb devices命令查询当前PC所连接的设备数量,并将查询的设备信息储存为一个list
        # """
        devices_list = []
        result_list = self.cmd.excute_cmd_result('adb devices')
        if len(result_list) >= 2:
            for i in result_list:
                if 'List' in i:
                    continue
                devices_info = i.split('\t')
                if devices_info[1] == 'device':
                    devices_list.append(devices_info[0])
        else:
            print("找不到已连接设备")
            devices_list = None

        return devices_list

    def create_command_list(self, i, start_port, start_bootstrap_port):
        # """
        # 	拼接生成Appium的启动命令
        # 	start_port:-p后接的起始端口值
        # 	start_bootstrap_port:-bp后接的起始端口值
        # """
        command_list = []
        if self.device_list != None:
            t = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime(time.time()))
            port_list = self.port.create_port_list(start_port,
                                                   self.device_list)
            # print(port_list)
            bootstrap_port_list = self.port.create_port_list(
                start_bootstrap_port, self.device_list)
            #拼接Appium启动命令
            command = "appium -p {} -bp {} -U {} --no-reset --session-override --log ../log/{}_log_{}".format(
                port_list[i], bootstrap_port_list[i], self.device_list[i],
                self.device_list[i], t)
            command_list.append(command)
            self.write_file.Write_data(i, self.device_list[i], port_list[i],
                                       bootstrap_port_list[i])
            print(command_list)
            return command_list
        else:
            print('生成Appium启动命令失败')
            return None

    def start_server(self, i):
        #封装一个启动Appium的方法
        start_list = self.create_command_list(i, 4700, 4900)
        self.cmd.excute_cmd(start_list[0])

    def kill_server(self, process):
        #封装一个杀掉Appium进程的方法
        server_list = self.cmd.excute_cmd_result(
            'tasklist | find "{}"'.format(process))
        # print(server_list)
        if len(server_list) > 0:
            self.cmd.excute_cmd("taskkill -F -PID {}".format(process))

    def main(self):
        self.kill_server('node.exe')  #清除进程
        self.write_file.clear_data()  #清除历史数据
        for i in range(len(self.device_list)):
            # 通过多线程方法,同时启动多个Appium
            appium_start = threading.Thread(target=self.start_server,
                                            args=(i, ))
            appium_start.start()
        time.sleep(20)
Exemple #9
0
 def __init__(self):
     self.dos = DosCmd()
     self.device_list = self.get_devices()
     self.write_file = WriteUserCommand()
     self.base_driver = BaseDriver()
Exemple #10
0
class Server:
    def __init__(self):
        self.dos = DosCmd()
        self.device_list = self.get_devices()
        self.write_file = WriteUserCommand()
        self.base_driver = BaseDriver()

    def get_devices(self):
        """
        获得设备信息
        :return: 设备list
        """
        devices_list = []
        result_list = self.dos.excute_cmd_result("adb devices")

        if len(result_list) >= 2:
            for i in result_list:
                if 'List' in i:
                    continue
                devices_info = i.split('\t')
                if devices_info[1] == "device":
                    devices_list.append(devices_info[0])
            return devices_list
        else:
            return None

    def create_port_list(self, start_port):
        """
        创建可用端口
        :param start_port:
        :return:
        """
        port = Port()
        port_list = []
        port_list = port.create_port_list(start_port, self.device_list)
        return port_list

    def create_command(self, i):
        """
        根据设备个数,生成最终启动appium的命令行list
        :return:
        """
        # appium -p 4700 -bp 4701 -U 127.0.0.1:21503
        command_list = []
        port_list = self.create_port_list(4700)
        bp_list = self.create_port_list(4900)
        device_list = self.device_list

        command = "appium -p " + str(port_list[i]) + " -bp " + str(
            bp_list[i]
        ) + " -U " + device_list[i] + " --no-reset --session-override"
        command_list.append(command)
        self.write_file.write_data(i, device_list[i], str(bp_list[i]),
                                   str(port_list[i]))
        return command_list

    def start_server(self, i):
        """
        启动服务
        :param i:控制执行启动服务的次数,如果只有一个设备,则只启动一次服务,以此类推
        :return:
        """
        self.command_list = self.create_command(i)
        self.dos.excute_cmd(self.command_list[0])

    def kill_server(self):
        """
        杀掉appium进程
        :return:
        """
        server_list = self.dos.excute_cmd_result("ps aux |  grep appium")
        if len(server_list) > 0:
            self.dos.excute_cmd("pkill -f appium")

    def main(self):
        """
        多线程启动appium服务
        :return:
        """
        self.kill_server()
        self.write_file.clear_data()
        for i in range(len(self.device_list)):
            appium_start = threading.Thread(target=self.start_server,
                                            args=(i, ))
            appium_start.start()
            time.sleep(10)